The cons cell constructed by (cons 1 2) is normally printed as (1 . 2). The list created by (list 1 2 3) could also be created as (cons 1 (cons 2 (cons 3 '()))). It could be printed as (1 . (2 . (3 . ()))).
Normally lists are simply printed as (1 2 3) though. Notice that (1 . (list 2 3)) is the same list since (cons 1 (list 2 3)) is the same as (list 1 2 3). In a round about way we have arrived at the pattern (name . args). Suppose we have a syntax object representing a list (plus 1 2 3) which could be written as (plus . (1 2 3)). If we match this against (name . args) we see that name matches plus and that args now matches (1 2 3). To practise the dot notation you can use the repl (since the reader understands dot notation. > ( 1 . (2 3 4)) ... /Jens Axel 2016-03-13 16:05 GMT+01:00 Pedro Caldeira <pedro.calde...@bluewin.ch>: > 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'? > > 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? > > Thank you for your attention. > > -- > 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 racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- -- Jens Axel Søgaard -- 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 racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.