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.


On Tue, Oct 9, 2012 at 7:28 PM, john skaller
<skal...@users.sourceforge.net>wrote:

> I have code like this:
>
>         var x1 = test1;
>         if x1 do
>                 ...
>         else
>                 var x2 = test2;
>                 if x2  do
>                         ...
>                 else
>                         var x3 = test3;
>                         if x3 do
>
>
> The "elif" clause normally relieves this nesting problem,
> but doesn't work when you have to compute something
> prior to the next test. So I'm trying this:
>
>         if x do
>                 ...
>         otherwise
>
>         blah;
>         if x2 do
>                 ..
>         otherwise
>
> "otherwise" is the same as "else" except scope extends to the end of
> the enclosing scope. Another way to do this is make "else" do what
> "otherwise" does and then add do/done:
>
>         do
>                 if x do ..
>                 else ..
>         done
>
> This is the Ocaml syntax (they use begin/end and if/then).
> Gets rid if "elif" since you can now write "else if".
>
> Ocaml generally open-scopes trailers like this:
> let .. in, match .. with, if ..else all work that way (but
> for loops don't).
>
> This makes some code more compact, but editing is a pain
> because you have to "back up" to put the "do/begin" at the top
> of a scope when you terminate it with "done/end", i.e. the
> Ocaml method is fragile.
>
> I note in passing ML uses let .. in .. endlet (i forget the actual
> terminator).
>
> C is similar:
>
>         if (c) x;
>         if (x) { x; y; }
>
> Fragile. But whilst Felix
>
>         if x do x; done
>
> is robust it also leads to a lot of ugly "done"s at the end
> of nested blocks .. almost as bad as Lisp.
>
>
> --
> john skaller
> skal...@users.sourceforge.net
> http://felix-lang.org
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Felix Language" group.
> To post to this group, send email to felix-langu...@googlegroups.com.
> To unsubscribe from this group, send email to
> felix-language+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/felix-language?hl=en.
>
>
------------------------------------------------------------------------------
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
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to