But that's optimizing a bad idea... Which is probably a lot of fun, but still a bad idea.
So here are some other fun takes on this bad idea: (($,)~ (#~ +./\@:~:&1)@$) (($,)~ (}.~ i.&0@:=&1)@$) -- Raul On Tue, Sep 4, 2012 at 5:13 PM, Henry Rich <henryhr...@nc.rr.com> wrote: > The combination > > ($,) > > has special code. If you remove one of the verbs from the hook, you lose > the special code. > > You can use $, to do Raul's job of discarding leading axes of 1: > > $ flattensingles =: (($,)~ (}.~ 1&(i.&0@:=))@$) i. 1 1 2 3 > 2 3 > > Henry Rich > > > On 9/4/2012 2:55 PM, Peter B. Kessler wrote: >> >> Henry Rich wrote: >>> >>> ''$, '' >>> |length error >>> >>> This one doesn't work when applied to an empty. Sometimes that's >>> desirable. The others work on empties. >>> >>> Note that >>> '' ($,) A >>> >>> has the same result as >>> >>> '' $ , A >>> >>> but the former version is backed by special code & doesn't actually do >>> the enfile. >>> >>> Henry Rich >> >> >> Does it make sense then to encapsulate this knowledge in a "firstOf" verb >> >> firstOfHook =: '' & ($ ,) NB. Does this enfile? >> B + firstOfHook A NB. Plus of B and the flatten of A. >> 7 9 11 >> >> ? How strictly does one have to adhere to the '' ($,) A surface >> syntax to avoid the enfile? >> >> Or (because I find Hooks hard to read) as an At (or, in this case, I >> could use Atop (@)) >> >> firstOfAt =: (('' & $) @: ,) NB. Does this enfile? >> B + firstOfAt A NB. Plus of B and the flatten of A. >> 7 9 11 >> >> Either of those gives me a monad that might be useful in its own right >> >> firstOfAt A NB. Names make things easier to read. >> 4 >> >> in case I was having trouble disentangling the monad on A from the dyad >> with B in the original problem. >> >> ... peter >> >>> On 9/3/2012 4:00 AM, Linda Alvord wrote: >>>> >>>> Thanks to all! >>>> >>>> Kip Murray showed me that I am dealing with a noun that is a table >>>> and not an atom! His solution ,A turns a list into an atom. >>>> >>>> ]A=:1 1$4 >>>> 4 >>>> ]C=:'' >>>> ]B=:3 5 7 >>>> ]B=:3 5 7 >>>> 3 5 7 >>>> >>>> Two alternatives helped: >>>> >>>> B+A >>>> |length error >>>> | B +A >>>> B+{.@,A NB. Bill Lam >>>> 7 8 9 >>>> B+''$,AN NB. Henry Rich >>>> 7 8 9 >>>> B+{.,A >>>> 7 8 9 >>>> >>>> I add the third because I try to avoid @ and I create the problem >>>> most often by using { >>>> >>>> All work if the noun is empty. >>>> C+{.@,A >>>> C+''$,A >>>> C+{.,A >>>> >>>> So this thread really should be called: Table to Atom - First time >>>> around. >>>> >>>> Linda >>>> >>>> -----Original Message----- >>>> From: programming-boun...@forums.jsoftware.com >>>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Henry >>>> Rich >>>> Sent: Monday, September 03, 2012 1:16 AM >>>> To: programm...@jsoftware.com >>>> Subject: Re: [Jprogramming] Scalar to Vector - Yet again >>>> >>>> The easiest way to make a scalar of an arbitrary noun is >>>> >>>> ''($,)A >>>> >>>> which will work on anything except an empty A. >>>> >>>> Henry Rich >>>> >>>> On 9/2/2012 10:52 PM, Roger Hui wrote: >>>>> >>>>> You are (probably) trying to undo years of conditioning in APL, which >>>>> has the misguided "singleton extension": In APL, >>>>> 2 3 4 + (?n⍴1)⍴5 >>>>> worked. Singleton extension is undesirable because it complicates the >>>>> rules for the rank operator. >>>>> >>>>>> It feels wrong to have to do things like this every time I want to >>>>>> use the result of a previous computation called A . >>>>> >>>>> >>>>> Alternatively, it feels wrong that A is non-scalar as computed. >>>>> >>>>> >>>>> >>>>> On Sun, Sep 2, 2012 at 6:48 PM, Linda Alvord >>>>> <lindaalv...@verizon.net>wrote: >>>>> >>>>>> I finally think I know what I don't know. I want to turn "table" A >>>>>> into a scalar (which it happens to look like). >>>>>> >>>>>> A >>>>>> 4 >>>>>> $A >>>>>> 1 1 >>>>>> B=:3 5 7 >>>>>> A+B >>>>>> |length error >>>>>> | A +B >>>>>> (,A)+B >>>>>> |length error >>>>>> | (,A) +B >>>>>> (,3$A)+B >>>>>> 7 9 11 >>>>>> (,($B)$A)+B >>>>>> 7 9 11 >>>>>> >>>>>> It feels wrong to have to do things like this every time I want to >>>>>> use the result of a previous computation called A . >>>>>> >>>>>> Linda >>>>>> >>>>>> -----Original Message----- >>>>>> From: programming-boun...@forums.jsoftware.com >>>>>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of Linda >>>>>> Alvord >>>>>> Sent: Saturday, September 01, 2012 7:26 PM >>>>>> To: programm...@jsoftware.com >>>>>> Subject: Re: [Jprogramming] Scalar to Vector - Yet again >>>>>> >>>>>> I wasn't thinking. A isn't a scalar. I even knew it had shape 1 1 . >>>>>> >>>>>> A >>>>>> 4 >>>>>> $A >>>>>> 1 1 >>>>>> $3 2 >>>>>> 2 >>>>>> 2$A >>>>>> 4 >>>>>> 4 >>>>>> 3 2 + ,2$A >>>>>> 7 6 >>>>>> >>>>>> This works! Thanks. >>>>>> >>>>>> Linda >>>>>> >>>>>> -----Original Message----- >>>>>> From: programming-boun...@forums.jsoftware.com >>>>>> [mailto:programming-boun...@forums.jsoftware.com] On Behalf Of km >>>>>> Sent: Saturday, September 01, 2012 6:10 PM >>>>>> To: programm...@jsoftware.com >>>>>> Subject: Re: [Jprogramming] Scalar to Vector - Yet again >>>>>> >>>>>> ,4 is a vector >>>>>> >>>>>> Sent from my iPad >>>>>> >>>>>> >>>>>> On Sep 1, 2012, at 4:56 PM, "Linda Alvord" <lindaalv...@verizon.net> >>>>>> wrote: >>>>>> >>>>>>> I vow to remember how to do this, and several months later I forget >>>>>>> and can't find it >>>>>>> >>>>>>> anywhere. Is there some way to get to the example from the >>>>>>> vocabulary >>>>>> >>>>>> page? >>>>>>> >>>>>>> Maybe I can remember that. >>>>>>> >>>>>>> >>>>>>> >>>>>>> A=:1 1$4 >>>>>>> >>>>>>> 3 2 + A >>>>>>> >>>>>>> |length error >>>>>>> | 3 2 +A >>>>>>> >>>>>>> >>>>>>> >>>>>>> Thanks. >>>>>>> >>>>>>> >>>>>>> >>>>>>> Linda >>>>>>> >>>>>>> -------------------------------------------------------------------- >>>>>>> -- 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