As I had to think about it a few minutes, I thought I should share the 
solution.
In the original program I was building a table from three separate 
files, for which
records with all the same keys do not exist. But I know, now, what to do.
---------------------------------------------------------------------------------------------------------------
record health_row(yr,mo,wgt)

procedure main()
     null_master := health_row(-1,-1,-1)
     write("Hello World")
     master_tbl := table()
     mo := "01"
     yr := "2014"

     glu_key := "DT" || yr || "/" || mo
     wgt := 198
     write("glu key = ",glu_key," wgt = ", wgt)
     master_tbl[glu_key] := health_row(yr,mo,wgt)

     mo := "02"
     yr := "2014"
     glu_key := "DT" || yr || "/" || mo
     wgt := 196
     write("glu key = ",glu_key," wgt = ", wgt)
     master_tbl[glu_key] := health_row(yr,mo,wgt)

     mo := "01"
     yr := "2014"

     glu_key := "DT" || yr || "/" || mo
     write("glu key = ",glu_key," wgt = from table ", 
master_tbl[glu_key].wgt)
     write("Now You get correct value!")
end
---------------------------------------------------------------------------------------------------------------------
Hello World
glu key = DT2014/01 wgt = 198
glu key = DT2014/02 wgt = 196
glu key = DT2014/01 wgt = from table 198
Now You get correct value!
----------------------------------------------------------------------------------------------------------------------

Dennis Darland
stud...@dennisdarland.com

On 3/1/2014 1:17 AM, Jeffery, Clint (jeffe...@uidaho.edu) wrote:
> Icon (and Unicon, due to obsessive backward compatibility) do not create a 
> separate copy of the table default value each time the table is subscripted 
> with a non-existent key. Instead they produce a reference to the (singleton) 
> default value. When you are using this default value in order to "insert" 
> elements into the table, you are really just inserting multiple keys that are 
> sharing the same health_row instance. The workaround is pretty easy -- but we 
> might have a lively discussion of whether this is one of the <1% of the cases 
> where we should break backward compatibility, since it is a fairly common 
> source of bugs and arguable would be more useful if it was modified to 
> copy-on-insert.
> ________________________________________
> From: Dennis Darland - student <stud...@dennisdarland.com>
> Subject: [Unicon-group] What am I doing wrong - table of records
>
> I've mostly been using Ruby lately, but I like to use different languages.
> I was writing a much larger program, and kept having troubles.
> I simplified it to this sample program. (really just Icon.)
> It happens with both linux and windows.
> ---------------------------------------------------------------------------------------------------------------
>
>
> record health_row(yr,mo,wgt)
>
> procedure main()
>       null_master := health_row(-1,-1,-1)
>       write("Hello World")
>       master_tbl := table(null_master)
>       mo := "01"
>       yr := "2014"
>
>       glu_key := "DT" || yr || "/" || mo
>       wgt := 198
>       write("glu key = ",glu_key," wgt = ", wgt)
>       master_tbl[glu_key].yr := yr
>       master_tbl[glu_key].mo := mo
>       master_tbl[glu_key].wgt := wgt
>
>       mo := "02"
>       yr := "2014"
>       glu_key := "DT" || yr || "/" || mo
>       wgt := 196
>       write("glu key = ",glu_key," wgt = ", wgt)
>       master_tbl[glu_key].yr := yr
>       master_tbl[glu_key].mo := mo
>       master_tbl[glu_key].wgt := wgt
>
>       mo := "01"
>       yr := "2014"
>
>       glu_key := "DT" || yr || "/" || mo
>       write("glu key = ",glu_key," wgt = from table ",
> master_tbl[glu_key].wgt)
>       write("You get last value - why not from table?")
> end
> ----------------------------------------------------------------------------------------------------------------------
> Hello World
> glu key = DT2014/01 wgt = 198
> glu key = DT2014/02 wgt = 196
> glu key = DT2014/01 wgt = from table 196
> You get last value - why not from table?
> ----------------------------------------------------------------------------------------------------------------------
>
>
>
>
>
> --
> Dennis Darland
> stud...@dennisdarland.com
>
>
> ------------------------------------------------------------------------------
> Flow-based real-time traffic analytics software. Cisco certified tool.
> Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
> Customize your own dashboards, set traffic alerts and generate reports.
> Network behavioral analysis & security monitoring. All-in-one tool.
> http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
> _______________________________________________
> Unicon-group mailing list
> Unicon-group@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/unicon-group


------------------------------------------------------------------------------
Flow-based real-time traffic analytics software. Cisco certified tool.
Monitor traffic, SLAs, QoS, Medianet, WAAS etc. with NetFlow Analyzer
Customize your own dashboards, set traffic alerts and generate reports.
Network behavioral analysis & security monitoring. All-in-one tool.
http://pubads.g.doubleclick.net/gampad/clk?id=126839071&iu=/4140/ostg.clktrk
_______________________________________________
Unicon-group mailing list
Unicon-group@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to