> Better how? Time? Space? Compactness?
Better than the "code smell" of using amend, according to the previous discussion On 7/10/14, Ben Gorte - CITG <[email protected]> wrote: > I am often in situations where I want to put a lot of (image) measurements > in a grid. I know what values I have to put at which positions, but I do not > have the entire set (sensor malfunctioning). > > This simulates it. From > M =: ?1000 1000$5 > my sensor takes: > i=.4$.$.M > v=.5$.$.M > $i > 800076 2 > > So I have 800076 values v and indexes i, which I want to put in a 1000 by > 1000 grid, filling up de holes with 0-s: > > N =: v (;/i) } 1000 1000$0 > > And of course: > N -: M > 1 > > Is there a better way to do this? > > Ben > ___________________________ > From: [email protected] > [[email protected]] on behalf of Dan Bron > [[email protected]] > Sent: Tuesday, July 08, 2014 02:23 > To: [email protected] > Subject: Re: [Jprogramming] Tacit J and indexed replacement > > Do you have examples, in practice, where you've wanted to modify one item > (or a sublist) from a data structure? > > Would you say those circumstances are the exception or the rule? (I'm asking > because it's definitely the exception in my own experience, and more often > than not a "code smell"). > > -Dan > > Please excuse typos; sent from a phone. > >> On Jul 7, 2014, at 8:14 PM, "'Pascal Jasmin' via Programming" >> <[email protected]> wrote: >> >> I think } (dyadic amend) is pretty essential. The obvious use is amending >> one (or sublist) item from a data structure. >> >> Item amend maybe a little more esoteric, but I find it easy to >> conceptualize, and use the "verbified" form 4 : 'x}y' as a "natural" way >> of implementing the example in this thread. >> >> >> ----- Original Message ----- >> From: Dan Bron <[email protected]> >> To: [email protected] >> Cc: >> Sent: Monday, July 7, 2014 7:42:35 PM >> Subject: Re: [Jprogramming] Tacit J and indexed replacement >> >> Pepe, I'm with Ian and Henry on this one: questions of efficiency aside, >> I >> rarely find a call for } . The only place I really use it is in the >> expression ('A'&=)`(,:&'B') } to make scalar substitutions. So I'm >> interested in where you find uses for it. >> >> Do you have specific examples? Would you say you reach for } when >> efficiency is a concern, even if the thought could be expressed more >> conveniently using some other tool, or that you've found places where } >> is the best way to say what you want to say? If the latter (} is the >> word >> you want), are there any particular characteristics that tie those use >> cases together? >> >> I personally find (bearing in mind that I'm a J hobbyist, and [no longer] >> a >> professional) that I mostly think in terms of items, and modifying >> anything below the level of an item would be quite unusual in my code, >> and >> make me suspicious. Similarly, I almost always treat all items >> identically, and a consistent need to treat just some items specially >> would make me suspicious, and I'd wonder whether I should be structuring >> my data differently. >> >> With that said, I certainly (especially in my "professional J-ing" days) >> see the benefit of } for performance. But I'm wondering if you've >> invented or discovered generally beneficial uses of } unrelated to >> performance. I'd be very interested in that, if so ('cause the only one >> I >> ever invented or discovered was, as I said, scalar substitution). >> >> -Dan >> >> ----- Original Message --------------- >> >> Subject: Re: [Jprogramming] Tacit J and indexed replacement >> From: Jose Mario Quintana <[email protected]> >> Date: Mon, 7 Jul 2014 19:12:55 -0400 >> To: Programming forum <[email protected]> >> >> Ian wrote: >> " >> And the reason for that has less to do with finding it "hard to get my >> head >> round Amend" than the fact that "in-place array modification" is a >> technique that goes hand-in-hand with a scalar approach to >> problem-solving, >> which is not what J is designed to do well. >> " >> >> How come? In the form (x m} y), x, y and m are all allowed to be >> arrays, >> are they not? >> >> Ian wrote: >> " >> I still >> stand firmly by what Henry and I wrote in the NuVoc page on Amend: >> >> x m} y is used in J much less than you would think, considering the >> importance of in-place array modification in other languages. >> " >> >> I also stand firm by what I wrote (no offense): >> >> "I find the forms <@:v N} ] and v N} ] extremelly useful for writing >> tacitly." >> >> That is, when the task at hand goes beyond to dealing with one or two >> (tacit) arguments and joggling intermediate results with forks or alike >> (and the tacit sentence (paragraph, chapter, section, book,...) is meant >> to >> be efficient). >> >> :) >> >> Actually, I think, both statements (yours and mine) can stand because few >> J >> users are willing to go that far tacitly. >> >> >> >>> On Mon, Jul 7, 2014 at 3:22 AM, Ian Clark <[email protected]> wrote: >>> >>> Thanks, guys, keep the ideas coming. There's enough been said in this >>> thread to enable me to substantially improve the NuVoc presentation of >>> Amend in http://www.jsoftware.com/jwiki/Vocabulary/curlyrt#dyadic - >>> which >>> I >>> think most would agree doesn't present Amend in the most appealing >>> light. >>> Perhaps unfairly so. >>> >>> In particular, I like Aai's idea: >>> >>> zero =: 0:`[`]} >>> 3 5 zero i.9 >>> 0 1 2 0 4 0 6 7 8 >>> >>> (BTW I realize this not the form he delivered it in) >>> >>> which I think ought to replace the present cumbersome NuVoc example. >>> >>> Raul asks, as usual, "what am I trying to do?" Adopting the role of a J >>> novice, I have to reply "learn J of course" - by the expedient of >>> learning >>> the utility and usage of J's primitives, viewed as a toolkit. But if I >>> come >>> clean about my own personal motives, it's to write a good NuVoc page >>> which >>> helps a complete J novice understand Amend and what it's good for - if >>> anything. >>> >>> I reject the insinuation that I use Amend less than I might because I'm >>> not >>> smart enough. A J novice, experienced in another language, would feel >>> patronized by such a suggestion. Moreover she would find it hard to >>> resist >>> the impression that J-jocks were covering up for a grave defect in the >>> language. And I was lying when I said I didn't have much use for Amend. >>> But >>> I wanted to play devil's advocate in support of Erling's criticism, >>> because >>> I believe he speaks for most newcomers trained on a "scalar" language >>> like >>> C. >>> >>> For all the splendid, creative ways of force-feeding Amend into >>> submission >>> I've seen in this thread (e.g. by using a gerund for operand "m") I >>> still >>> stand firmly by what Henry and I wrote in the NuVoc page on Amend: >>> >>> x m} y is used in J much less than you would think, considering the >>> importance of in-place array modification in other languages. >>> >>> And the reason for that has less to do with finding it "hard to get my >>> head >>> round Amend" than the fact that "in-place array modification" is a >>> technique that goes hand-in-hand with a scalar approach to >>> problem-solving, >>> which is not what J is designed to do well. So Raul's question "what am >>> I >>> trying to do?" turns out to be appropriate after all, when it comes to >>> using Amend. Or using something else - like (*) or (#) with a Boolean >>> list. >>> >>> >>>> On Mon, Jul 7, 2014 at 4:58 AM, Raul Miller <[email protected]> >>>> wrote: >>>> >>>> Since it'w nagging at me (and this is still unteted code :/), here's >>>> what I currently think i should have said: >>>> amend=: (0:{::])`(1:{::])`(2:{::])}~ >>>> >>>> The trailing ~ because I need the dyad from the resulting verb, and >>>> the trailing ] on each because those verbs need to ignore one of the >>>> resulting arguments. >>>> >>>> Sadly, my fingers (and "quick memory") keep forgetting this. >>>> >>>> Thanks, >>>> >>>> -- >>>> Raul >>>> >>>>> On 7/6/14, Raul Miller <[email protected]> wrote: >>>>> Meh, no, that won't work. >>>>> >>>>> Stick with Jose's version. >>>>> >>>>> (I also don't have the feature enabled which lets me cancel sending an >>>>> email after "sending" it.) >>>>> >>>>> I'll just go do some "practical" work now... >>>>> >>>>> Sorry for the noise. >>>>> >>>>> -- >>>>> Raul >>>>> >>>>>> On 7/6/14, Raul Miller <[email protected]> wrote: >>>>>> Oops, yes. Sorry about that. >>>>>> >>>>>> I should have said: >>>>>> amend=: (0:{::)`(1:{::)`(2:{::)}~ >>>>>> >>>>>> (I'm working right now from a machine where J doesn't run, and I >>>>>> forget details when I don't test my code.) >>>>>> >>>>>> Thanks, >>>>>> >>>>>> -- >>>>>> Raul >>>>>> >>>>>>> On 7/6/14, Jose Mario Quintana <[email protected]> >>>>>>> wrote: >>>>>>> Raul wrote: >>>>>>> " >>>>>>> For example: >>>>>>> amend=: 0&{::`(1&{::)`(2&{::)} >>>>>>> amend 0;2 3 5;7#9 >>>>>>> 9 9 0 0 9 0 9 >>>>>>> " >>>>>>> >>>>>>> Actually, >>>>>>> >>>>>>> JVERSION >>>>>>> Installer: j602a_win.exe >>>>>>> Engine: j701/2011-01-10/11:25 >>>>>>> Library: 6.02.023 >>>>>>> >>>>>>> amend=: 0&{::`(1&{::)`(2&{::)} >>>>>>> amend 0;2 3 5;7#9 >>>>>>> |rank error: amend >>>>>>> | amend 0;2 3 5;7#9 >>>>>>> |[-3] >>>>>>> >>>>>>> However, >>>>>>> >>>>>>> amend=. _: 0&{::@]`(1&{::@])`(2&{::@])} ] >>>>>>> amend 0;2 3 5;7#9 >>>>>>> 9 9 0 0 9 0 9 >>>>>>> >>>>>>> I use a slight variation of this verb occasionally; yet, I find the >>>>>>> forms >>>>>>> <@:v N} ] and v N} ] extremelly useful for writing tacitly (and I >>> write >>>>>>> tacitly all the time). >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Sun, Jul 6, 2014 at 6:42 AM, Raul Miller <[email protected]> >>>>>>> wrote: >>>>>>> >>>>>>>> I would agree that amend is seldom useful in much the same way that >>>>>>>> computers are seldom useful. That is: it depends on what you mean >>>>>>>> by >>>>>>>> "seldom" (and, for that matter, "useful"). >>>>>>>> >>>>>>>> Generally speaking, } is one of the less common characters that I >>> use >>>>>>>> when I write in J, but I do use it. >>>>>>>> >>>>>>>> Also, in addition to the very fine 0:`[`]} which behaves something >>>> like >>>>>>>> this: >>>>>>>> >>>>>>>> 2 3 5 0:`[`]} 7#9 >>>>>>>> 9 9 0 0 9 0 9 >>>>>>>> >>>>>>>> (Aside: note that in the above expression 2 3 5 is a word, and 0: >>> is a >>>>>>>> separate word. Try ;:'2 3 5 0:`[`]} 7#9' if you want proof.) >>>>>>>> >>>>>>>> ... in addition to that approach, you can also arrange so that all >>>>>>>> arguments are given in an argument list, if you use >>>>>>>> 0&{::`(1&{::)`(2&{::)} >>>>>>>> >>>>>>>> For example: >>>>>>>> amend=: 0&{::`(1&{::)`(2&{::)} >>>>>>>> amend 0;2 3 5;7#9 >>>>>>>> 9 9 0 0 9 0 9 >>>>>>>> >>>>>>>> But, as with everything, whether this is a good thing or not >>>>>>>> depends >>>>>>>> on what you are trying to do... >>>>>>>> >>>>>>>> Which leads back to the question: what are you trying to do? >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> -- >>>>>>>> Raul >>>>>>>> >>>>>>>>> On 7/6/14, Ric Sherlock <[email protected]> wrote: >>>>>>>>> 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 >>> ---------------------------------------------------------------------- >>>>>>>> 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 >> ---------------------------------------------------------------------- >> 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
