[racket] Convert macro argument to string

From: Roman Klochkov (kalimehtar at mail.ru)
Date: Wed Sep 4 21:33:14 EDT 2013

 I think that it is right thing. But it translates symbol to string in runtime.

In my opinion, it is better to use syntax-case and translate symbol to string when expanding macros.

For example:

(define (test)
   (defxosd 123 : _int))

in your variant will fail when (test) will be runned. If you use syntax-case it will not be compiled at all.


Среда,  4 сентября 2013, 16:22 -06:00 от Kieron Hardy <kieron.hardy at gmail.com>:
>In trying to use the ffi example interface to the xosd program (xosd.rkt/use-xosd.rkt at ), I notice that 
>
>(define-syntax defxosd
>  (syntax-rules (:)
>    [(_ name : type ...)
>     (define name
>       (get-ffi-obj (regexp-replaces 'name '((#rx"-" "_") (#rx"[*?]$" "")))
>                    libxosd (_fun type ...)))]))
>
>fails on execution, with:
>
>regexp-replace*: contract violation
>  expected: (or/c string? bytes?)
>  given: 'xosd-create
>  argument position: 2nd
>  other arguments...:
>   #rx"-"
>   "_"
>
>It appears Racket is now more strict, and perhaps what used to work now doesn't. 
>
>I naively fixed the immediate problem by using the ~a form (from racket/format) to convert the constant formed with 'name to a string, i.e, replace:
>
>       (get-ffi-obj (regexp-replaces 'name '((#rx"-" "_") (#rx"[*?]$" "")))
>
>with:
>
>       (get-ffi-obj (regexp-replaces (~a 'name) '((#rx"-" "_") (#rx"[*?]$" "")))
>
>Was this the right thing to do, or is there a better way?
>
>Cheers,
>
>Kieron.
>____________________
>  Racket Users list:
>   http://lists.racket-lang.org/users
>


-- 
Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130905/c18bb43c/attachment-0001.html>

Posted on the users mailing list.