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

Reply via email to