I like your example, but though its very cool, I see why you think its useless 
for J.  Your goals seem to have been to make a pretty calling convention rather 
than leverage J's existing multi-assign facilities which is what my approach 
does, with the convention that a passed null parameter is to be replaced with 
defaults.

To make your example parameterized function using my approach:

   3 : ('": each filename;max;color' Par 'filename max color'; 
'c:\short.log';42;'red') 
3 : 0 
'filename max color'=. y defaults fixlenx 'c:\short.log';42;'red' 
": each filename;max;color 
)

and called as:

   3 : ('": each filename;max;color' Par 'filename max color'; 
'c:\short.log';42;'red') a:,73; 128 244 111 
┌────────────┬──┬───────────┐ 
│c:\short.log│73│128 244 111│ 
└────────────┴──┴───────────┘ 
or
   3 : ('": each filename;max;color' Par 'filename max color'; 
'c:\short.log';42;'red') 'none.log';22 
┌────────┬──┬───┐ 
│none.log│22│red│ 
└────────┴──┴───┘ 

Anyways, I came up with another J implementation of something else in your file 
that has been a topic on the forums: Lexical closures.

I've seen your comments that this is generally useless, and without arguing 
that, I can at least claim that this is the most useful possible J 
implementation.  A conjunction that creates a bonded verb

lex =:  2 : 0 
a =. n~ :: ] y 
(n) =: u(a&) 
a 
)
details here:
http://www.jsoftware.com/jwiki/PascalJasmin/nonads%20revisited

----- Original Message -----
From: Dan Bron <[email protected]>
To: [email protected]
Cc: 
Sent: Wednesday, June 11, 2014 11:32:07 PM
Subject: Re: [Jprogramming] copula -- function parameters for J

Pascal wrote:
> I wrote something else cool instead:
>
> Parsing function parameters outside of the function:
> last section at:  
> http://www.jsoftware.com/jwiki/PascalJasmin/J%20tricks%20with%20assign

I haven't read that whole page yet, but if you're interested in silly
tricks with assign, maybe you'd like this (and the pages it links to):

  http://rosettacode.org/wiki/Named_parameters#J

Basically, it lets you declare formal parameters for J verbs, conceptually
like the "function foo(string name, int age)" of other languages, and then
refer to these parameters, reliably and transparently, inside your verb
(e.g. 'if. age > 10 do. 'Hello Mr.' , name else. 'Hey ',name',' is your
dad around?' end.) . Auxillary names are defined to let you know whether a
user specified a given parameter, or it took its default value. All names
are completely, authentically local, and so evaporate when the verb exits.
An additional script, added later, emulates the calling conventions of
other languages (e.g.  foo['Bobby',10] or foo[name='Bobby',age=10] etc).

And though these things exist and were fun to write, I don't see any
serious use for them in J. Our language has its own conventions, offered
in pursuit of its own objectives, which are more often than not at odds
with the conventions of most mainstream languages.  For example, it would
be hard to marry rank and named parameters in any cohesive and useful way;
since rank is utterly central to J programming, we probably won't see much
use of named parameters. 




-Dan


----------------------------------------------------------------------
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