Couple of nice solutions!  Educational , interesting, elegant.  Thanks!

Here is the actual problem:
   I want the write() and writes() funcitons to take arbitrary typed
objects and print something
reasonable.  So writeany() could take a list of lists for instance.  The
solutions so far do not
assume the components can be printed by writes.   What if this needs to be
a recursive application
of writeany for lists so each elem in the list is also printed with
writeany.   That gets in the way of
these two solutions for various reasons.   Anyone want to speculate on an
elegant method if the
function must invoke itself for each element until things writeable with
writes are found.

cheers,



On Mon, Mar 10, 2014 at 11:42 AM, Jafar Al-Gharaibeh <to.ja...@gmail.com>wrote:

> 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 <david.ga...@rogers.com>wrote:
>
>> How about something like:
>>
>>
>> c := "["
>> every writes(c,!l) do c := ","
>> write("]")
>>
>>
>> less wasteful than the slice
>>
>>
>> David
>>
>>   ------------------------------
>>  *From:* Clinton Jeffery <clint.jeff...@gmail.com>
>> *To:* Robert Heckendorn <captainmeer...@gmail.com>
>> *Cc:* Unicon group <unicon-group@lists.sourceforge.net>
>> *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 <
>> captainmeer...@gmail.com> 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
>> | captainmeer...@gmail.com
>> | 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
>> Unicon-group@lists.sourceforge.net
>> 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
>> Unicon-group@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/unicon-group
>>
>>
>


-- 
------------------------------------------------------------------------------
|
|     "People would rather believe than know."       -- E. O. Wilson
|
| Dr. Robert Heckendorn
| captainmeer...@gmail.com
| http://marvin.cs.uidaho.edu/~heckendo
| Computer Science Dept, Univ. of Idaho, Moscow, Idaho, USA   83844-1010
------------------------------------------------------------------------------
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
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to