On 10/10/2012, at 2:15 PM, Dobes Vandermeer wrote:
> Didn't you recently add the "as" syntax which would allow, for example:
>
> if test1 as x1 do
>
> elif test2 as x2 do
>
> elif test3 as x3 do
>
> done
>
> ?
>
> This probably eliminates the nested else if 90% of the time without adding to
> the language.
That only works with expressions. The word "test1" above should be viewed as a
sequence of computations rather than a single function/generator.
It's an issue in Felix that it has both statements and expressions and a lot
of stuff needs to be duplicated.
The actual code I was writing now looks like this:
for line in split (lines,char "\n") do
++count;
var commentry = Match (scomment, StringPiece line, 0, ANCHOR_BOTH,
vcomment.stl_begin, 2);
if commentry do
comments = list (vcomment . 1 . string.strip);
otherwise
commentry = Match (ccomment, StringPiece line, 0, ANCHOR_BOTH,
vcomment.stl_begin, 2);
if commentry do
comments = Cons (vcomment . 1 . string.strip, comments);
otherwise
var m = Match (grexp, StringPiece line, 0, ANCHOR_BOTH, v.stl_begin,n);
if m do
var sym = v.3.string;
var dfn = "";
var m2 = Match (extract, StringPiece line, 0, ANCHOR_BOTH, v2.stl_begin,
n2);
if m2 do
m2 = Match (extract, StringPiece line, 0, ANCHOR_BOTH, v2a.stl_begin,
n2);
if m2 do
dfn = v2a . 1 . string . strip;
else
dfn = v2 . 1 . string . strip;
done
else
dfn = line . strip;
done
if ishtml do
if prefix (dfn, "class") do
println$ f"%04d" count + ": " + '<a href="'+href+'#'+f"%04d"
count+'">'+dfn +'</a>';
for cline in comments do println cline; done
comments = Empty[string];
else
println$ f"%04d" count + ": " + '<a href="'+href+'#'+f"%04d"
count+'">'+ dfn +'</a>';
for cline in comments do println cline; done
comments = Empty[string];
done
else
if prefix (dfn, "class") do
println$ f"%04d" count + ": " + dfn;
for cline in comments do println$ " "+cline; done
comments = Empty[string];
else
println$ f"%04d" count + ": " + dfn;
for cline in comments do println$ " "+ cline; done
comments = Empty[string];
done
done
done
done
Before "otherwise" the third match had to be indented twice and we had
two more "done"s at the end.
Of course in *this* case we might say
if Match ..
And of course I could write, for example:
dfn = if m2 then v2a else v2 endif . 1 . string . strip
or even better if I used expressions instead of statements.
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language