I am reading DrRacket document http://docs.racket-lang.org/guide/binding.html
There is a function
(define f
(lambda (append)
(define cons (append "ugly" "confusing"))
(let ([append 'this-was])
(list append cons))))
> (f list)
'(this-was ("ugly" "confusing"))
I see that we define function f, inside we define lambda that takes (append), why ?
Procedure (body) for lambda is another function called cons, that appends two strings.
I don’t understand this function at all.
Thanks !
Scheme takes some getting used to 🙂
fis assigned the function returned by thelambda.lambdadefines the function that takes a parameter (calledappend).(define cons (append "ugly" "confusing"))is not a function per se, but calls append with the two strings as parameter and assigns the result to cons.letblock, append is re-assigned a different value, the symbolthis-was.append(which now contains'this-was) andcons(which contains'("ugly" "confusing")from 3 aboveffis called with the parameterlist(thelistfunction). which gets passed as the parameter append. And this is why 3 above creates a list'("ugly" "confusing")which gets assigned tocons.Hope that cleared up things a bit.
Cheers!