I looked at Devon's answer and had a response very similar to the
paper (before reading the paper).  It'd be like if I was riding a
horse and carriage in 1910 and an automobile raced by.  J has a
pleasant way of humbling in 10 characters or less.

It still took me about 15 minutes to figure it out, so I'll post here
for any other beginners more explicitly

BraceIdx =: '{}' i. '@{ foo; if (abc) { if (q) { m; } } }'
BraceAddSubtract =: BraceIdx { (1 _1 0)    NB. Add 1 for { and
subtract 1 for }, do nothing for other characters
]BraceRunSum =: +/\BraceAddSubtract



On Wed, Jan 15, 2014 at 11:22 AM, Roger Hui <[email protected]> wrote:
> An oldie but a goodie.  See the third paragraph of Perlis, APL is more
> French than English <http://www.jsoftware.com/papers/perlis78.htm>, 1978,
> talking about events in the 1960s.
>
>
>
> On Wed, Jan 15, 2014 at 8:01 AM, Devon McCormick <[email protected]> wrote:
>
>> This (old) trick works nicely if you can fit complete expressions into
>> memory:
>>
>>    +/\(1 _1 0){~'{}' i. '@{ foo; if (abc) { if (q) { m; } } }'
>> 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 2 2 1 1 0
>>
>> It becomes clunkier if you have to process expressions in sequential chunks
>> but can be made to work.
>>
> ----------------------------------------------------------------------
> 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