Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

macro help needed

3 views
Skip to first unread message

cgay

unread,
May 19, 2008, 6:34:20 AM5/19/08
to
Every time I sit down to write a macro in Dylan I get hopelessly
confused. (This, to me, is the biggest drawback to infix syntax, but
let's not start that discussion again.)

I want to be able to write this:

define xml-rpc-server $my-server "/RPC2"
(error-fault-code: 1)
"echo" => method (#rest args) args end;
"ping" => method () "ack" end;
end;

Here's my attempt.

define macro xml-rpc-server-definer
{ define xml-rpc-server ?:name ?url:expression (?initargs:*) ?
functions end }
=> { define constant ?name = apply(make, <xml-rpc-server>, ?
initargs);
let _server = ?name;
add-responder(?url, curry(respond-to-xml-rpc-request,
_server));
?functions
}
functions:
{ } => { }
{ ?function; ... } => { ?function; ... }
function:
{ ?function-name:expression = ?fun:expression }
=>
{ register-xml-rpc-method(_server, ?function-name, ?fun) }
end macro xml-rpc-server-definer;

When I compile my example I get the unhelpful error message "invalid
syntax",
and I'm afraid that's all I have to go on. Can anyone spot the
problem?

Thanks.
-Carl

Peter S. Housel

unread,
May 20, 2008, 1:07:02 AM5/20/08
to
On Mon, 19 May 2008 03:34:20 -0700, cgay wrote:

> { ?function-name:expression = ?fun:expression }

Shouldn't that be:

> { ?function-name:expression => ?fun:expression }

-Peter-

cgay

unread,
May 20, 2008, 10:11:32 AM5/20/08
to

Yes, but that's just an artifact of my messing about to try and figure
out what the problem was. Even with => I still get the mysterious
"syntax error".

-Carl

cgay

unread,
May 21, 2008, 6:22:35 AM5/21/08
to

The new definition below works. I just added parens around ?
url:expression. I wonder if it was greedily taking all of

"/RPC2"(error-fault-code: 1)

as the ?url expression? And if that's the case, I wonder why it
doesn't take all of

("/RPC2")(error-fault-code: 1)

as well. Black magic.

define macro xml-rpc-server-definer
{ define xml-rpc-server ?:name (?url:expression)
(?initargs:*)
?functions


end }
=> { define constant ?name = apply(make, <xml-rpc-server>,
?initargs);

begin


let _server = ?name;
add-responder(?url, curry(respond-to-xml-rpc-request,
_server));
?functions

end }

functions:
{ } => { }
{ ?function; ... } => { ?function; ... }

function:
{ ?function-name:expression => ?fun:expression; }

0 new messages