hravnx
2018-10-21 08:53:40

@hravnx has joined the channel


paul
2018-10-21 11:12:55

@greg No, it doesn’t use “special form,” which is why I scare-quoted it. :sunglasses: Now I know to distinguish a syntax from a procedure.

I am looking for crisp definitions. Still struggling with “serve directly as values” and “immediate values” and such. I left those paragraphs alone in eval-model.scrbl.


paul
2018-10-21 11:16:31

@lexi.lambda Right, sorry, I should have said “all flavors of apply.” Why is #%app a syntax rather than a procedure? In fact, why does it exist at all? There is obviously some interesting internal stuff going on here that I don’t understand yet.


soegaard2
2018-10-21 11:18:03

In most Scheme systems an application (foo 1 2 3) is kept as (foo 1 2 3) during expansion.


soegaard2
2018-10-21 11:18:22

In Racket an application (foo 1 2 3) is expanded into (#%app foo 1 2 3).


soegaard2
2018-10-21 11:18:42

This allows a user to write his own #%app and thus change the meaning of application.


soegaard2
2018-10-21 11:19:14

For example one can make an #%app that turns unbound identifers in the arguments into a symbol.


soegaard2
2018-10-21 11:19:27

Think: symbolic algebra system.


soegaard2
2018-10-21 11:19:37

Or one can change the evaluation order.


soegaard2
2018-10-21 11:20:31

One of the simplest uses it to extend the set of values that can be applied.


soegaard2
2018-10-21 11:20:55

E.g. ((list 1 2 3) 0) could give 1


soegaard2
2018-10-21 11:21:21

%app evaluates the first argument, if it is a list it inserts an list-ref


soegaard2
2018-10-21 11:21:34

turnning ((list 1 2 3) 0) into (list-ref (list 1 2 3) 0).


soegaard2
2018-10-21 11:22:08

Since #%app is used everywhere it is important that #%app is fast.


soegaard2
2018-10-21 11:23:08

In a larger persepective #%app is one of the pieces that makes it easier to implement new languages on top of Racket.


notjack
2018-10-21 11:51:35

my favorite use of #%app so far is the fancy-app package: http://docs.racket-lang.org/fancy-app/index.html?q=fancy-app


paul
2018-10-21 12:05:34

Now that is pretty cool. Is the reason to insert #%app instead of apply so that apply retains the usual semantics?


soegaard2
2018-10-21 12:07:16

The function apply takes a function and a list as input. Then applies the function using the elements of the list as arguments for the function.


soegaard2
2018-10-21 12:07:37

So you can’t write (apply foo 1 2 3) but (apply foo (list 1 2 3)) works.


paul
2018-10-21 12:08:49

Aha. But my question was stupid. The point of #%app is that it’s not a procedure call but some faster internal thing.


soegaard2
2018-10-21 12:08:58

Yes.


notjack
2018-10-21 12:18:24

it’s also how keyword arguments work


notjack
2018-10-21 12:19:35

racket/base provides an #%app macro that’s built on top of a lower-level #%plain-app form - the former supports keyword arguments while the latter doesn’t


paul
2018-10-21 12:23:39

Why don’t keywords evaluate to themselves in Racket?


soegaard2
2018-10-21 12:27:56

Not 100% sure, but I think this makes it easier to catch error situations where keywords are used incorrectly. Say (foo #:bar) where foo is not a function accepting keywords.


soegaard2
2018-10-21 12:28:38

A compile error here is better than getting a runtime error, when foo discovers that it received a keyword.


abmclin
2018-10-21 14:00:32

@paul you may be interested in reading https://www2.ccs.neu.edu/racket/pubs/scheme2009-fb.pdf it explains the design of the keywords and the rationale for treating keywords as syntactic markers instead of expressions


minhnhat10bk
2018-10-21 15:47:00

how can i display image(2htdp/image) from repl


soegaard2
2018-10-21 15:47:37

which repl? (DrRacket, Emacs, terminal, etc)


minhnhat10bk
2018-10-21 15:47:54

racket terminal


soegaard2
2018-10-21 15:48:09

don’t know


minhnhat10bk
2018-10-21 15:48:18

haha


minhnhat10bk
2018-10-21 15:48:26

i have try frame, canvas


minhnhat10bk
2018-10-21 15:48:31

but not work :disappointed:


soegaard2
2018-10-21 15:49:12

Creating a frame with a canvas and drawing the image on the canvas would work.


soegaard2
2018-10-21 15:58:32

@minhnhat10bk #lang racket (require racket/gui) (define f (new frame% [label “Image Preview”])) (define bm (make-object bitmap% "/Users/soegaard/Downloads/stepper.png")) (define c (new canvas% [parent f] [min-width 100] [min-height 100] [paint-callback (λ (c dc) (send dc draw-bitmap bm 0 0))])) (send f show #t)


soegaard2
2018-10-21 15:59:50

Note that the window manager (macOS or Windows) might delete the contents of a window, and if this happens, then the paint-callback is called.


soegaard2
2018-10-21 16:00:37

Drawing the bitmap on the canvas outside the paint-callback only until the system deletes the content again.


minhnhat10bk
2018-10-21 16:11:48

how to draw image-snip% in canvas


soegaard2
2018-10-21 16:12:24

I think snips (and image-snips) needs to be in an editor.


minhnhat10bk
2018-10-21 16:13:13

thanks you


minhnhat10bk
2018-10-21 16:13:47

my question is from picture language in SICP :smile:


soegaard2
2018-10-21 16:14:02

Which one? The new or the old?



soegaard2
2018-10-21 16:14:37

The new implementation of the SICP picture language is here:



soegaard2
2018-10-21 16:15:04

It works much better than the old one.


soegaard2
2018-10-21 16:15:28

It now supports colors, different sizes etc.


soegaard2
2018-10-21 16:17:13

And why is this not in the documentation? Well - someone needs to write documentation for it.


soegaard2
2018-10-21 16:17:36

@paul Would you be interested in that?


minhnhat10bk
2018-10-21 16:17:41

but I see in racket docs it can use with REPL


soegaard2
2018-10-21 16:18:37

Yes - if you use it the DrRacket repl or in an Emacs repl (using racket-mode).


soegaard2
2018-10-21 16:20:05

If you open sicp-pict2/sicp.rkt in DrRacket and hit run, then, results will be drawn in the repl.


minhnhat10bk
2018-10-21 16:23:37

ok


soegaard2
2018-10-21 16:29:32

Look at the end of the file for some examples.


soegaard2
2018-10-21 16:29:41

(escher) is nice


minhnhat10bk
2018-10-21 16:37:54

I see a bug


soegaard2
2018-10-21 16:38:45

thanks - I’ll take a look.


soegaard2
2018-10-21 16:41:05

@minhnhat10bk Hmm. Try downloading einstein2.jpg and saving it in the same folder as you saved sicp.rkt.



minhnhat10bk
2018-10-21 16:43:21

oh, my fault


soegaard2
2018-10-21 16:43:52

Nope - I ought to make a better error message.


hravnx
2018-10-21 21:50:00

Hi all - n00b here. I made a Docker image for easy testing of Racket packages in Azure Pipelines, and I thought I would share. https://hub.docker.com/r/hravnx/racket-azpipe/


paul
2018-10-22 00:40:25

@abmclin Thanks for that reference.


paul
2018-10-22 00:42:25

@soegaard2 I will look into documenting SICP, though not immediately.


sorawee
2018-10-22 01:29:48

Hello. I have a quick question about syntax values. Consider:

#lang racket

(define-syntax (my-if stx)
  (syntax-case stx ()
    [(_ c t e)
     (quasisyntax/loc stx (s-if c (thunk t) (thunk e)))]))

(define (s-if c t e)
  (if c (t) (e)))

(my-if 1
       (begin
         (define p 1)
         (define q 2)
         (print p))
       (print 3))

After fully expanding the above program, we will have something like:

(#%app call-with-values (lambda () (#%app s-if (quote 1) (lambda () (let-values (((p) (quote 1))) (let-values (((q) (quote 2))) (#%app print p)))) (lambda () (#%app print (quote 3))))) print-values)

which totally makes sense.

However, somehow the syntax value (let-values (((p) (quote 1))) (let-values (((q) (quote 2))) (#%app print p))) has source location from the macro my-if (line 6) rather than the source location from (define p 1). And this doesn’t make sense to me since my-if should simply move (define p 1) around, but never destruct and reconstruct its syntax (which could change srcloc).

So, why does this happen, and what’s the way I can retain the srcloc from (define p 1)?


sorawee
2018-10-22 01:35:22

Actually I guess it doesn’t make sense to have srcloc from (define p 1) either because (let-values (((q) (quote 2))) (#%app print p)) is not a part of the original syntax, but still, why does the srcloc from my-if leak in?