In terms of other languages, I don't know many that have implicit
arguments. It seems like K can accept more than a left and right
argument.
The closest analogy I came up with is javascript:
(function(f1,f2) { return (function(g1) { return [g1,arguments[1]]
})(f1,f2) }) (1,2)
[1, 2]
This uses the implicit arguments array
More explicitly:
var g = function(g1) { return [g1,arguments[1]] }
var f = function(f1,f2) { return g(f1,f2) }
f(1,2)
[1, 2]
You can skip passing any arguments if you return an anonymous function
var f = function(f1,f2) { return function(g1) { return [g1,arguments[1]] }; }
f()(1,2)
[1,2]
or no arguments at all
var f = function() { return function(g1) { return [g1,arguments[1]] }; }
f()(1,2)
[1,2]
This feels like a "lambda over let over lambda" and is still somewhat
mysterious to me. The anonymous function must be enclosing over f's
arguments
http://letoverlambda.com/textmode.cl/guest/chap2.html
For non-javascripters, this can be tinkered with in your browser's
developer console or jsfiddle or http://jsconsole.com/ or any other
similar service
On Fri, Mar 21, 2014 at 11:37 AM, Pascal Jasmin <[email protected]> wrote:
> 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm