A version that allows either literal or multiline by passing 0
Dadverb =: ':'&; '1 :' oa@:cutLF@:(' 0 :' Cloak)
Dadverb 'x u y'
1 : (':'; 'x u y')
Dadverb 0
x u y
)
1 : (':'; 'x u y')
----- Original Message -----
From: 'Pascal Jasmin' via Programming <[email protected]>
To: Programming Forum <[email protected]>
Sent: Friday, December 2, 2016 12:14 PM
Subject: [Jprogramming] A useful application of Cloak -dyad explicit adverb
I have a slightly different version of the Cloak function that Jose brings up
often. I want it to be an adverb and want it to work with linear trains or
verbs. I also introduce the utility oa: "at(o as Jose calls it) after" which
executes an adverb after a verb (or cloaked function) and its argument applied.
isNoun =: (0 = 4!:0 ::0:)@:<
eval =: 1 : ' a: 1 : m'
aar =: 1 : 'if. isNoun ''u'' do. q =. m eval else. q =. u end. 5!:1 < ''q'' '
Cloak =: (aar(0:`))(,^:)
oa =: 1 : 'u Cloak @:'
I don't think its possible to define the following function any other way.
Dadverb creates an explicit adverb that only has dyadic valence by appending a
header to it.
Dadverb =: ':'&; '1 :' oa
Dadverb 'x u y'
1 : (':'; 'x u y')
2 + Dadverb 'x u y'3
5
The same technique can add any header or footer to a function, or
process/modify it with any verb.
multiline version
Dadverb cutLF 0 : 0
x u y
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm