helper macro construct-from-string for srfi-108 Per Bothner 21 Mar 2013 06:34 UTC
Re: helper macro construct-from-string for srfi-108 Per Bothner 25 Mar 2013 22:37 UTC

Re: helper macro construct-from-string for srfi-108 Per Bothner 25 Mar 2013 22:37 UTC

On 03/20/2013 11:34 PM, Per Bothner wrote:
> The idea is that you could implement $construct$:cname thus:
>
> (define-syntax $construct$:cname
>    (syntax-rules ()
>      ((_ . args) (construct-from-string cname-maker . args))))
>
> This assumes you also a function cname-maker.
>
> Then:
> &cname{abc&(+ 3 4)z} ==> (cname-maker "abc7z")
> &cname[id: "n7"]{&(+ 3 4)abc} ==> (cname-maker id: "n7" "7abc")

I came up with something that I think is better than
construct-from-string:  A new syntax:

(define-simple-constructor cname cname-maker [str-maker])

This binds $construct$:cname such that:

($construct$:cname [init-arg ... $>>$] text-arg ...)

is mapped to:

(cname-maker init-arg ... (str-maker text-arg ...))

cname-maker and str-maker are user-supplied macros or functions.
I.e. either names of syntax or expression that evaluate to functions.
str-maker defaults to $string$

--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/