@paulw has joined the channel
Where is syntax
provided from? Docs say it’s provided from racket
and racket/base
and while racket
seems to work, racket/base
doesn’t, the following code from the “Fear of Macros”: #lang racket/base
(define-syntax (also-foo stx)
(syntax "I am also foo"))
gives me an error: unsaved editor:4:3: syntax: unbound identifier; also, no #%app syntax transformer is bound in the transformer phase at: syntax in: (syntax "I am also foo")
My understanding is that syntax is a different phase, so you’ll need to require that for syntax as well: (require (for-syntax racket/base))
Ah, yes, this works. I guess I had some expectation that racket/base will already do it for me. Thank you!
@ury.marshak The margin note next to the first example, a few paragraphs above, mentions what @willbanders did. :simple_smile:
Right. To be more precise, the code above uses syntax
at phase 1, so you need to somehow require
it for phase 1. As Blake said, (require (for-syntax racket/base))
is the standard way of doing that. (require racket)
or #lang racket
would also work, because racket
provides syntax
at both phase 0 and phase 1.
Cool, didn’t know just (require racket)
could do that.
@greg Wow, it does! I literally had the page open in front of me, copying and pasting the example and had not noticed it even had a margin note…
No worries. Even better someday I should figure out how to have Scribble examples that display the #lang
line, for clarity. Even just greyed out or a little title caption line, to clarify that you needn’t/can’t keep typing the lang line for each example.
It can be tricky because Scribble examples support a kind of REPL style, where examples can use things defined in previous examples. Which is concise. OTOH it makes it tricky to jump to one example and use it “stand-alone”.
TL;DR writing documentation or tutorials is hard :simple_smile:
@greg Writing documentation or tutorials certainly tends to be underappreciated, I’d like to thank you very much for writing it! Coming to Racket from Common Lisp, to me this seems to be one of the more alien parts of the language.
@keith has joined the channel
Here is a simple example that I can’t seem to get to work with register-finalizer-and-custodian-shutdown
. Neither PLTSTDERR=info@finalize racket -e '(require (submod "finalized-simple.rkt" A))'
or PLTSTDERR=info@finalize racket -e '(require (submod "finalized-simple.rkt" B))'
indicate that the finalize
function has been called. #lang racket/base
;; finalized-simple.rkt
(require ffi/unsafe/custodian)
;; hijack name for logging
(define (displayln x)
(log-message (current-logger) 'info 'finalize x))
(define (finalize x)
(displayln "finalizing"))
(define the-box
(let ([v "a value"])
(register-finalizer-and-custodian-shutdown v finalize #:at-exit? #t)
(displayln "created")
(box v)))
(module* A #f
(set-box! the-box #f)
(collect-garbage 'major)
(collect-garbage 'major)
(collect-garbage 'major)
(displayln "exiting"))
(module* B #f
(displayln "exiting"))
It looks like this may not be working right on Racket CS. Does it work as expected with BC?
Getting 7.7BC now. I can check in a little bit.
Erp. I mean 7.8BC
Welcome to Racket v7.8.
sam@bmo:~/projects/racket-dev/misc$ PLTSTDERR=info@finalize racket -e '(require (submod "finalized-simple.rkt" A))'
finalize: created
finalize: exiting
finalize: finalizing
sam@bmo:~/projects/racket-dev/misc$ PLTSTDERR=info@finalize racket -e '(require (submod "finalized-simple.rkt" B))'
finalize: created
finalize: exiting
finalize: finalizing
It works. Although I was expecting the ordering to be different in the A submodule.
Finalizers run in a background thread, so you probably need (sync (system-idle-evt))
to get the ordering that you expected.
Makes sense. In a larger test program I got the ordering that I expected.
@kian.melhus has joined the channel