3 ms·
And yet I'm still too stupid to understand the macro system. Oh well. I also didn't know there was a Chez version. Racket already has a native AOT compiler, ri
by nerdponx 8y ago
And yet I'm still too stupid to understand the macro system. Oh well.
I also didn't know there was a Chez version. Racket already has a native AOT compiler, right? What would the advantage be to run on Chez, faster or smaller compiled code?
- swdunlop 8y agoSee http://blog.racket-lang.org/2019/01/racket-on-chez-status.html http://blog.racket-lang.org/2019/01/racket-on-chez-status.ht... and scroll down to “Performance of Compiled Code.” That was back in January, so things may be even better now.
- jim-jim-jim 8y agoIs it the general Scheme syntax-rules macros that you're struggling with? Or something unique to Racket? (which I haven't used) If it's the former, I found this little article helpful when I was new to Scheme: http://www.willdonnelly.net/blog/scheme-syntax-rules/ http://www.willdonnelly.net/blog/scheme-syntax-rules/
- tgbugs 8y agoFor Racket specific macro tooling syntax-parse [0] in combination with syntax classes is usually the suggested starting point. Hygenic with pattern matching and a bunch of other features for parsing s-expression grammars. As mentioned down-thread Greg Hendershott's Fear of Macros [1] is a good starting point for a number of folks. The curriculum for Racket School 2018 [2] also has exercises that help introduce the syntax-parse tooling. 0. https://docs.racket-lang.org/syntax/Parsing_Syntax.html https://docs.racket-lang.org/syntax/Parsing_Syntax.html 1. https://www.greghendershott.com/fear-of-macros/ https://www.greghendershott.com/fear-of-macros/ 2. https://summer-school.racket-lang.org/2018/plan/ https://summer-school.racket-lang.org/2018/plan/
- xabush 8y agoThis is great tutorial. I used to be confused by the macros in scheme
- pjmlp 8y agoGetting rid of C dependency and bootstrap Racket in Scheme.
- darkpuma 8y agoTry out this guide perhaps: http://www.greghendershott.com/fear-of-macros/ http://www.greghendershott.com/fear-of-macros/
- deleted 8y ago[deleted]
- deleted 8y ago[deleted]
- pyb 8y agoA few people exist who are genuinely able to use Racket macros, but they all have a PhD in CS. As opposed to the larger group who think they understand them. I was once in that group, but now I've just given up.
- NikkiA 8y agoRacket's macro transformers are about as easy as hygenic macros[0] get unfortunately, I can occasionally manage to make a er-macro-transformer based macro in chicken work how I want. defmacro was a lot easier, but I understand the aversion to it, even if it was rare that it was/is a problem. [0] syntax-rules based macros are cake, naturally, but they're also incredibly limited, although I have seen people implement massive complex OO systems using a sort of ad-hoc state machine built in pages upon pages of syntax-rules rules.
- Bogdanp 8y ago> And yet I'm still too stupid to understand the macro system. Oh well. This talk[0] by Robby Findler helped me a ton when I was first learning about macros in Racket. I've found that the best way to learn, though, is by doing: when you find a use case for a macro, figure out how to do that particular thing and, slowly but surely, things will start to click. [0]: https://www.youtube.com/watch?v=hFlIl0Zo234 https://www.youtube.com/watch?v=hFlIl0Zo234
- gus_massa 8y agoFor the macros, I prefer to recommend to start with very straightforward macros that use `define-syntax-rule`. For example #lang racket (define-syntax-rule (run3times code ...) (begin (begin code ...) (begin code ...) (begin code ...))) (define x 0) (run3times (set! x (add1 x)) (display x)) ; shows ==> 123 As other comment said, you have to find some good opportunity to use a simple macro. (In this case, it is better to use the build-in `for`. Actually, `for` is defined in a macro, it is not part of the internal "secret" low level language.) Once you are confident and you grok the difference between a macro and a function, you can try the other ways to define macros. These other ways are more flexible and can make weirder macros, and have better support when the macro is used wrongly. There are good links in the sibling comments.
- GeoffKnauth 8y agoAnother way to learn about all this stuff from the experts themselves is Racket School: https://school.racket-lang.org/ https://school.racket-lang.org/