[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SRFI 31 procedure vs. named-lambda



Hi Al!

Al Petrofsky writes:
> Your procedure proposal appears to be the same as the r2rs
> named-lambda special form, except you moved the name into the
> paramter list.  

Thanks for your hint at `named-lambda', which I wasn't aware of.
While I couldn't obtain a copy of R2RS yet, I found that MIT Scheme
(7.7.0) does offer a variant of `named-lambda'.  This form has the
same syntax (except for the name) that I proposed. Citing the MIT
Scheme manual:

 - special form: named-lambda formals expression expression ...
     The `named-lambda' special form is similar to `lambda', except
     that the first "required parameter" in FORMALS is not a parameter
     but the "name" of the resulting procedure; thus FORMALS must have
     at least one required parameter.  This name has no semantic
     meaning, but is included in the external representation of the
     procedure, making it useful for debugging.

Curiously, the purpose of `named-lambda' is solely in debugging here,
with "no semantic meaning".  Indeed, we have

1 ]=> (define g (named-lambda (f n) (if (zero? n) 1 (* n (f (- n 1))))))
;Value: g
1 ]=> g
;Value: #[compound-procedure 2 f]
1 ]=> (g 3)
; Unbound variable: f
...

I wonder whether this is a bug. 

> If you want to revive named-lambda, I suggest you use the old name
> and syntax, or else provide justification for the change.  

We should find out about the precise semantics of R2RS `named-lambda'
first.  If the same as in MIT Scheme, I would prefer `procedure'
instead of `named-lambda'. Anyway, the name `lambda' wasn't the best
choice in the first place, was it?  And writing the procedure tag
inside the formals list would be the same syntax as in
procedural-`define' and in procedure call in Scheme.

> I also suggest you research why named-lambda was dropped from the
> reports (I don't really know), and let us know why you think those
> reasons should not deter you from this srfi.

My preliminary answer here is that `procedure' should be there for
esthetical and systematical reasons.

It is a proper extension of `lambda' and fits neatly into the chain

`lambda' < `procedure' < procedural-`define'. 

It allows reducing `lambda' and named-`let' to `procedure'. 

It allows reducing procedural-`define' to `procedure' and `define',
thus helping to separate state-preserving and state-changing concerns.

Mirko.