[plt-scheme] keywords aren't isomorfic to symbols?

From: Eli Barzilay (eli at barzilay.org)
Date: Sun Nov 6 18:15:10 EST 2005

On Nov  6, Hans Oesterholt wrote:
> Hi,
> 
> The original mail about keywords states:
> 
> >/ * Syntactic forms can also use keywords, and pattern matching "just
> />/   works". Using keywords can help clarify when a syntactic form
> />/   expects to match literals (e.g., the colon in a `compound-unit/sig'
> />/   form) versus bindings (e.g., `quasiquote' in a `match' pattern).
> 
> So why doesn't the following work?

Keywords are like *symbols* not like identifiers.


> *******************************************************************************
> Welcome to MzScheme version 299.403, Copyright (c) 2004-2005 PLT Scheme, Inc.
> > 
> (define-syntax a
>   (syntax-rules ()
>     ((_ b ...)
>      (list 'b ...)
>      )))
> 
> (define q (a e f g h i j))
> (map (lambda (x) (symbol? x)) q)
> > > (#t #t #t #t #t #t)
> > (define-syntax ka
>   (syntax-rules ()
>     ((_ kb ...)
>      (list #:kb ...)
>      )))

There is no connection between the input `kb' and the output `#:kb'.
The "#:" part is not like "'" -- there is no form holding a `kb'
identifier like in 'kb.  To see how this doesn't work, consider how
this breaks:

  (define-syntax ka
    (syntax-rules ()
      ((_ kb ...)
       (list "kb" ...))))

This might make more sense:

  (define-syntax ka
    (syntax-rules ()
      ((_ #:kb ...)
       (list #:kb ...))))

but it fails because `#:kb' is not a pattern variable, just like

  (define-syntax ka
    (syntax-rules ()
      ((_ "kb" ...)
       (list "kb" ...))))

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.