Am 07.09.2005, 06:58 Uhr, schrieb Dmitry Lizorkin <[EMAIL PROTECTED]>:
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


_______________________________________________
Chicken-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to