So what you are really after is nesting?

First, I have to ask: why?

You can do nesting in J, but it's generally a bad idea.

J is already incredibly terse, and it's a good idea to give things
meaningful names (and to provide well-written documentation for them -
something which most programming communities have sadly gotten out of
the habit of doing).

A related issue, though, is that everything is a specialist activity,
and most all work of all sorts is temporary. People need to eat, and
somehow accommodate each other, but after that? Most of what most of
us produce winds up being consumed and/or discarded sooner or later,
and the only way to get beyond that is ongoing effort.

Which leads back to: the primary advantage J confers on people (at
least in a professional sense) is a perspective which is:

(a) different from that of other languages,
(b) closer to the underlying hardware, and
(c) closer to the aspects of mathematics which have proven their use
through history.

(It also provides a relatively short feedback loop for experimental
coding, which drives some adoption, but *that* particular feature is
not unique to the language and has been widely adopted in a wide
variety of contexts.)

So.. how to do nesting in J?

You can use something other than a lone ) to terminate blocks, with a
few other constraints and a pre-processor (perhaps a recursive
pre-processor). I've done this and become quickly dissatisfied with
the result, because this also needs multi-line sentences, and also
because there are no readers of J multi-line sentences with nested
blocks. Most code never gets read by very many people, anyways. (How
much time have you spent reading, for example, the source code to
tomcat? hive? avro? And those are what pass for *popular* nowadays.
But they are so verbose and clumsy that most people just aren't
interested in reading them. Then again, it takes quite a bit of
patience to get anything useful done, and apparently most people would
rather spend their time with their family or getting drunk or
traveling or pleasing their employer, or whatever. There's no
accounting for taste...)

Anyways, you can also use native features if you want a relatively
simple form of nesting. If you only want one nested block at each
level you can use a chain of adverbs terminated by a verb.

defn=: (3 :0) (1 :0) (1 :0) (1 :0)
  NB. outer definition
  NB. u refers to nested verb
  ...
)
    NB. first nested block
    NB. u refers to nested verb
    ...
)
      NB. next nested block
      NB. u refers to final nested verb
      ...
)
        NB. final nested block
        NB. no reference nesting
        ...
)

Thanks,

-- 
Raul


On Mon, Feb 2, 2015 at 7:21 AM, alexgian <[email protected]> wrote:
> Hm, would that nest?
>
> Could you do
> (lambda (x)
>   (lambda(y)
>      (+ x y)))
>
> or if Scheme doesn't please you:
> /x -> /y -> x+y
>
> ?
>
>
>
> On 2 February 2015 at 10:11, Jan-Pieter Jacobs <[email protected]>
> wrote:
>
>> Well, if I'd be using it a lot, I'd write a not-so-beautiful thing
>> (which probably other people are going to phrase more eloquently) to make
>> the other code look better.
>> For instance:
>>
>> NB. lambda-ifying adverb:
>> L =: 1 : '3 : (( [: (( ''=.y'' ,~ ''''''''&([,,~) )&.>@{. , {:) < ;.  _1 )
>> m)'
>>
>> Usage:
>>
>>    times =: '|a b|a*b' L
>>    plus  =: '$x y$x+y' L NB. any separator you fancy (but space)
>>    plus 1 2
>> 3
>>    times 3 4
>> 12
>>
>>
>>
>> 2015-02-02 10:39 GMT+01:00 alexgian <[email protected]>:
>>
>> > > On a related note, lambda syntax is not really simple.
>> > > Consider:
>> > > ((lambda (x y) (+ x y)) 2 3)
>> >
>> > Well, that's *one* form of lambda syntax, viz. the Scheme variant
>> >
>> > In Haskell you'd write
>> > \x y -> x+y
>> >
>> > Hardly rocket science.  But I think the point is that that however
>> > awkwardly you may choose to codify it, lambda is brilliant in its
>> > simplicity and accessibility of understanding.  Static scoping is a
>> > no-brainer for managing complexity.
>> >
>> > I agree that the inability of abstracting J more than two levels (as
>> > already mentioned) is a serious PITA, and probably the most inexplicably
>> > klutzy piece of work in an otherwise so elegant system... I mean, needing
>> > to combine tacits inside explicits, and gawdknows what other
>> work-arounds!
>> > Really?  We might have got used to it, but I doubt that many in the real
>> > world would.  But, of course, I could be wrong....
>> > ----------------------------------------------------------------------
>> > 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

Reply via email to