Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

>So I had the idea to explore the lambda-calculus using s-expressions and patiently rebuilt booleans, pairs, lists, recursion and beyond a real complete Turing language, for instance:

Syntax is not semantics.

The only thing that s-expressions do that is mathematically interesting is make the abstract syntax tree of expressions explicit in a way that standard notation does not. The whole point of them is that they make string rewriting into tree rewriting which is vastly easier and makes writing your own DSLs a breeze.

From a practical point of view they are also the simplest way to serialize any expression which is why I can type them out in a text only comment as they are. Meanwhile doing the same with a math (or lambda calculus) expression requires a type setting system like latex to be understandable.

Lisp has decided that application is nameless in its syntax which means that things like ((lambda (x) (+ x 1)) 2) work when semantically they mean (apply (lambda (x) (+ x 1)) 2). This makes programming with multivariable functions very clean but partial application incredibly messy, e.g. ((((lambda (x) (lambda (y) (lambda (z) (+ x y z)))) 1) 2) 3). This is not something that can be fixed because the ABS of partial application when thought of as a tree is indeed very messy. The only reason why it works in languages like Haskell as well as it does is that as long as you only have single variable function - goodbye thunks and multivariable functions - you can treat the partial application trees as a list instead.

You can of course do the same in lisp using a DSL:

    '(partial
      ((lambda (x)) (lambda (y)) (lambda (z)) (lambda (w) (+ x y z w)))
      (1 2 3 4))
But it doesn't fit very well with the rest of the language and feel quite pointless.


@thrown: This makes programming with multivariable functions very clean but partial application incredibly messy

In lambdatalk the implementation of lambdas does not make them closures (no free variables) but is such that they accept de facto partial application and a number of values higher than the number of arguments. This compensates for the lack of closure. So for instance:

((lambda (x)) (lambda (y)) (lambda (z)) (lambda (w) (+ x y z w))) (1 2 3 4))

is written this way

{{{{{lambda {x y z w} {+ x y z w}} 1} 2} 3} 4} -> 10

and obviously

{{lambda {x y z w} {+ x y z w}} 1 2 3 4} -> 10




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: