Here is a workaround that is probably nicer anyway,
chkerrA_z_ =: (hook ;)(hook }.)(^:(0 = >@{.@:]))
boxeach_z_=: ,&<
mkerr_z_=: ((0&boxeach)@:) ( :: ((13!:11 ; 13!:12)@:(''"_)))
mode_z_ =: 2 : '([: ]chkerrA [: v inv u mkerr hook v)'
still don't understand why first version fails.
----- Original Message -----
From: 'Pascal Jasmin' via Programming <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Saturday, June 21, 2014 11:58:44 AM
Subject: [Jprogramming] why won't this work (bug in :: ?)
mode_z_ =: 2 : '([: v inv u hook v) finallyC (v inv) ' NB. v y must return y
finallyC_z_ =: 2 : 'u :: ((v)][:13!:12(''''[]))
hook_z_ =: 2 : ('u v y' ;':';'x u v y')
plus =: +
bizmode =: (3 : 0 :. (3 : 0))
plus =: +
y
)
plus =: *
y
)
this works as intended: mode switches definition of plus, then switches back
after executing u
3 plus mode bizmode 3
9
plus
+
The bug is in finallyC, (::) . I'd expect that if there is any error in u, it
should execute v, but:
3 +: mode bizmode 2
|domain error
| 3 +:mode bizmode 2
plus__a
*
Is the problem that hook is an explicit conjunction?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm