[racket] Convert macro argument to string

From: Kieron Hardy (kieron.hardy at gmail.com)
Date: Wed Sep 4 18:22:33 EDT 2013

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130904/cafdaa81/attachment.html>

Posted on the users mailing list.