Richard
FWIW, Dyalog APL has had something like the C-type
f= assignment for a long time, so perhaps J could also
achieve this if there was sufficient demand.
So: if f is _any_ dyad, and r x and y nouns, you could do
x f=: y NB. instead of (valid) x =: x f y
[I'm embedding extra line breaks]
NB. APL doesn't really distinguish =. and =:
or
r =: x f=: y NB. instead of x =: x f r =: y
Interestingly, APL assigns y as the "pass-through" value to r
rather than x f y which one might have expected.
A simple example:
A =: 1 2 3 4 5
r =: A+=: 10 NB. APL, this is not valid J!
A
11 12 13 14 15
r
10
and another:
vec =: 3 5 1 _1 _2 4 0 _3 2
vec#~ =: vec>0 NB. APL, this is not valid J!
vec
3 5 1 4 2
Using Raul's modf:
'v' #~ modf v>0 NB. this is valid J!
3 5 1 4 2
or !?!!
'v' (#~>&0) modf v NB. so is this!
3 5 1 4 2
When you get to know J, you might prefer something like
[v =: (#~>&0) 3 5 1 _1 _2 4 0 _3 2
3 5 1 4 2
However, I do like Dyalog's modified assignment and use
it often when in APL.
BTW, modified assignment (with indexed assignment, also not in J!)
allows a nice way of constructing a frequency table:
v =: 1 1 2 1 2 1 2 3 NB. data!
w =: 0#~#~. v NB. initialise table with 3 zeros
w[v i.~ ~. v] +=: 1 NB. APL allows bracket indexed assignment
w
4 3 1 NB. v has 4 ones, 3 twos, 1 three
You can of course do this in J using key, /.
Mike
Raul Miller wrote:
> For what it's worth, here is how to define, in J, a
> word which parallels C's modified assignment
> operations:
>
> modf=:1 :0
> :
> (x)=:(".x)u y
> )
>
>
> Its use pattern is:
>
> quotedname verb modf noun
>
> Its meaning is:
> name =: name verb noun
>
> where name is the name which was quoted.
>
> For example:
> N=:10
> 'N' + modf 3
> 'N' * modf 2
>
> N will have the value 26 after executing these lines.
>
> If any of this needs explaining, please let me know.
>
> FYI,
>
>
and Richard Kubina wrote:
f=:3
(=: >:) f
|syntax error
| (=:>:)f
Why is this not allowed?
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm