if you want to pass a gerund (or boxed noun) to a function, it must either be
all verbs (with single adverbs as strings permitted), or all nouns. So this is
possible.
'`a b c' =. '/';+`-
(c a , b a) 1 2 3
2 6
but it fails for an adverb phrase.
'`a b c' =. '/\';+`-
|spelling error
gerunds are a bit complex to hold nouns, and while the dereferencing assignment
"trick" will work for single conjunctions as well as adverbs, an issue is that
it requires a fixed number of parameters to do so.
linear boxed representation aims to make a representation format that is easier
to manipulate and dereference. Core function is ncA. 4 definitions below:
lrA_z_ =: 1 : '5!:5 < ''u'' NB. linear representation of verb or noun
ismodstring =: 1 : 'if. 0 = 4!:0 <''u'' do. try. q =. m eval catch. 0 return.
end. 1 2 e.~ 4!:0 <''q''else. 0 end. '
ncS=:3 :'z=.y 1 :y label_. 4!:0 <''z'' ' :: _2: NB. nameclass of string
ncA =: 1 : 'if. 3 ~: 4!:0 < ''u'' do. if. m ismodstring do. m ; ncS m else. 0
;~ ''('', m lrA ,'')'' end. else. 3;~ ''('', u lrA ,'')'' end.'
This is an extention of some of my work on double adverbs here:
http://www.jsoftware.com/jwiki/PascalJasmin/double%20adverbs%20vs%20conjunctions
ismodstring returns 1 if the adverb parameter is a string (linear)
representation of an adverb. 0 if not.
+ ismodstring
0
'/\' ismodstring
1
ncS is Dan Bron's (or perhaps someone he "shamelessly stole it" from) adverb
for obtaining the name class of u or m
ncA will make a boxed pair where the first box is the linear (as string)
representation of the adverb parameter, and the 2nd is its type (name class) as
a number. Some extraneous parentheses are added to ensure sane interpretation
when these elements are unboxed and combined into expressions.
(+/ % #) ncA
┌────────┬─┐
│(+/ % #)│3│
└────────┴─┘
'@' ncA
┌─┬─┐
│@│2│
└─┴─┘
('asd';4) ncA
┌─────────┬─┐
│('asd';4)│0│
└─────────┴─┘
Note the last example adds quotes to what were strings, and so you can get out
what you put in.
The only potential problem area is a situation where you want to force a simple
text interpretation instead of a modifier. Its easy to manually create a
compatible represenation, and functionalize it for situations where modifier
interpretations are to be excluded.
'ncA' ncA
┌───┬─┐
│ncA│1│
└───┴─┘
'ncA' lrA ;0
┌─────┬─┐
│'ncA'│0│
└─────┴─┘
tables can be manually built
(+ ncA , - ncA , ; ncA ,: 3 2 1 4 ncA)
┌─────────┬─┐
│(+) │3│
├─────────┼─┤
│(-) │3│
├─────────┼─┤
│(;) │3│
├─────────┼─┤
│(3 2 1 4)│0│
└─────────┴─┘
or from double adverb wiki code:
daF =: 1 : ('a =. (''2 : '', (quote m) , '' u'') label_. 1 : (''u 1 :'' ,
quote a)')
tieB =: 'if. 1 = #@$ n do. n =. ,: n end. n ,~ u ncA' daF
+ - ; 3 2 1 4 ncA tieB tieB tieB
┌─────────┬─┐
│(+) │3│
├─────────┼─┤
│(-) │3│
├─────────┼─┤
│(;) │3│
├─────────┼─┤
│(3 2 1 4)│0│
└─────────┴─┘
note: first (right) parameter needs to be started with ncA, or otherwise made
to be 2 boxed items in the right format
some examples:
eval =: 1 : ' a: 1 : m'
`:6 equivalent
+/ % # ncA tieB tieB 1 :'(;: inv {. |: m)'eval
+/ % # NB. this is verb. without eval would be string.
(+/ % #) 3 2 1 4 ncA tieB 1 : '(;: inv {. |: m) eval'2.5
add an adverb to each "linear gerund item":
amendT =: 2 : ' u hook (n { ]) n} ]'
hook =: 2 : '([: u v) : (u v) '
(,&'/') each amendT 0 "1 + - ncA tieB
┌────┬─┐
│(+)/│3│
├────┼─┤
│(-)/│3│
└────┴─┘
it can be much easier to just drop the type column and modify the "linear
components", but keeping the type column allows you to filter based on type,
and only modify those items. Which can allow binding nouns (pack into your
gerund list) to verbs before binding/inserting modifiers.
The type column exists as a possible formality to disambiguate some conditions
(modifier or string), and allow you to do anything with anything. But its also
easy to simplify and get rid of it.
The simpler version if you assume all linear components are verbs (which is
what above code assumed)
,&'/\' each {.@|: + - ncA tieB
┌─────┬─────┐
│(+)/\│(-)/\│
└─────┴─────┘
or still relatively simple, but keep the type info.
(}. ,~ [: ,&'/\' each {.)&.|: + - ncA tieB
┌─────┬─┐
│(+)/\│3│
├─────┼─┤
│(-)/\│3│
└─────┴─┘
to insert either a middle fork verb or conjunction between "linear components"
boxsert =: 1 : '([ , (boxopen u) , ])/'
'@:' boxsert ,&'/' each {.@|: * + - ncA tieB tieB
┌────┬──┬────┬──┬────┐
│(*)/│@:│(+)/│@:│(-)/│
└────┴──┴────┴──┴────┘
';' boxsert ,&'/' each {.@|: * + - ncA tieB tieB
┌────┬─┬────┬─┬────┐
│(*)/│;│(+)/│;│(-)/│
└────┴─┴────┴─┴────┘
( ;: inv ) obtains an executable linear sentence from components
(;: inv ';' boxsert ,&'/' each {.@|: * + - ncA tieB tieB)
(*)/ ; (+)/ ; (-)/
( eval ) interprets linear sentences can produce any form of speech (verb in
this case)
(;: inv ';' boxsert ,&'/' each {.@|: * + - ncA tieB tieB) eval 1 2 3 4
┌──┬──┬──┐
│24│10│_2│
└──┴──┴──┘
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm