Oh, in the case that N is a (possibly repeated?) element of A, rather than an 
index into A [1] then: 

      anotherPhrase =: adverb def (':';'(x=y)}y,:u x')

or tacitly:

      anotherPhrase =: (,:`) (`:6) (@:>) (@:{.) (=&>/`) } (@:,) (&:<)

Again untested. (The tacit isn't worth it in this case - we don't have a 
gerundial amend with the right semantics to make it pretty).

-Dan



Please excuse typos; composed on a handheld device.

-----Original Message-----
From: Raul Miller <[email protected]>
Sender: [email protected]
Date: Tue, 23 Nov 2010 17:24:49 
To: Programming forum<[email protected]>
Reply-To: Programming forum <[email protected]>
Subject: Re: [Jprogramming] A phrase for amendment

On Tue, Nov 23, 2010 at 5:05 PM, Justin Paston-Cooper
<[email protected]> wrote:
> What is a common phrase for replacing element n in an array a by
> itself applied to a monad m?

Note that m is often used to refer to nouns rather than verbs,
(in explicit adverbs and conjunctions) so lets use M instead of m.
Also, 'a' is an english word, so let us use A instead of a.  And,
for consistency and emphasis, let us use N in place of n.

The most common phrase is:
   M A

Of course, this replaces all of A with the result of M, but
that is usually good practice.  But this means that you
have to pull the conditional logic into the definition of M
which sometimes may be an issue.

If A is numeric, you can use
   A + (N=A) * (M A)-A

Or, if you want a tacit version of that:
   N (] - = * (- M)@]) A

If A has only one dimension, you can use:
   (M (N=A)#A) (I.N=A)} A

That said, I just now noticed a response from Dan
Bron where he understood N to mean the index of
a value rather than the value itself.  And that is
another possibility.

I suppose the really correct approach, here, would be to ask
what problem you are trying to solve.  This sort of question
(where you are focusing on an  individual element of an array,
rather than the array itself) seems to suggest a problem where
perhaps a better approach could be available than the one you
are trying to apply.  (Or, it would be if I were posing this kind
of question.)

Thanks,

-- 
Raul
----------------------------------------------------------------------
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