|
List Info
Thread: Program flow
|
|
| Program flow |

|
2006-08-09 00:43:04 |
|
Hi, all,
I've been trying to implement a case construct such that one could write
something like: case(x==1, 1 print, x==2, 2 print, nil print) to print 1
if x is 1, 2 if x is 2 and nil otherwise.
Upon writing I got two questions:
1. There probably is an ideologically better way of writing such chains of
comparisons. Could someone, please, point them out 
2. I did write the thing. It works, no problem. But then I write:
method(case(1==1, return 1); return 2) and find out that this method
returns 2!!! That's definitely not wanted behaviour. I tried to dig into
implementation and found nothing that would differ behaviour of "if" from
"evalArgAt". Except one thing: if is not a method.
So, the question is: cat one write proper program-flow constructions in
pure Io? I'd very much like to be able to!
Danya.
__._,_.___
.
__,_._,___
|
| Program flow |

|
2006-08-09 00:55:29 |
|
I recall someone already implementing case()- I'm sure they will pipe
up.
Personally I find no use for case()-
At my level of Io-ness I would simply make a Map that contained each
of my cases and then the code to be executed.
Then it becomes only a single check-
doString(Map at(case))
Which I believe should either return the code and execute it or
attempt to execute nil.
(whoops, just tried it and doString doesn't like executing nil)
So then it's just a check for nil, then an execution if non nil.
As in:
if(nonNil Map exists(case), doString Map at(case)
(there may be better ways to do this from more advanced users- i'm
still a weakling)
--
"Jupiter accepts your offer..."
AIM:IMFDUP
On Aug 8, 2006, at 5:43 PM, Dendik wrote:
> Hi, all,
>
> I've been trying to implement a case construct such that one could
> write
> something like: case(x==1, 1 print, x==2, 2 print, nil print) to
> print 1
> if x is 1, 2 if x is 2 and nil otherwise.
>
> Upon writing I got two questions:
>
> 1. There probably is an ideologically better way of writing such
> chains of
> comparisons. Could someone, please, point them out 
>
> 2. I did write the thing. It works, no problem. But then I write:
> method(case(1==1, return 1); return 2) and find out that this method
> returns 2!!! That's definitely not wanted behaviour. I tried to dig
> into
> implementation and found nothing that would differ behaviour of
> "if" from
> "evalArgAt". Except one thing: if is not a method.
>
> So, the question is: cat one write proper program-flow
> constructions in
> pure Io? I'd very much like to be able to!
>
> Danya.
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
__._,_.___
.
__,_._,___
|
| Program flow |

|
2006-08-09 01:13:48 |
|
Hi Danya,
On 8/9/06, Dendik <me.dendik gmail.com> wrote:
> Hi, all,
>
> I've been trying to implement a case construct such that one could write
> something like: case(x==1, 1 print, x==2, 2 print, nil print) to print 1
> if x is 1, 2 if x is 2 and nil otherwise.
Some kind of case statement has been discussed a number of times on
this mailing list. After a year or so of discussing I think we're
finally coming around to KirinDave's suggestion. 
http://www.quag.geek.nz/paste/bff3641b8a991fbd.txt might interest you.
At some point we'll put something in the main line. I'm not 100%
exactly the form it should take.
Jonathan.
> Upon writing I got two questions:
>
> 1. There probably is an ideologically better way of writing such chains of
> comparisons. Could someone, please, point them out 
>
> 2. I did write the thing. It works, no problem. But then I write:
> method(case(1==1, return 1); return 2) and find out that this method
> returns 2!!! That's definitely not wanted behaviour. I tried to dig into
> implementation and found nothing that would differ behaviour of "if" from
> "evalArgAt". Except one thing: if is not a method.
>
> So, the question is: cat one write proper program-flow constructions in
> pure Io? I'd very much like to be able to!
>
> Danya.
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
__._,_.___
.
__,_._,___
|
[1-3]
|
|