That's one of my favorite J idioms!

A similarly elegant phrase arising from the use of -. is (, '/' -.~ {:) 
'/some/path' . This ensures all paths end in a slash, without duplicating 
slashes in paths that are already in canonical form. To appreciate its 
elegance, write an analogous function on another language of your choice, then 
compare it to the J: did you notice that the J only has a single reference 
(direct or indirect) to the constant '/'? How many were used in the othe 
language? (Now, try transliterating the two algorithms to English. Fun game.)

Brian McGuiness showed this pattern to me in 2010 and it blew me away (and I'd 
been studying J for decade at the time; it's an endless thrill) [1].

-Dan

[1] J as a declarative language:
    http://www.jsoftware.com/pipermail/programming/2010-January/017673.html





N
consider that there is only a single reference to the constant '/' (direct or 
indirect), and then try and  how you would express function in another language 
w

Please excuse typos; composed on a handheld device.

On Sep 8, 2013, at 11:16 PM, Joey K Tuttle <[email protected]> wrote:

> Another (related, and also using -. (twice!)) expression that I use a lot for 
> getting just the digits from a string -
> 
>   digits=: -.&(a.-.'0123456789')
> 
>   digits ": 23 45 6
> 23456
> 
> 
> On 2013/09/08 19:54 , Alex Giannakopoulos wrote:
>> That 'less' verb is very useful, I'd never had occasion to use it until now!
>> It could have been a bit more hyped up in the documentation, though, I'd
>> never even seen it used before! (blush)
>> 
>> 
>> 
>> On 9 September 2013 03:46, Alex Giannakopoulos<[email protected]>wrote:
>> 
>>> >Ah, OK, now I got it!
>>> >
>>> >(": 23 45 6) -. ' '
>>> >
>>> >23456
>>> >
> ----------------------------------------------------------------------
> 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