I personally only discovered the "&.:" variant of "&." very recently.  I
was working on an introductory example of finding the distance between two
points and it occurred to me that "the square root of the sum of the
squares" should apply an inverse under summation.  I was initially
frustrated that "&." did not work but eventually discovered that "&.:" does.

I've documented my travails here -
http://www.jsoftware.com/jwiki/NYCJUG/2013-01-08/#Distance_Between_Two_Points_in_J-
with my discovery here -
http://www.jsoftware.com/jwiki/NYCJUG/2013-01-08/#Back_to_Basics_and_Beyond.

Also, I've recently had occasion to use the embedded (n : 0) in a simple
sequence I've been invoking to help me time when I start and end a note I'm
taking.  Assigning the initial expression shown below to a key sequence in
emacs (under which I'm running J console) gives the start time when I start
the note and the end time when I close the note with a solitary closing
parenthesis ")" , as demonstrated here:

   ($0 : 0),~  qts'' [ smoutput qts''
2013 2 14 12 58 6.093
Example of writing a time-stamped note.
)
2013 2 14 12 58 16.842 40

This shows the starting time, then the ending time followed by the shape of
my note, where "qts" is simply
   qts
6!:0




On Wed, Feb 13, 2013 at 12:19 PM, Raul Miller <[email protected]> wrote:

> If you are struggling to learn J's grammar, here are some resources:
>
> Overview:
> http://www.jsoftware.com/docs/help701/dictionary/samp03.htm
>
> Details:
> http://www.jsoftware.com/docs/help701/dictionary/partsofspeech.htm
> and appendix ii at
> http://www.jsoftware.com/docs/help701/dictionary/contents.htm
> especially section E:
> http://www.jsoftware.com/docs/help701/dictionary/dicte.htm
>
> There's also a trace facility. I think I used to be able to use it
> using require'trace' but today when I experimented I wound up using it
> like this:
>
> require 'addons/general/misc/trace.ijs'
>
> T=: trace [ smoutput
>
> T 'remel_base_ =: ([ }.~ [: >: i.)"_ 0'
>
> T 'allfactors_base_ =: af q:'
>
> T 'af_base_ =: [ , 4 : 0 ^: (*@#@])'
>   x (% af&.>(;@:) y <@remel ]) ~.y
> )
>
> Note that using trace with names is quirky at the moment. The current
> implementation of trace is not aware of the locale it is being
> referenced from, and executes the expressions in its own locale.
> Furthermore, there's no trivial way of having trace be aware of local
> values, so if I wanted to use trace in the body of af I would have to
> do some significant work to deal with stacking of arguments (I'd do
> that by creating a new locale for each instance of af, setting an x
> and y within that locale, and then I'd coinsert the jtrace locale in
> this new locale and refer to a trace within that locale for the
> evaluation - and then cleanup afterwards)
>
> (It might be possible to work around these issues using tacit code to
> extract local names and their definitions, along with the current
> locale. And then tacit code again to modify any local names which had
> been updated during the trace, before finally returning the result.
> But I have not thought enough about this issue,)
>
> --
> Raul
>
> On Tue, Feb 12, 2013 at 5:32 PM, Alex Giannakopoulos
> <[email protected]> wrote:
> > Marshall Lochbaum wrote:
> >> [this version of]
> >> af uses a bit refactoring to avoid having to write the case where y is
> > empty...
> >
> > Marshall I almost missed your post, just read it...
> > I really like the way you use ^:  as a replacement for recursion, but I
> had
> > NO IDEA that the syntax you have used was remotely possible.
> > Really need some more coherent documentation...
> > First off, prepending a value before the  4:0  ???  Wow.  OK I'll let
> that
> > one ride...
> > Next,  ^: (* @ # @ ])  after the 4:0  ???  Brilliant, I love it, but
> where
> > is it documented? (pretty please)
> > So the above is acts as a loop, telling it how many to perform the
> "power"
> > operator, yes?  With any thing executable permitted as argument?  Very
> > powerful.
> >
> > Which brings me to my main point:  I suppose all the scoping problems
> > arose  because I couldn't figure out how to express the mapping function,
> > remember...
> >   (map (lambda (x) (af (/ num x) (remel divisors x)))
> > Now if you look at Marshall's code,  and also Raul's pretty little
> > execution using the fork so handily
> >   ;num; (num&% af divisors&remel)  &. > uniquefactors
> >
> > Both are making use in some form of this idiom, which I have called "verb
> > under unbox".
> > It seems to facilitate the mapping somehow, but I am not totally clear
> how
> > this is happening.
> > It does seem powerful though, I tried a few things interactively.
> > Any pointers to documentation for this, or any words of wisdom?
> >
> > ===
> >
> > I must say, up to now J has often impressed me, surprised me, or caused a
> > little smile to be raised.
> > However, working through this example and the helpful suggestions, I can
> > say this is the first time I actually actively enjoyed it, i.e. without a
> > feeling of repidation!
> > Shurely shum mishtake.
> > ----------------------------------------------------------------------
> > 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

Reply via email to