Programming Languages (CS302 2006S)

Why Are There Three Lambdas

Comments on:

Kelsey, R., Clinger, W., and Rees, J. (Eds). (1998). Revised5 Report on the Algorithmic Language Scheme. Section 7.2

In particular, responses to the question: Why are there forms of lambda in the abstract syntax, and three equations to define those forms in the semantic functions?

Comments from: Peter Brown, Michael Claveria, Davis Hart, Alex Leach, Brad Miller, Angeline Namai (*), Mark Nettling. Dimitar Tasev, Dave Ventresca.


It appears to me that there are three lambda definitions for one main reason, which is that they accept different parameters that are handled differently according to the definitions. The first seems to be the standard lambda we are used to that defines a procedure by accepting a series of parameters (identifiers) and running some commands on them that evaluate to an expression. I believe the second lambda is similiar but has the option to run a default setting if given no or improper parameters. The third lamda is a procedure that takes no parameters and always runs the default setting.

I could not exactly understand why there are three definitions of lambda, but the main difference in their definition seems to be is in the very declaration of lambda. The first case seems to include definition of functions that take functions as well as variables as parameters. The second case includes functions, evaluated values of functions, and variables as parameters. finally, the last case includes definitions of functions that take variables as parameters.

It is my understanding that the different lambda's correspond to the number and types of parameters to be used in the proceedure. In the first version, lambda needs a series of individual atoms, and the definition can then just progress more or less straight forward with the parameters being used as needed. With the second version, however, we look at what happens when a parameter is a list. In this case, we have to progress along the list in order and the lambda definition uses tievalsrest to look at the rest of the list. The third version simply provides instructions on how to evaluate a single identifier as the parameters for lambda, since we could use either of the first two in this case. The authors choose to use the second list-based definition, although to me it looks more inefficient, but I could be wrong.

My guess is that there are three different lambda functions to support the different parameters. The first lambda function defined takes I* or a sequence of variables. The second one takes (I* . I) which including the lambda means a function of a sequence of variables that are somehow affected by a single variable through a function (maybe?). The last one takes only one variable. In the first two definitions we take some lambda of continuations and environments and something is done with expressed values and checking the number of a bunch of expressed values and comparing it to the number of variables. For the first lambda since there are a number of variables in the sequence the number has to be equal to the number fo expressed values for the function to be called otherwise there is an argument number error. In the second one the there has to be more or as much expressed values as variables. I guess the last lambda function is necessary to signify that we are applying a bunch of commands to a single variable.

I think that the first lambda is defined for procedures with a fixed arity. The second and third lambda definitions include the dot notation, so I believe they are defined for procedures that have variable arity. The second lambda requires at least one argument before the period, and those arguments that precede the dot are bound to identifiers, while those that follow it are placed into a list. The third lambda is equivalent to a lambda in which there are no identifiers before the period, so my best guess is that it is defined for procedures that take zero or more parameters. For the third kind, we do not enclose the parameters in parentheses, so that whenever we call the function, everything that comes after the function-name is placed into a list.

The last two kinds of lambda are often useful when we would like to perform the same operation on all, or most of, the arguments of a procedure, but cannot anticipate or do not want to restrict the number of these arguments. For example, it would be inefficient to limit product to 5 arguments, since we would need to write new procedures to find the product of say 2, 3 or 10 numbers. The third lambda would therefore be convenient in such a case. The second lambda may be useful if we need to filter out numbers that are smaller than a given value from a sequence. In this case, assuming that all preconditions are met, we are certain that at least one argument, minimum, will be supplied during a function call, but we cannot foretell the size of the following sequence of numbers.

As far as I can tell, there are three definitions of lambda for 1) regular variable input, 2) variable arity input and 3) function input?. That is to be read tentatively since, although I read section 7.2 at least 12 times, I still don't understand the notation.

I am not sure what the third of the lambda expressions does, however I think the first takes in a set number of arguments(zero or more) as determined when a lambda expression is written, and the second lambda expression takes a variable number of arguments (zero or more) so that when a lambda expression is written it take in at least a certain number of arguments, as defined when the expression is written.


I was unable to really understand the use of the tievals function and hence could not figure out the various lambda definitions. It seemed to me that tievals ties names to values in some environment, but I couldn't figure the use of that in a lambda definition. It would _greatly_ help to go over one of the functions as I still don't get some of the syntax. Sorry to dissapoint.

This reading turned out to be much more difficult than I thought at first glance. After my poor attempt at analyzing the lambda definitions, I came up with a few questions. The definition of 'wrong' says that it is implementation specific, but you said in class that we would need to look up 'wrong' and understand it; does wrong have any other function beside to return errors? In the second definition of lambda I am having a great deal of difficulty understanding the sequence that begins "send(<new (o-thing) | L ... " given the definition of new(o-thing) on the previous page, actually I don't understand that particularly well either. Also, is it bad that, the more and more we read about scheme, I feel like there is more and more about it that I do not understand? One last question: what does in E mean? That is puzzling me, perhaps I'm just tired. See you tomorrow morning.

What is the difference between tievals and tievalsrest? Does Epsilon[(lambda I Gamma* E0)] get interpreted in the same fashion as Epsilon[(lambda (I* . I) Gamma* E0)]? More specifically, how is (. I) interpreted?

Disclaimer: I usually create these pages on the fly, which means that I rarely proofread them and they may contain bad grammar and incorrect details. It also means that I tend to update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This document was generated by Siteweaver on Wed May 10 09:03:23 2006.
The source to the document was last modified on Wed Feb 22 09:48:49 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS302/2006S/Readings/three-lambdas.html.

You may wish to validate this document's HTML ; Valid CSS! ; Check with Bobby

Samuel A. Rebelsky, rebelsky@grinnell.edu