4 5(3 (4 5"_)} ] )10+i.10
10 11 12 13 3 3 16 17 18 19
4 5(3 ([)} ] )10+i.10
10 11 12 3 14 15 16 17 18 19
/Erling
On 2014-07-08 11:21, Linda Alvord wrote:
And then!
h=: 3 :'0 x } y'
4 5 h i.11
|domain error: h
| 4 5 h i.11
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On BehalSSf Of Linda Alvord
Sent: Tuesday, July 08, 2014 5:14 AM
To: [email protected]
Subject: Re: [Jprogramming] Tacit J and indexed replacement
Ian's post was very early in this thread, but something has puzzled me for a
while as I tried to write a tacit version:
f=: 13 :'0 x } y'
4 5 f i.11
0 1 2 3 0 0 6 7 8 9 10
g=: 4 :'0 x } y'
4 5 g i.11
0 1 2 3 0 0 6 7 8 9 10
f
4 : '0 x } y'
g
4 : '0 x } y'
4!:0 <'f'
3
4!:0 <'g'
3
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ian Clark
Sent: Sunday, July 06, 2014 3:54 AM
To: [email protected]
Subject: Re: [Jprogramming] Tacit J and indexed replacement
I think Erling is quite right, if you take what he says literally: "Amend
is seldom useful for indexed replacement when you write tacit J".
I'd go further and say "Amend is seldom useful." Period. I write a lot of J
code and I hardly ever use it.
To someone coming from C (say), this cries out for explanation. In C, just
about everything is done by keyhole surgery, i.e. by tinkering with
whatever happens to be at the end of a pointer (read: index). In J, just
about nothing is done that way.
Let me give an example. Suppose I want to write a verb to zero the x'th
element of a list y ...
I can easily write it as an explicit verb:
zero=: 4 : '0 x} y'
3 zero i.6
0 1 2 0 4 5
But "13 :" refuses to give me an equivalent tacit verb ...
13 : '0 x}y'
4 : '0 x}y'
Is this just a shortcoming of "13 :" ? Does anyone know a "nice" tacit
equivalent? I don't.
Contrast this with what happens if I switch round 0 and x (...which gives
me a verb to replace the first element of a list y with x). In this case
"13 :" does deliver me a nice simple tacit equivalent ...
13 : 'x 0}y'
0}
So why doesn't 13 : '0 x}y' do something equally as nice? It's all
explained in http://www.jsoftware.com/jwiki/Vocabulary/curlyrt#dyadic . But
that doesn't really explain to a newcomer why Amend was designed as an
adverb:
x m} y
with (index) m as an *operand*, not an *argument*.
Yes, I can write a tacit verb to zero the x'th element of list y ...
zero2=: 13 : 'y * y~:x'
3 zero2 i.6
0 1 2 0 4 5
zero2
] * ~:
... but not by using Amend, which is quite simply not useful in that role.
Though I'm not claiming it can't be done - in fact there's a worked example
in: http://www.jsoftware.com/jwiki/Vocabulary/curlyrt#dyadic under "More
Information". But I wouldn't call it "nice".
This illustrates the J approach to programming:
http://www.jsoftware.com/jwiki/Vocabulary/Loopless -and how it contrasts
with the C approach. Henry would explain it far better than I can, but he's
busy.
IanClark
On Sat, Jul 5, 2014 at 8:59 PM, Erling Hellenäs <[email protected]>
wrote:
Hi all !
When you write tacit code, the index m used by Amend, syntax description
x m} y, is a constant?
Normally you have a variable you want to use for indexing? This means
Amend is seldom useful for indexed replacement when you write tacit J?
Are there any descriptions of nice ways to do indexed replacement in tacit
J?
As with Amend, the result has to be a new variable, of course.
Cheers,
Erling Hellenäs
----------------------------------------------------------------------
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm