Howdy Y'all,

As you may recall, a table takes a default value, but one of Icon and
Unicon's most long-standing little irritations is that, if the default
value is a structure, that value may easily wind up shared by many keys
by accident, as in

t := table([])
push(t["foo"], 1)
push(t["bar"], 2)

in which neither t["foo"] nor t["bar"] has been associated with
(i.e. assigned) a value yet, but the table's default value (a list) is
accumulating values that will be seen in the default later on.  The
way to handle this is cumbersome:

t := table()
/ (t["foo"]) := []
push(t["foo"], 1)
/ (t["bar"]) := []
push(t["bar"], 1)

I recently received another request that this problem be "fixed".  Sure,
this is a feature, not a bug, and yes, breaking compatibility with Icon is
anathema :-).  But how many people would complain bitterly if the semantics
of table defaults were changed so that, if the default value were a
structure, it was copied (a la copy()) and inserted the first time the
table was referenced?  I found 1-2 tables in the IPL with structure defaults,
but am not aware of one that actually uses it to do aliasing. The cleverest
existing use of it I saw was

t:=table([])
...
t["foo"] |||:= 1
t["bar"] |||:= 2

Cheers,

Clint


-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to