

Learning Racket #2: Macros, Macros and a Bit of Modules - mmastrac
http://artyom.me/learning-racket-2

======
gus_massa
Just nitpicking. The first example that uses define-syntax-rule can also be
fixed with “...”. He uses the “...” later in syntax-parse, but they are
available in define-syntax-rule too. With syntax-parse is easier to construct
advanced macros, but I like to use define-syntax-rule for small throwaway
macros.

    
    
      #lang racket
      
      (define-syntax-rule (def id body ...) (define id body ...))
      
      (def (vector-swap! vec i j)
        (def t (vector-ref vec i))
        (vector-set! vec i (vector-ref vec j))
        (vector-set! vec j t))
      
      (let ([v (vector 'a 'b 'c)])
        (vector-swap! v 0 1)
        v)  ;==> (vector 'b 'a 'c)

~~~
artyomkazak
Thanks for telling! (I've written a bit of a response here:
[http://artyom.me/learning-racket-2#gus_massa-from-
hn](http://artyom.me/learning-racket-2#gus_massa-from-hn) .)

------
minikomi

        I'm afraid that with the level of flexibility Racket allows, I'll never get to writing an actual program
    

Great series

------
e12e
While I know hn discourages "mee too!"-posts, let me just say that I find
these series really interesting. I'm such a lazy programmer, I just love
having someone else muck about with stuff like this macro-madness and then
tell me about it, saving me from having to start up racket at all :-)

In short: Keep at it! It's greatly appreciated.

~~~
dang
HN discourages substanceless comments, but this one is just fine.

