Re: case and foreach
On 31 Mar 2005, at 23:00, D. Newhall wrote:
>
>
> posted by: D. Newhall <derek_newhall at yahoo.com>
>
> I too have yearned for the "case", "foreach", and "next" statements. However,
> one of Euphoria's goals is to keep the code simple and these suggestions kinda
> run against that trend. Regardless, I've found myself wishing I had a "next"
> statementmany times when I need to find all possible permutations of a certain
> string. Also, if you look at probably 90% of for loops, they seem to be used
> in
> instances where "foreach" would be much better.
>
> "Case" I'm torn on. While yes "select" and "case" would be excellent things to
> add you don't really need them. Yes, they'd increase productivity and probably
> make it easier to debug but they aren't necessary, "if" and "then" work
> perfectly fine (even if it takes longer to type all the conditions in).
>
> "Next" we can live without but most people seem to want "foreach" and
> "select/case".
>
> Here's my suggestion for the syntax:
>
> -- select/case
> select x do
> case 5 then
> -- code
> end case
> case 2 then
> --code
> end case
> end select
>
> -- foreach
> foreach o in s by 1 do -- o is an object
> -- code
> end foreach
This is even cleaner:
function case(object x)
goto x
:1 return("x=1")
:2 return("x=2")
:orangutan return("x needs a banana")
:roo return("as in kanga?")
:{"a","b","c"} return("That is very good, "&nick&"!")
return(type(x))
end
puts(1,case(x))
But alas, that requires a goto statement, and going to something, which
almost every crawling baby can understand, also breaks RDS's message of
"simple".
Kat
|
Not Categorized, Please Help
|
|