@hravnx has joined the channel
@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.
@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.
In most Scheme systems an application (foo 1 2 3) is kept as (foo 1 2 3) during expansion.
In Racket an application (foo 1 2 3) is expanded into (#%app foo 1 2 3).
This allows a user to write his own #%app and thus change the meaning of application.
For example one can make an #%app that turns unbound identifers in the arguments into a symbol.
Think: symbolic algebra system.
Or one can change the evaluation order.
One of the simplest uses it to extend the set of values that can be applied.
E.g. ((list 1 2 3) 0) could give 1
%app evaluates the first argument, if it is a list it inserts an list-ref
turnning ((list 1 2 3) 0) into (list-ref (list 1 2 3) 0).
Since #%app is used everywhere it is important that #%app is fast.
In a larger persepective #%app is one of the pieces that makes it easier to implement new languages on top of Racket.
my favorite use of #%app
so far is the fancy-app
package: http://docs.racket-lang.org/fancy-app/index.html?q=fancy-app
Now that is pretty cool. Is the reason to insert #%app
instead of apply
so that apply
retains the usual semantics?
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.
So you can’t write (apply foo 1 2 3) but (apply foo (list 1 2 3)) works.
Aha. But my question was stupid. The point of #%app
is that it’s not a procedure call but some faster internal thing.
Yes.
it’s also how keyword arguments work
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
Why don’t keywords evaluate to themselves in Racket?
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.
A compile error here is better than getting a runtime error, when foo discovers that it received a keyword.
@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
how can i display image(2htdp/image) from repl
which repl? (DrRacket, Emacs, terminal, etc)
racket terminal
don’t know
haha
i have try frame, canvas
but not work :disappointed:
Creating a frame with a canvas and drawing the image on the canvas would work.
@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)
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.
Drawing the bitmap on the canvas outside the paint-callback only until the system deletes the content again.
how to draw image-snip% in canvas
I think snips (and image-snips) needs to be in an editor.
thanks you
my question is from picture language in SICP :smile:
Which one? The new or the old?
The new implementation of the SICP picture language is here:
It works much better than the old one.
It now supports colors, different sizes etc.
And why is this not in the documentation? Well - someone needs to write documentation for it.
@paul Would you be interested in that?
but I see in racket docs it can use with REPL
Yes - if you use it the DrRacket repl or in an Emacs repl (using racket-mode).
If you open sicp-pict2/sicp.rkt in DrRacket and hit run, then, results will be drawn in the repl.
ok
Look at the end of the file for some examples.
(escher) is nice
I see a bug
thanks - I’ll take a look.
@minhnhat10bk Hmm. Try downloading einstein2.jpg and saving it in the same folder as you saved sicp.rkt.
oh, my fault
Nope - I ought to make a better error message.
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/
@abmclin Thanks for that reference.
@soegaard2 I will look into documenting SICP, though not immediately.
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)
?
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?