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

Re: helper macro construct-from-string for srfi-108

This page is part of the web mail archives of SRFI 108 from before July 7th, 2015. The new archives for SRFI 108 contain all messages, not just those from before July 7th, 2015.

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.

&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
per@xxxxxxxxxxx   http://per.bothner.com/