Joey's fun3 illustrates how the tacit form encourages simplification. Very impressive.
Linda -----Original Message----- From: programming-boun...@jsoftware.com [mailto:programming-boun...@jsoftware.com] On Behalf Of d...@shaw.ca Sent: Wednesday, January 04, 2012 11:58 PM To: Programming forum Subject: Re: [Jprogramming] Faster deb Thank you and Linda for this information and help. Don Kelly -----Original Message----- From: Joey K Tuttle Sent: Wednesday, January 04, 2012 8:28 PM To: Programming forum Subject: Re: [Jprogramming] Faster deb How about: fun3 =: ' ' -.~ ] fun3 a nowisthetimeforallgoodmentocometotheaidoftheircountry On 2012/01/04 20:05 , Linda Alvord wrote: > Some hints to create a tacit verb: > > > a=.' now is the time for all good men to come to the aidof their > country > ' > (0<-.' ' E.a)#a > nowisthetimeforallgoodmentocometotheaidoftheircountry > > See if you can write a simple expression that gives the result you want. > Then if it is monadic, simply begin name=: 13 : and enter the > expression > with y for the argument. Inside a set of single quotes, you must use > double > quotes. > > fun2=: 13 :'(0<-.'' ''E.y)#y' > fun2 > ] #~ 0< [: -. ' ' E. ] > > The display of the tacit expression will have been created for you. > > fun2 a > nowisthetimeforallgoodmentocometotheaidoftheircountry > > And it should work in the same way that your sample worked. > > Linda > > -----Original Message----- > From: programming-boun...@jsoftware.com > [mailto:programming-boun...@jsoftware.com] On Behalf Of d...@shaw.ca > Sent: Wednesday, January 04, 2012 9:08 PM > To: Programming forum > Subject: Re: [Jprogramming] Faster deb > > How about using E. ? > > fun=:verb define > s=.0< -. ' 'E.y > s#y > ) > > a=.' now is the time for all good men to come to the aid of their country > ' > > fun a > nowisthetimeforallgoodmentocometotheaidoftheircountry > > the result is not boxed but leading and trailing blanks are removed. > The timing is, on my now obsolete machine (Athlon 64 5600+ (brisbane > 65nm) > > and 200Mhz bus) > > 1000(6!:2)'fun a' > 8.91696e_6 > > I am a novice so I am having problems putting fun into a tacit form- lots > of > > trial and error. > Essentially, I am taking an APL approach to the problem. > > Don Kelly > cross out to reply > > > -----Original Message----- > From: Marshall Lochbaum > Sent: Wednesday, January 04, 2012 9:41 AM > To: Programming forum > Subject: Re: [Jprogramming] Faster deb > > If you really want top-of-the-line performance, you'll have to go to a > sequential machine. Here's my solution, which leaves the leading and > trailing blanks in, then specifically deletes them. > I don't claim that these tests are universal; it's quite plausible that a > different mixture of blanks and words would give different results. > Of course, benefits are marginal, and if performance is REALLY critical, I > would advise just wasting the 20 lines and 10 minutes that it takes to > code > the thing in C. > > ws =. ' ',TAB,LF > dlb =. }.^:(ws e.~{.) NB. delete leading blank > dtb =. }:^:(ws e.~{:) NB. delete trailing blank > > m =. ws -.@:e.~ a. > s =. 2 2 2$ 0 1 1 2 0 2 1 0 > sdeb =: [: dlb@:dtb (1;s;m)&;: > > fdeb =: [: dlb [ #~ [: -. [: (] *. 1&|.) ' ' = [ > > test =. ; ' test'&,&.> (1e5?@$10)<@$"0 ]' ' > 100 (6!:2) 'deb test' > 0.0167294 > 100 (6!:2) 'sdeb test' > 0.012571 > 100 (6!:2) 'fdeb test' > 0.0162943 > (deb -: sdeb) test > 1 > (deb -: fdeb) test > 1 > > Marshall > > On Wed, Jan 4, 2012 at 11:53 AM, Ian Clark<earthspo...@gmail.com> wrote: > >> okay, I didn't read Raul's posting properly. >> >> On Wed, Jan 4, 2012 at 4:44 PM, Ian Clark<earthspo...@gmail.com> wrote: >>> Raul's points are valid, but as a technique I like it. I'm going to >>> add it to my collection of idioms for a monograph on string-handling. >>> >>> Rotate-and-compare can be generalized to detect any given letter >>> followed/preceded by some other. But in the speed stakes, there's >>> often extra housekeeping handling the string ends. >>> >>> Harking back to a recent thread where (;:inv) came up, how about these >> too? >>> wdeb=: ;:inv @ ;: >>> udeb=: ]&. ;: NB. a faster variant of the same idea >>> >>> Not as fast as either deb or fdeb, (besides mishandling punctuation) >>> but with a certain idiot appeal. And try replacing (]) with (|.), >>> (~.), sort, etc. >>> >>> In my monograph, (;:) will have a chapter to itself. >>> >>> >>> On Wed, Jan 4, 2012 at 1:54 PM, Raul Miller<rauldmil...@gmail.com> >> wrote: >>>> As you point out, these are not equivalent. >>>> >>>> # TEST=: ' this is a test ' >>>> 26 >>>> # deb TEST >>>> 14 >>>> # fdeb TEST >>>> 15 >>>> >>>> Note also: >>>> # ]&.;: TEST >>>> 14 >>>> >>>> That said: >>>> # ]&.;: ' Don''t do this... ' >>>> |open quote >>>> >>>> Also, the timing difference between 3.446e_6 and 3.293e_6 is >> inconsequential. >>>> -- >>>> Raul >>>> >>>> On Wed, Jan 4, 2012 at 2:14 AM, Alan Stebbens<a...@stebbens.org> wrote: >>>>> "delete extra blanks" from strings.ijs has this definition: >>>>> >>>>> deb =: #~ (+. (1: |. (> </\)))@(' '&~:) >>>>> >>>>> NB. Here is a slightly faster deb: >>>>> >>>>> fdeb =: [ #~ [: -. [: (] *. 1&|.) ' ' = [ >>>>> >>>>> NB. s is the test string; w is its boxed words >>>>> >>>>> w=.;:s=.'now is the time for all good men to come to the aid of >> their country' >>>>> w >>>>> +---+--+---+----+---+---+----+---+--+----+--+---+---+--+-----+-------+ >>>>> |now|is|the|time|for|all|good|men|to|come|to|the|aid|of|their|country| >>>>> +---+--+---+----+---+---+----+---+--+----+--+---+---+--+-----+-------+ >>>>> >>>>> NB. show >>>>> 1000 tx 'deb ,>w' >>>>> 3.446e_6 3072 >>>>> >>>>> 1000 tx 'fdeb ,>w' >>>>> 3.293e_6 3072 >>>>> >>>>> NB. same value for both the old and new fun >>>>> (deb -: fdeb),>w >>>>> 1 >>>>> >>>>> NB. the results match the original string >>>>> s -: fdeb ,>w >>>>> 1 >>>>> >>>>> However, it's not exactly the same as deb: it doesn't remove a single >> leading blank, as does deb (which, IMHO, is not necessarily an "extra" >> blank anyway). >>>>> Alan >>>>> >>>>> ---------------------------------------------------------------------- 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