What is a function parameter =[] for?

Marko Rauhamaa marko at pacujo.net
Wed Nov 25 11:44:42 EST 2015


Jussi Piitulainen <harvest at should.be.invalid>:

> Marko Rauhamaa writes:
>> As far as the words "variable" and "binding" go, they are present in
>> lambda calculus (1929 and on):
>
> So it's more than ten years earlier than I thought. Old enough,
> anyway. Strictly speaking, that a Wikipedia article uses the words
> "variable" and "binding" to discuss lambda calculi today is not a
> proof that Church used those words in his time. I'm inclined to
> believe he did. (Our CS department had a copy of Church's book. It
> smelled funny.)

I haven't even smelled the originals, but the formalization of variable
substitution was *the* big selling point for lambda calculus.
Previously, combinatory logic solved the age-old problem with variables
by eliminating them altogether:

   Combinatory logic is a notation to eliminate the need for quantified
   variables in mathematical logic.

   <URL: https://en.wikipedia.org/wiki/Combinatory_logic>

>> Now we would have this reduction:
>>
>>    f(7)
>>    =>
>>    7 += 1; return 2 * 7
>>
>> because "x" would be bound to "7" everywhere in the function body.
>
> You know, people have developed further ways to talk about these things
> precisely because substitution semantics is inadequate for what they
> wanted to talk about.

"Assignment" is what everybody uses and understands.

> Not substituted to the program text - who would even think that?

Actually, if Scheme didn't possess set! et al, we would be talking about
true binding. For example, the function

   (define (sum numbers)
     (let loop ((total 0) (remaining numbers))
       (if (null? remaining)
           total
           (loop (+ total (car remaining)) (cdr remaining)))))

can be described and effectively implemented using true, syntactic
binding. To execute such code, you start with an expression, say,
(sum '(1 2 3 4 5)) and keep on rewriting the expression until you can't
rewrite it anymore.

The availability of set! forces the implementation to generate a memory
slot for each binding, turning the binding semantics into an assignment
semantics.


Marko



More information about the Python-list mailing list