> On Mar 13, 2016, at 11:05 AM, Pedro Caldeira <[email protected]> > wrote: > > Hello everyone, > > Since I've discovered the concept of metaprogramming I've been quite > interested in Racket and its syntax extension capabilities. > > While searching for a memoization syntax extension I found a macro whose > pattern extension remained unclear. > > (define-syntax define/memoized > (syntax-rules () > ((_ (name . args) . body) > (define name (memoize (lambda args . body)))))) > > With the memoization function being defined as such: > > (define (memoize f) > (local ([define table (make-hash)]) > (lambda args > (dict-ref! table args (lambda () (apply f args)))))) > > What does the '.' mean in '(name . args)' and '. body’?
The parameter spec "(name . args)" means at least one argument (name) followed by an arbitrary number of additional (regular) arguments. The ". body” in the syntax pattern denotes ‘the rest of the given Syntax expression (!= S-expression). > In a call like (define/memoized (foo x y z) (displayln "bar"))) I would > imagine that name would be matched to foo; (x y z) to args and body to > (display ln "bar") but why do we use the '. body' in the lambda expression at > the end? Imagine (_ (foo x y z) (displayln x) (displayln y) (displayln z)) as the actual syntax. The .body will be bound to the sequence of three diaplaylns and this sequence will become the body of the lambda in the expansion. ;; — You may want to read up on Racket’s syntax first, starting with the Guide documentation. Meta-programming is about manipulation syntax and generating syntax and making sure bindings work out. — Matthias -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

