How about a PDCO :-

procedure nth_result(a)
        local n
        n := integer(@a[1]) | fail
        every 1 to n - 1 do
                @a[2] | fail
        return @a[2]
end

procedure main()
        write( nth_result { 3, "a"|"b"|"c"|"d" } )
end


Here nth_result { n, expr } will produce the nth result from
expr, or fail.



Art Eschenlauer wrote:
> 
> Is there a compact way to reference the Nth result in the set of results
> produced?
> 
> For example, suppose that I want to obtain the third result produced by
> the expression ("a"|"b"|"c"|"d").  Thinking in my stone-age procedural way,
> I would write:
> 
> procedure main()
>   i := 0
>   every s := ("a"|"b"|"c"|"d") do {
>     write ("s = "||s)
>     i +:= 1
>     if i = 3 then {
>       write ("i = "||i)
>       write(s)
>       break
>     }
>   }
> end
> 
> I suppose that I could do this with a co-expression:
> 
> procedure main()
>   E := create ("a"|"b"|"c"|"d")
>   i := 0
>   while s := ! @E do {
>     write ("s = "||s)
>     i +:= 1
>     if i = 3 then {
>       write ("i = "||i)
>       write(s)
>       break
>     }
>   }
> end
> 
> but I don't think that immediately gives me much benefit.
> 
> What I'm hoping for is a compact syntax, similar to one of the following
> examples except that it would actually work!
>   ("a"|"b"|"c"|"d")[3]
>   3("a"|"b"|"c"|"d")
> 
> The most compact idiom I have come up with is:
> every s := ("a"|"b"|"c"|"d")\3 ; write (s)
> Any suggestions?
> Is there an idiomatic way to get rid of the variable s for example?
> 
> _______________________________________________
> Unicon-group mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/unicon-group

_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to