I don't agree that Amend is seldom useful. I do agree that it isn't the
easiest thing to get your head around (perhaps why you have found other
ways to getting stuff done).

Aai has shown how to tacitly use Amend so it seems that 13 : is not smart
enough to give you a tacit equivalent. I suspect the reason Amend has been
defined as an adverb is that it requires 3 arguments: the array to amend,
the indicies to amend, the replacement data. Compare that to From which
only requires 2 bits of info (the array, the indicies).



On Sun, Jul 6, 2014 at 7:53 PM, Ian Clark <[email protected]> wrote:

> 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

Reply via email to