Since I like co-expressions and threads, here is another solution that uses
a co-expression to avoid the slice:

procedure writeany(l)
    C := create !l
    writes("[")
    writes(@C )
    while writes(", " || @C)
    write("]")
end

--Jafar



On Sun, Mar 9, 2014 at 7:22 PM, David Gamey <[email protected]> wrote:

> How about something like:
>
>
> c := "["
> every writes(c,!l) do c := ","
> write("]")
>
>
> less wasteful than the slice
>
>
> David
>
>   ------------------------------
>  *From:* Clinton Jeffery <[email protected]>
> *To:* Robert Heckendorn <[email protected]>
> *Cc:* Unicon group <[email protected]>
> *Sent:* Sunday, March 9, 2014 7:48:18 PM
> *Subject:* Re: [Unicon-group] Some unicon code
>
> Robert,
>
> You are asking a classic Icon question, one so classic that any number of
> experts on the list might weigh in on the best solution. You are correct
> that l[2:0] creates a copy of (most of) l -- not a good thing if l is
> large. Instead of generating elements from a slice via
> !l[2:0]
> one can certainly generate the elements with
> l[2 to *l]
>
> Can anyone else suggest a shorter/cleaner formulation of Robert's
> writeany() procedure? Is there an IPL procedure that already does this?
>
> Cheers,
> Clint
>
>
> On Sat, Mar 8, 2014 at 10:24 AM, Robert Heckendorn <
> [email protected]> wrote:
>
> The following can write out a list.   I don't like doing the slice of the
> list because I am worried it builds a copy of the list.   Any comments?
>
> procedure writeany(l)
>     every writes("[" |
>                  l[1] |
>                  ", " || !l[2:0] |
>                  "]")
>     write()
> end
>
> procedure main()
>     l := ["a", "b", "c"]
>     writeany(l)
>     pop(l)
>
>     writeany(l)
>     pop(l)
>
>     writeany(l)
>     pop(l)
>
>     writeany(l)
>
>     writeany("dogs")
>
> end
>
> --
>
> ------------------------------------------------------------------------------
> |
> |     "People would rather believe than know."       -- E. O. Wilson
> |
> | Dr. Robert Heckendorn
> | [email protected]
> | http://marvin.cs.uidaho.edu/~heckendo
> | Computer Science Dept, Univ. of Idaho, Moscow, Idaho, USA   83844-1010
>
>
>
>
> ------------------------------------------------------------------------------
> Subversion Kills Productivity. Get off Subversion & Make the Move to
> Perforce.
> With Perforce, you get hassle-free workflows. Merge that actually works.
> Faster operations. Version large binaries.  Built-in WAN optimization and
> the
> freedom to use Git, Perforce or both. Make the move to Perforce.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
> _______________________________________________
> Unicon-group mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/unicon-group
>
>
>
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> Unicon-group mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/unicon-group
>
>
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to