chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] escaping the # character in identifiers


From: Thomas Chust
Subject: Re: [Chicken-users] escaping the # character in identifiers
Date: Wed, 07 Sep 2005 09:07:24 -0000
User-agent: Opera M2/8.02 (MacPPC, build 2148)

Am 07.09.2005, 06:58 Uhr, schrieb Dmitry Lizorkin <address@hidden>:
Hello!

I am not quite familiar with Chicken macro system, and I cannot understand
the following result:
[...]
Could you please explain this result to me? What should I do in order to
escape the # character in identifiers?
[...]

Hello,

this problem has got nothing to do with CHICKEN's macro system. It just means that there is a considerably larger amount of magic involved with qualified symbols and keywords in CHICKEN, which is not documented at all. To get the keyword blubb: you would have to do something like
        (string->symbol "\x00blubb")
and to get the qualified symbol ##sys#structure? you would have to do
        (string->symbol "\x03sysstructure?")

So the magic is actually in the first byte of the symbol's name! Therefore, to achieve your goal you should use a macro like this:
        (define-macro (qualified-symbol namespace symbol)
          (let* ((ns (symbol->string namespace))
                 (nsl (string-length ns))
                 (sm (symbol->string symbol)))
            (if (or (fx< nsl 1) (fx> nsl 31))
              (abort
               (make-composite-condition
                (make-property-condition
                 'exn
                 'message "namespace identifier too short or too long"
                 'location 'qualified-symbol
                 'arguments (list namespace symbol))
                (make-property-condition
                 'syntax))))
            (string->symbol
             (string-append
              (string (integer->char nsl))
              ns sm))))

Perhaps a string->qualified-symbol procedure along these lines should be added to CHICKEN for completeness' sake?

Ciao,
Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]