Brian Schott:
> verb definitions are terminated with ! instead of )
> Is this an undocumented feature?
Nah. If you look more closely, you'll see that the ! -terminated verbs are
actually embedded within a noun. I've indented the
captured noun for clarity, but in the script it's not indented:
k=. 0 : 0
9!:1 >.*:+/6!:0 ''
free=: ' '
run=: 3 : 0
q=. a:-.~<;._2 y.,' '
n=. ".>{.q
q=. }.q
n runc q
!
...
)
k=. k rplc ('!',LF);')',LF
k=. k rplc LF;LF,' '
Subsequently, the ! are replaced by ) , creating the proper definitions.
The ! are used (presumably) to avoid early
termination of the noun k .
I have this pattern in my scripts, but instead of using a replacement for ) I
just indent the entire noun. That has the
advantage of being valid J, and makes it clear that it's "nested". It's
important that the indentation be a tab 9{a. though,
because a lone ) preceded or followed by any number of spaces 32{a. is
still treated like a terminator. THAT is an
undocumented feature.
J's IDE lets you indent a multi-line block of text with tabs by
selecting/highlighting the block and pressing the tab key.
By the way, you can test ideas like yours:
a =. 3 : 0
NB. A comment
!
NB. Nope, not terminated
)
NB. Now it's terminated
a
3 : 0
NB. A comment
!
NB. Nope, not terminated
)
-Dan
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm