On Tue, 2003-10-28 at 22:24, Hiroshi Shinohara wrote: > Louis, Steve, > Thank you for your kind explanations. > > Steve >The problem is that gen_out() itself knows nothing about it's > Steve >calling environment and so doesn't know that it's got a generator > Steve >producing values for its first parameter ... > > I see! I must put "procedure" for the argument of gen_out. > > #################### > # write output of generator > # 1,2,..,10 -> "1 2 3 .. 10" > # gentest3.icn > > procedure main() > write(g2s(seq,,10)) > end > > procedure g2s(gproc,Larg,n_limit,s) > /s := " " # delimiter > /Larg := [] # argument of gproc > s1 := "" > every s2 := if /n_limit then gproc ! Larg > else gproc ! Larg \n_limit > do s1 ||:= (s2 || s) > return s1[1:-*s] > end
Hi Hiroshi, While the above works, that's actually quite a bit of work that using a co-expression as Louis suggested avoids. In fact, your problem is a good fit for a PDCO, (which can be thought of as fancy syntax to avoid writing 'create'...): For example, here's a slight varient of your solution, using a PDCO. procedure main(args) gen_out{seq()\10} end procedure gen_out(L) s := [EMAIL PROTECTED] | " " while writes(@L[1],s) write() end The above solution puts out an extra separator at the end of the line, but I doubt that's a problem. If it is, then writing gen_out() as below fixes that problem: procedure gen_out(L) s := [EMAIL PROTECTED] | " " t := "" while writes(t, @L[1]) do t := s write() end (there are other ways to fix it). One of the advantages of using the co-expression is that you can now use *any* expression to produce the result sequence, not just a simple procedure call: procedure main() gen_out{2*seq()\10} end to produce the first 10 even numbers, for example. When you want to manipulate result sequences, co-expressions are a natural way to encapsulate that result sequence and then act on it. > I have another question with generator. > A few weeks ago I wrote a program to generate column numbers > like MS Excel (A,B,..,Z,AA,AB,..IV). More on this later, I'm a little pressed for time right now. -- Steve Wampler <[EMAIL PROTECTED]> ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Unicon-group mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/unicon-group