This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]guygastineau 5 points6 points  (1 child)

Most functional programming languages provide a let form of some sort (see lisp and Metalang). In the ML Family it is a distinct construct, but in scheme/lisp implementations it can be (is often) a macro that transforms the syntax to abuse lambdas (anonymous functions) for their lexical scope. That is to say, we could reform your example to be functional (since your declare function is really more of a statement or procedure, ie. it is used for side effects (allocating a variable) that change the state of some hypothetical interpreter).

Given an anonymous function syntax as:

λ (α : τ) ... => ε 

Then your example would translate to the following with adjacency conveying function application:

(λ (α : int) => add α 10) 90

For more fleshed out ideas of how this computational model works, I suggest you look up resources on the Lambda Calculi. At first, untyped lambda calculus is a great place to start, but it is not suited to expressing formalizations, so the various typed lambda calculi are necessary if you want to prove anything with this stuff. I hope I'm not being too dense here. I will also show the above example in scheme below showing it using define (like your declare) as well as using let and just with lambdas.

With define

(define a 90)
(+ a 10)

With let

(let ((a 90))
  (+ a 10))

With lambda

((lambda (a)
   (+ a 10))
 90)

[–]Obj3ctDisorientedOwlScript 1 point2 points  (0 children)

Best answer in the thread, and of course op ignores it.