One useful example to having parameter access inside conjunctions is this short
circuiting conjunction which (tries to) submits each atom of x to x u y but
aborts if too many (function of n and x) return false.
atleastx=: 2 : 0
NB. short circuit application of u if more accumulated falses than #x - n
NB. in x u"0 _ y. return last x if at least n are true. false if not.
brk=. n -~ #x
f=. 0
while. brk > f do.
'h x'=. xxs x
f =. f + 0=(h u"0 _ y)
if. 0=#x do. if. brk > f do. h end. end.
end.
0
)
xxs =: ({.);(<@:}.)
----- Original Message ----
From: Pascal Jasmin <[EMAIL PROTECTED]>
To: General forum <[email protected]>
Sent: Monday, October 2, 2006 10:41:42 AM
Subject: [Jgeneral] conjunction definition problem- bug.
there is a problem accessing the x parameter in conjunction definitions that
create a dyadic verb, with a noun right argument.
t1
2 : ' x ; y '
t2
2 : ' m ; n '
t4
2 : '(u y) ; v y'
t
2 : 'if. n do. x u y end.'
(2 t2 3)
+-+-+
|2|3|
+-+-+
(2 t1 3)
+-+-+
|2|3|
+-+-+
(+: t4 *:) 2 3
+---+---+
|4 6|4 9|
+---+---+
1 (+ t 3) 2
|domain error
t5=: 2 : 'y ' NB. returns verb or noun bound to conjunction.
2 (+ t5 +) 3
5
2 (+ t5 -) 3
_1
I would very much appreciate some mechanism for always retrieving the left and
right arguments to the bonded conjunction (as x and y). I appreciate the issue
of polymorphic conjunctions (can accept either noun or verb arguments), but
these are rare and annoying to implement.
A foreign (!:) could be used to test conjunction arguments for whether they are
verbs or nouns, but probably a better approach to developing polymorphic
conjunctions would be the : separator used to distinguish monads and dyads.
Polymorphic Conjunctions could have up to 3 sections.
2 : 0
u v
:
u n NB.(use convention for noun and verb argument to always be on same sides)
:
m n
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm