Is is a subtle problem.  First of all you are not acually passing the
generator into gen_out.  The parameter "gen" is just taking numerical
values, so inside the function, the line "every ss := gen do {" is
actually only being evaluated once.  But, the gen_out function itself is
called 10 times.  First time gen_out(1), second time is gen_out(2), and so
forth.  This happens because gen_out keeps failing (because there is no
return statement) so Icon's goal-directed execution keeps repeating it
trying to make it succeed.

In order to pass the expression "seq()\10" to the gen_out function, you
need to use a co-expression.  I've rewritten your program so it will work
as you expect:

# write output of generator
# 1,2,..,10 -> "1 2 3 .. 10" ?
# gentest2.icn

procedure main()
  write(&version)
  gen_out(create(seq() \10))
end

procedure gen_out(gen,s)
  /s := " "
  n := 0
  while ss := @gen do {
    if n > 0 then writes(s,ss)
             else writes(ss)
    n +:= 1
  }
  write()
end







> Then I try to make a procedure "gen_out" to write generator's output.
> ####################
> # write output of generator
> # 1,2,..,10 -> "1 2 3 .. 10" ?
> # gentest2.icn
>
> procedure main()
>   write(&version)
>   gen_out(seq() \10)
> end
>
> procedure gen_out(gen,s)
>   /s := " "
>   n := 0
>   every ss := gen do {
>     if n > 0 then writes(s,ss)
>              else writes(ss)
>     n +:= 1
>   }
>   write()
> end
>
> But gentest2 writes
> Icon Version 9.3.2.  July 1, 1999
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
>
> I cannot understand the behaviour of "gen_out".
> Why "gen_out" does not work as I expect ?
> How I change "gen_out" to write generator's output in one line ?
>
> Thanks,
> Hiroshi Shinohara
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: The SF.net Donation Program.
> Do you like what SourceForge.net is doing for the Open
> Source Community?  Make a contribution, and help us add new
> features and functionality. Click here: http://sourceforge.net/donate/
> _______________________________________________
> Unicon-group mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/unicon-group
>


-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to