You can avoid the overhead of memory allocation for the ( a,:b ) part by recognizing that ( c{ ) can access "a" and "b" in-place without building the joined array. Why this happens for the assignment case and not generally, I don't know but I suspect Raul is on the right track with the insight that idiom recognition needs to be simple to avoid overhead for the non-idiomatic cases.
However, when you're parsing the assignment case, you'd know that you're going to allocate non-temporary memory - which incurs a potentially large penalty - and this might be a cue to spend more time on idiom recognition (which is kind of what Raul said). On Thu, Dec 22, 2011 at 12:58 PM, David Vaughan < purpleblue...@googlemail.com> wrote: > Why should there be any speed up just from assigning the phrase to a noun? > Surely in both cases the same code has to be executed, one will display the > result, one will store the result? > > ___________________________ > > David Vaughan > > On 22 Dec 2011, at 17:46, Raul Miller <rauldmil...@gmail.com> wrote: > > > Actually, I think he was asking why the speedup is not available without > the =: > > > > And I think that has to do with "ease of implementation". > > > > Also, if there's no =: then that syntax is almost certainly being used > > to generate a noun -- it's not being used to build a repeatable > > operation. You'd have to use different syntax to generate a useful > > verb. > > > > -- > > Raul > > > > On Thu, Dec 22, 2011 at 12:24 PM, Devon McCormick <devon...@gmail.com> > wrote: > >> In a word: performance. > >> > >> a=. 1e6?@$0 > >> b=. <:+:1e6?@$0 > >> c=. 1e6?@$2 > >> > >> 10 ts 'r=. c}b,:a' > >> 0.0066557413 8390912 > >> 10 ts 'c}b,:a' > >> 0.021307987 41945088 > >> > >> > >> On Thu, Dec 22, 2011 at 11:00 AM, Johann Hibschman < > jhibsch...@gmail.com>wrote: > >> > >>> Thanks, everyone. I never understood item-amend until now. That's > >>> exactly what I was looking for. For context, I was reading through the > >>> APL book and hit the "/a,u,b/" notation, and wondered how to do that > >>> in J. > >>> > >>> One question though: why is the particular form (result=:c}b,:a) > >>> singled out, rather than the general (c}b,:a)? > >>> > >>> On Wed, Dec 21, 2011 at 10:54 AM, Henry Rich <henryhr...@nc.rr.com> > wrote: > >>>> Note that > >>>> > >>>> c}b,:a > >>>> > >>>> does indeed compute b,:a. But if it's used in the precise form > >>>> > >>>> result =: c}b,:a > >>>> > >>>> the computation is avoided. > >>>> > >>>> b =: 1e6$4 > >>>> a =: 1e6$4 > >>>> c=: ? 1e6$ 2 > >>>> ts 'c}b,:a' > >>>> 0.0401299 2.09725e7 > >>>> ts 'q =: c}b,:a' > >>>> 0.0112949 4.19558e6 > >>>> > >>>> There are other special cases; see the Special Code page. > >>>> > >>>> Henry Rich > >>>> > >>>> On 12/21/2011 11:43 AM, Marshall Lochbaum wrote: > >>>>> A more obvious way is to use (c { b,.a) . The key is to realize that > >>> saying > >>>>> (if c then a else b) is just selection: if c is 0, we pick b, and if > c > >>> is > >>>>> 1, we pick a. So we rephrase as (c { b,a), and J's implicit rank > allows > >>> us > >>>>> to do (c { b,.a) for vector c, a, and b. > >>>>> > >>>>> That said, (c} b,:a) is faster, and uses less memory by not actually > >>>>> computing b,:a . So it's a better choice. > >>>>> > >>>>> Marshall > >>>>> > >>>>> On Wed, Dec 21, 2011 at 10:26 AM, Brian Schott< > schott.br...@gmail.com > >>>> wrote: > >>>>> > >>>>>> One way is the following. > >>>>>> > >>>>>> c}b,:a > >>>>>> 10 2 30 > >>>>>> > >>>>>> > >>>>>> -- > >>>>>> (B=) > >>>>>> > ---------------------------------------------------------------------- > >>>>>> 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 > >>> > >> > >> > >> > >> -- > >> Devon McCormick, CFA > >> ^me^ at acm. > >> org is my > >> preferred e-mail > >> ---------------------------------------------------------------------- > >> 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 > -- Devon McCormick, CFA ^me^ at acm. org is my preferred e-mail ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm