Nicholas Spies <[EMAIL PROTECTED]> wrote:
>From the wilderness: Why doesn't this work?!
> get =: 4 : 'x.{ y.'
>
> set =: 4 : '({. x.) (({: x.)}) y.'
The syntax of your primitives is essentially:
index get array
(value,index) set array
This is similar, but not identical to, the J primitives
index { array
value index} array
} is an adverb, but set is a verb.
> inc =: 4 : '((>:(x. get y.))(x.) set y.)'
> dec =: 4 : '((<:(x. get y.))(x.) set y.)'
>
> NB. above gives an error
Of course. You are actually invoking
value index set array
This calls set with an atom (so {. and {: give the same result)
This will produce the same result as
value (index,index) set array
However, since set returns a (probably incorrect) result, you have
value result
which is two nouns in a row, which is illegal
> inc =: 4 : '( 1&+(x. get y.)),( x.) set y.'
> dec =: 4 : '(_1&+(x. get y.)),( x.) set y.'
> a
> 2 0 0 0 0 0 0 0
> ]a =: 0 inc a
> 1 0 0 0 0 0 0 0 0
>
> NB. OK, it puts the 1: at the 0th position... but adds a zero
This is executing
value,index set y. NB. it SHOULD be (value,index) set y.
so, it is basically executing the syntactically correct,
but logically incorrect result:
value, ((index,index) set y.)
Also, you are writing something like:
1&+(x. get y.)
This evaluates
1&+value
which is just the same as
1+value
You don't really need to use bond in places like this,
since it not syntactically necessary, and does not
affect the symbol order. you WOULD want to use it
with things like
+&1 x.get y.
or
-&1 x.get y.
Bond is more common when writing tacit expressions like:
x (1&[EMAIL PROTECTED]) y
or
x ([: 1&+ get) y
although for small constants (_ and _9 ... 9) you can just
write
x (1: + get) y
or under the new J 6
x (1 + get) y
-- Mark D. Niemiec <[EMAIL PROTECTED]>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm