Working on R. E.'s latest problem, I hit an interpreter bug. The
session log is
load 'C:\JPrograms\temp\interpbug.ijs'
jtree G
|domain error: jtree
| jtree G
X
10 12
Y
12 15
(<10 12) joinroutes (<12 15)
┌──────────┐
│┌────────┐│
││10 12 15││
│└────────┘│
└──────────┘
jtree G
|domain error: joinroutes
| y(+./@:E.}.;)(1{.y) ,x,(l}.y)
jtree G
|length error: joinroutes
| 'f l'=.0 1+(0 1+#y) |y i.x
G
+---+-+---+---+---+---+--+---+---+---+---+----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
|0 1||2 3|2 4|3 5|4 6| |5 7|5 8|6 7|7 9|7 10|8 10|9 11|10 12|10 11|11
13|11 14|11 15|12 16|12 15|12 14|
+---+-+---+---+---+---+--+---+---+---+---+----+----+----+-----+-----+-----+-----+-----+-----+-----+-----+
You can see that the variable G has been corrupted; also, the errors
running jtree are bogus, I think. The script file follows. The first
line is wrapped, and the name 'joinroutes' is defined and then overwritten:
G =:<"1 ] 0 1 2 2 3 4 4 5 5 6 7 7 8 9 10 10 11 11 11 12 12 12 ,. 1 2 3
4 5 6 5 7 8 7 9 10 10 11 12 11 13 14 15 16 15 14
NB. x is new pair
NB. y is old route
NB. Result is merged routes
joinroutes =: 4 : 0&.>
select. (#y) > 'f l' =. y i. x
case. 1 1 do.
y ; (f {. y) , x , ((>:l) }. y)
case. 0 1 do.
y ;^:(l~:0) < x , ((>:l) }. y)
case. 1 0 do.
y ;^:(f~:<:#y) < (f {. y) , x
case. do.
y ; x
end.
)
joinroutes =: 4 : 0&.>
X =: x
Y =: y
'f l' =. 0 1 + (0 1 + #y) | y i. x
y (+./@:E. }. ;) (f {. y) , x , (l }. y)
)
jtree =: ([: ~.@; joinroutes)/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm