Verb definitions that lack trailing ) are the thing that causes
me the most trouble teaching beginners. When they execute the
erroneous verb, nothing seems to happen (because it's waiting for
the ) to be entered from the console) and they say 'Roger has died'.
I have just realized that I can do something about this. I am
going to redefine the script_z_ verb for my students so that it
checks for missing ) in scripts before they are loaded. The changed
script_z_, which will go into their profile, is given below.
0. Can anyone think of anything else that should go into a
beginner-protection script? (I don't claim that this change
should go into the system)
1. Can anyone explain why the script_z_ verb goes to the trouble of
erasing y before loading the script? Do I need to erase all
the temporary variables I create?
Henry Rich
NB. Override the load verb with one that checks for malformed
NB. verb definitions
script_z_ =: [: 3 : 0 jpath_z_&.:>
try.
fd =. CR -.~ 1!:1 y
NB. Check for explicit definitions that lack a trailing )
lines =. <;._2 fd , LF
wdlines =. ;: :: ((0$a:)"_)&.> lines
vstart =. +./@:((<@;:@> 'define';':0')&(((+./@:E.)~ >)~"0 _/))@> wdlines
vend =. -:&(<,')')@{.@> wdlines
vendct =. vstart +/;.1 vend
if. +./ toofew =. 1 > vendct do.
smoutput }. ; (LF,'missing ending ): ')&,&.> (lines {~ (I. vstart) {~ I.
toofew)
else.
0!:0 y [ 4!:55<'y'
end.
catch.
smoutput 'File not found: ' , >y
end.
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm