While browsing around the J library I stumbled onto this problem with
"scriptform" in "misc.ijs":

  require 'misc'
  a=:b=:'aaa'
  r=:'xxx'
  n
|value error: n
  scriptform 'a b n r'
a=: 'aaa'
b=: ,<'aaa'
n=: 0
r=: 97 61 58 32 39 97 97 97 39 13 10 98 61 58 32 44 60 39 97 97 97 39 13 10
110 61 58 32 48 13 10{a.

"scriptform" has a number of local names which if one is trying to format a
global name matching one of those gets the local definition instead of the
one in the argument. A second problem: if a name is invalid then
"scriptform" never gets to the tests to for "invalid name" or "undefined".

Here are a couple of suggestions to fix it. They contain no local names to
cause problems.

NB. This one causes an error if a name is invalid as now happens.
scriptform=.([:;(],'=: ',CRLF,~[:5!:5<)&.>)@cutopen

NB. This one handles "invalid name" and "undefined" and it works
NB. like how I think the original was supposed to work.
NB. Instead of using the words "invalid name" and "undefined"
NB. this uses the words from the J error messages.
NB. Personally I prefer the first definition. I want an error
NB. if I give a bad name and it handles the name "y" properly.
scriptform=: [:;3 : 0&.>@cutopen
try. (;y),'=: ',(5!:5 <y),CRLF
 catch. y,'=: ',CRLF,~;(<:13!:11''){9!:8''
end.
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to