one of the comments at your link is
> Update: even access to enclosing function's local vars is not always correct:

J cannot access local vars from outside a function, and local vars only exist 
in functions.  module level (locale) vars exist within that scope.

J's function parameters are fixed based on left and right params.  All j 
functions are like operators (+) in other languages.

J can make anonymous functions implicitly through tacit code:

mean =: +/%#
  (+/%#) 1 2 3
2
  cat =: ,
  1 cat 2
1 2
explicit (code) functions can also be anonymous, which might seem contradictory 
but J's use of term explicit is in naming the  possible arguments (x y u v) to 
a function.  explicit mean might look like:

3 : '(+/ y) % # y' NB.(just y arg)

when we want more arguments, we unpack them inside the function:

'arg1 arg2 arg3' =. 1;2;3  NB. or 1 2 3

will pass each parameter to each arg (arg2 =2 above)

your example seems a bit too easy for J, though you seem to be implying that K 
has a language feature where parameters are ignored and passed to 
sub-functions, which seems weird and un necessary.

but:

catf =: 4 : 'x , y'

will pass x and y (left and right) to anonymous cat (,)

if your question is how to deal with nulls:  2, null
 $  2 , i.0
1
is a list with 1 element  (as opposed to a scalar)



----- Original Message -----
From: Tom Szczesny <[email protected]>
To: [email protected]
Cc: 
Sent: Friday, March 21, 2014 10:47:59 AM
Subject: [Jprogramming] Lambdas

My question concerns lambdas, implict parameters, and scoping.
(I'm not sure what lambdas are called in J.  In some languages, like K,
they are called subfunctions.)

We are working on issue in Kona, see
https://github.com/kevinlawler/kona/issues/220
and I need to check how other languages (like J or Scheme) handle the issue.

Suppose lambdas are supported and implicit parameters for functions are
supported.
An example in K would be {{[a]a,x}}[1][2]
Let's call the parent function f, and the child function g.

f has 2 parameters: [1] and [2]
f has no arguments at the parent level to bind to any parameters.

g has 2 arguments: one explicit [a], and one implicit [x], but no
parameters at the subfunction level
g simply catenates the arguments a and x.

K3.2 (and K2.8) yields 2 1 as a result.
Kona yields (2;) as a result (a heterogeneous list of 2 elements: 2 and
null)
There are arguments for both approaches (which are outlined in the issue
discussion thread).

Question: Can a similar case occur in J, and what does J yield as a result?
----------------------------------------------------------------------
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