Hi all, I am running into a weird issue concerning the $: verb as used in the following tic-tac-toe game. Somehow replacing (u f.) with u's body gives a different result; it seems they should always be strictly equivalent.
JVERSION
Engine: j9.7.0-beta4/j64/linux
Build: commercial/2025-05-05T13:14:19/clang-14-0-0/SLEEF=1
Library: 9.7.1
Platform: Linux 64
Installer: j9.7 install
InstallPath: /home/cam/Programs/j/j9.7
Contact:
www.jsoftware.com
'`c t b'=.(?@#{])@([:I.0=b)`{.`}. NB. cpu's move; turn; board
'`wm tm'=. (''echo@, {&'.XO'@-@t ,' wins'"_)`([:echo LF&,@'tie') NB. print win/tie message
i=. (0=]{b@[) ::0 *: ]e.i.@9 NB. invalid posn? (x: state; y: posn)
y=. ($:@[ echo@'no')^:i _1+0".1!:1@1@echo@'move (1-9):' NB. your move
m=. -@t , c`y@.(1=t) t@]`[`(b@])} ] NB. apply current player's move to board
d=. ''echo@, '',~ (,' '&,)/"1@({&'.XO')@(3 3$b) NB. display the board
w=. 3 +./@:= |@(+/"1)@(],|:,(<@0 1|:|.),:<@0 1|:])@(3 3$b) NB. test whether game has been won
g=: wm`tm`$:@.(1:i.~w,0-.@e.b)@([d)@m NB. move and display until won or full
g 10{._1 NB. this works; recursion is scoped because g is a named verb
. . .
. . O
. . .
move (1-9):
5
. . .
. X O
. . .
. . O
. X O
. . .
move (1-9):
9
. . O
. X O
. . X
. . O
. X O
. O X
move (1-9):
1
X . O
. X O
. O X
X wins
([: g f.{{u y}} 10{._1:)'' NB. this also works; {{u y}} limits the recursion to exclude the 10{._1:
. . .
O . .
. . .
move (1-9):
5
. . .
O X .
. . .
. . O
O X .
. . .
move (1-9):
1
X . O
O X .
. . .
X O O
O X .
. . .
move (1-9):
9
X O O
O X .
. . X
X wins
NB. replacing (g f.) with g's body should be strictly equivalent, but fails for some reason:
([: wm`tm`$:@.(1:i.~w,0-.@e.b)@([d)@m {{u y}} 10{._1:)''
. . .
. . O
. . .
|domain error: y
| u y
Press ENTER to inspect