yilin.wei10
2020-8-7 12:58:51

Hello, I’ve been trying to write a macro which calls define appending a prefix to an id. Roughly speaking I was thinking I could create a syntax object which looked like #(define #,(local-expand #’(append-prefix id)) definition )but the identifier isn't found. I experimented a bit further and I found that calling what I'd assumed to beidentity = (datum->syntax #f (syntax->datum #’id))` didn’t work either.


yilin.wei10
2020-8-7 12:59:36

I’m clearly missing something about manipulating syntax objects here - what should I be looking at?


soegaard2
2020-8-7 13:01:20
  1. Use format-id to create the new identifier.
  2. Use with-syntax to turn your new identifier into a pattern variable.
  3. Use syntax or syntax/loc to generate the piece of code.

soegaard2
2020-8-7 13:08:04

#lang racket (require (for-syntax racket/syntax syntax/parse)) (define-syntax (define-foo stx) (syntax-parse stx [(_define-foo id) ; 1. Generate the new identifier (define foo-id (format-id #'id "foo-~a" #'id)) ; 2. Turn it into a pattern variable (with-syntax ([foo-id foo-id]) ; 3. Use it in a template (syntax/loc stx (define foo-id 42)))])) ; Example (define-foo bar) ; define foo-bar foo-bar ; reference foo-bar


yilin.wei10
2020-8-7 13:17:50

Ah OK - so it was the ctx which I was losing when doing the transforms?


soegaard2
2020-8-7 13:18:21

Yes.


yilin.wei10
2020-8-7 19:31:19

The pdf on https://download.racket-lang.org/releases/6.10.1/pdf-doc/foreign.pdf\|ffi/unsafe has a rather cryptic sentence if a resource is scarce or visible to end users, then custodian management is more appropriatethan mere finalization as implemented by allocator.. Why is this the case? Is a custodian not simply a tree like model of resource frees? Or am I missing something?


yilin.wei10
2020-8-7 19:31:50

pg. 11 for reference.


yilin.wei10
2020-8-7 19:50:39

Thank you!


samth
2020-8-7 19:58:04

That’s because finalization may happen after a long time, and is hard for users to speed up


samth
2020-8-7 19:58:26

Whereas custodian management is tree shaped and deterministic


yilin.wei10
2020-8-7 21:01:23

Ah I see; because it’s tied to the GC?


samth
2020-8-7 21:01:32

Yes


yilin.wei10
2020-8-7 21:01:57

Thank you, that makes sense.


zainab.ali.london
2020-8-7 21:03:33

@zainab.ali.london has joined the channel