sydney.lambda
2019-8-19 07:56:18

Thanks @rokitna, good to know it does in fact work correctly. Apologies for my embarrassing mathematics skills, haha.


darioszr
2019-8-19 22:45:20

Nob question’: I understand the macro vaguely however I can’t find any use case in real projects


darioszr
2019-8-19 22:46:08

I mean, what could be a real usage of a macro for an opensource project? Any input appreciated :grin: :racket-flat:


soegaard2
2019-8-19 22:47:50

If you experience repetition, a pattern in some kind in your program, it is time to give the pattern a name.


soegaard2
2019-8-19 22:48:16

If you experience that you have a lot of similar expressions, you make a function.


soegaard2
2019-8-19 22:48:57

The arguments of the function represent what’s different and the body is what’s common (i.e. the pattern).


soegaard2
2019-8-19 22:50:03

If you experience a pattern in your program that consists of declarations, bindings, control structures or other patterns that aren’t expressions — you need a macro.


soegaard2
2019-8-19 22:52:13

A simple example: You have a file where you define all your structs.


soegaard2
2019-8-19 22:52:34

These structs needs to be provided, so you write:


soegaard2
2019-8-19 22:52:54

(provide (struct-out foo) (struct-out bar) (struct-out baz))


soegaard2
2019-8-19 22:53:39

You realize, that you repeat (struct-out name) and want to write (provide-structs foo var baz) instead.


soegaard2
2019-8-19 22:53:49

You now need to write a macro.


badkins
2019-8-20 00:13:10

I was working on a macro today to allow specifying routes for a web application. After some help on the mailing list, I have the following: https://gist.github.com/lojic/842619ab2c59a2c96960f9ccd30bc136 See the routes.rkt file for an example of using the macro to specify a few web application routes.


badkins
2019-8-20 00:13:27

the macro code is in the router-stx.rkt file


samdphillips
2019-8-20 02:22:00

If you look in the manual there are tags on entries that they are either ‘procedure’ or ‘syntax’. Almost all of the ones marked ‘syntax’ are macros written in Racket.

Some of the useful builtin macros are match and for (and all of the for variants.)