[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Anaphora and token filters
- From: "Steven Johnson" <s.johnson@...>
- Date: Mon, 08 Jan 2007 19:22:47 -0600
On Mon, 08 Jan 2007 16:24:45 -0600, Michael Newberry
<mnewberry@mirametrics.com> wrote:
It would be nice if one or more assignments could be evalulated but
ignored left to right, so long as there is a value to test before "do":
while <assignment>, str ~= nil do
--[code]
end
or just evaluate str rather than str ~= nil.
Michael
This isn't really pressing, but the loop syntax topic reminded me of
something. I've been meaning to implement "anaphoric while"
(and if) since the token filter stuff started to take off. I use the sort
of idiom mentioned above (at least in the single-
assignment, test-against-nil case) enough that I think it would be worth
having. Something that transforms this:
awhile <expression>[, <var>] do
<body>
end
into this:
do
local it
while true do
<var> = <expression>
if <var> then
<body>
end
end
end
(If <var> is omitted above, then "it" (or some other default) is used;
otherwise, the first two lines and the last line need not
be emitted.)
So you'd have something (referring again to the other topic) like this:
awhile S:Next(), str do
--[code]
end
Has anybody done this or something similar? I may have a go at it now that
ftools and friends are out, but I haven't done
anything with these yet and it's not clear if such a construct would play
nice, due to the possiblity of nesting, as well as
balancing the "awhile" and "end" properly. Are my worries unfounded? Maybe
I missed a good example? I suppose I'd attempt it
sooner or later, but it would be nice to know ahead of time if I'm going
to be beating my head against the wall.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/