Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anonymous lambdas directly referring to themselves

Tags:

scheme

racket

Does Scheme or do any dialects of scheme have a kind of "self" operator so that anonymous lambdas can recur on themselves without doing something like a Y-combinator or being named in a letrec etc.

Something like:

(lambda (n)
   (cond
     ((= n 0) 1)
     (else (* n (self (- n 1)))))))
like image 543
Harry Spier Avatar asked Oct 28 '11 23:10

Harry Spier


People also ask

Can lambda be called directly?

You can invoke Lambda functions directly using the Lambda console, a function URL HTTP(S) endpoint, the Lambda API, an AWS SDK, the AWS Command Line Interface (AWS CLI), and AWS toolkits.

Are lambdas and anonymous functions the same?

In Python, an anonymous function is a function that is defined without a name. While normal functions are defined using the def keyword in Python, anonymous functions are defined using the lambda keyword. Hence, anonymous functions are also called lambda functions.

Which command Cannot be called directly by an anonymous function?

An anonymous function cannot be a direct call to print because lambda requires an expression. Lambda functions have their own local namespace and cannot access variables other than those in their parameter list and those in the global namespace.

Are lambdas anonymous?

Lambda functions are intended as a shorthand for defining functions that can come in handy to write concise code without wasting multiple lines defining a function. They are also known as anonymous functions, since they do not have a name unless assigned one.


1 Answers

No. The trouble with the "current lambda" approach is that Scheme has many hidden lambdas. For example:

  • All the let forms (including let*, letrec, and named let)
  • do (which expands to a named let)
  • delay, lazy, receive, etc.

To require the programmer to know what the innermost lambda is would break encapsulation, in that you'd have to know where all the hidden lambdas are, and macro writers can no longer use lambdas as a way to create a new scope.

All-round lose, if you ask me.

like image 125
Chris Jester-Young Avatar answered Sep 27 '22 22:09

Chris Jester-Young