I get
5#''
(5#'')*/i.5
''*/i.5
NOTE-. blank line
using J802
Don Kelly
On 10/09/2014 4:16 PM, Linda Alvord wrote:
Dan, after your 4 series, I tried this. Also odd:
NB. Begin here
5#''
(5#'')*/i.5
''*/i.5
''
NB. Note the spacing between lines above
Linda
-----Original Message-----
From: programming-boun...@forums.jsoftware.com
[mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Dan Bron
Sent: Wednesday, September 10, 2014 11:56 AM
To: programm...@jsoftware.com
Subject: Re: [Jprogramming] Replace one item of a list
Linda wrote:
*i.5
0 1 1 1 1
*/"0 i.5
0 1 2 3 4
Joe wrote:
It looks like /"0 yields the right side without evaluating the left side
asdfasdf/"0 i.5
0 1 2 3 4
I don't totally get it myself
This boils down to foo/ scalar_value .
Note that because of the "0 (meaning "apply to each scalar value
individually")
asdfasdf/"0 i.5
0 1 2 3 4
is equivalent to
(asdfasdf/ 0),(asdfasdf/ 1),(asdfasdf/ 2),(asdfasdf/
3),(asdfasdf/ 4)
0 1 2 3 4
In Linda's example, asdfasdf is *, so her example is
(*/ 0),(*/ 1),(*/ 2),(*/ 3),(*/ 4)
0 1 2 3 4
And this is quite different from the other expression she contrasts it
with, which is
*i.5
0 1 1 1 1
which, because monad * (signum) is a scalar function, is equivalent to:
*"0 i.5
0 1 1 1 1
which, after expanding in the same manner as above, is equivalent to:
(* 0),(* 1),(* 2),(* 3),(* 4)
0 1 1 1 1
Note the lack of any / which is the key issue here. That is, the
difference Linda spotted boils down to the difference between these two
expressions:
*/ 4
4
* 4
1
Now, *4 is 1 because 4>0 ; no mystery there. But why does */4 produce
4 ? Well, */ is product, and
*/ 4 4 4 4 NB. Product of four 4s is 4^4, 256
256
*/ 4 4 4 NB. Product of three 4s is 4^3, 64
64
*/ 4 4 NB. Product of two 4s is 4^2, 16
16
*/ 4 NB. Product of one 4 is 4^1, 4
4
And in general, foo/ scalar_value (or asdfasdf/ scalar_value) is simply
scalar_value . Because foo/ noun says "insert foo between all _pairs
of items_ in noun", but when noun is scalar_value, there _are no pairs_,
so no insertion is done.
-Dan
PS: and, of course,
*/ '' NB. Product of zero "4s" is 4^0, 1
1
There are no pairs to insert * between here, either, but empty arguments
gets into identity functions.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm