paulw
2020-8-12 12:21:40

@paulw has joined the channel


ury.marshak
2020-8-12 15:00:40

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")


willbanders
2020-8-12 15:02:08

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))



ury.marshak
2020-8-12 15:08:55

Ah, yes, this works. I guess I had some expectation that racket/base will already do it for me. Thank you!


greg
2020-8-12 15:09:12

@ury.marshak The margin note next to the first example, a few paragraphs above, mentions what @willbanders did. :simple_smile:


ryanc
2020-8-12 15:09:13

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.


willbanders
2020-8-12 15:10:16

Cool, didn’t know just (require racket) could do that.


ury.marshak
2020-8-12 15:13:59

@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…


greg
2020-8-12 15:17:05

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.


greg
2020-8-12 15:18:25

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”.


greg
2020-8-12 15:19:03

TL;DR writing documentation or tutorials is hard :simple_smile:


ury.marshak
2020-8-12 15:35:29

@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
2020-8-12 18:34:03

@keith has joined the channel


samdphillips
2020-8-12 20:32:15

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"))


mflatt
2020-8-12 20:45:03

It looks like this may not be working right on Racket CS. Does it work as expected with BC?


samdphillips
2020-8-12 21:04:52

Getting 7.7BC now. I can check in a little bit.


samdphillips
2020-8-12 21:05:17

Erp. I mean 7.8BC


samdphillips
2020-8-12 21:13:26

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.


mflatt
2020-8-12 23:15:52

Finalizers run in a background thread, so you probably need (sync (system-idle-evt)) to get the ordering that you expected.


samdphillips
2020-8-12 23:43:15

Makes sense. In a larger test program I got the ordering that I expected.


kian.melhus
2020-8-13 03:39:52

@kian.melhus has joined the channel