For Programmers: Free Programming Magazines  


Home > Archive > Dylan > October 2005 > On macros and variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author On macros and variables
Chris Dutton

2005-10-05, 6:57 pm

Having experimented just recently a bit with Dylan's macros, I wrote a
simple "times" macro to give me back something I enjoyed in Ruby.

times 10 with i
format-out("%d\n", i);
end;

Which runs the body ten times, with "i" as the counter.

There's just one thing that bothers me.

times 10 with i
format-out("%d\n", i);
i := i + 1;
end;

This will interfere with the loop.

Is there anyway to keep the body from modifying "i"?
Daniel Brockman

2005-10-05, 9:56 pm

Chris,

> times 10 with i
> format-out("%d\n", i);
> i := i + 1;
> end;
>
> This will interfere with the loop.
>
> Is there anyway to keep the body from modifying "i"?


I don't know whether there is a way in Dylan of making
variables immutable. However, you could always store the
value of `i' in two variables --- one that's visible to the
body and one that's internal to the macro.

This is possible because Dylan's macro facility is hygienic,
meaning that names introduced in one lexical context do not
bleed into (and "pollute") the other.

--
Daniel Brockman <daniel@brockman.se>
Chris Dutton

2005-10-08, 6:56 pm

Daniel Brockman wrote:
> Chris,
>
>
>
>
> I don't know whether there is a way in Dylan of making
> variables immutable. However, you could always store the
> value of `i' in two variables --- one that's visible to the
> body and one that's internal to the macro.
>
> This is possible because Dylan's macro facility is hygienic,
> meaning that names introduced in one lexical context do not
> bleed into (and "pollute") the other.
>


That's a beautiful idea. Thank you.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com