Back to News
Advertisement
Advertisement

⚑ Community Insights

Discussion Sentiment

100% Positive

Analyzed from 517 words in the discussion.

Trending Topics

#language#function#lambda#calculus#bits#eval#env#https#more#programming

Discussion (8 Comments)Read Original on HackerNews

trompβ€’about 1 hour ago
> Alonzo Church developed the lambda calculus in 1929.

His first publication that showed the elements of the lambda calculus was the 1932 paper "A set of postulates for the foundation of logic", as I included in my recent paper [1]. It's quite possible he worked on it earlier than that, but I don't know of any credible evidence on that (would be very interested to hear it).

> Wait! How the heck is this a "programming" language? > At first glance, this simple language seems to lack both recursion and iteration, not to mention numbers, booleans, conditionals, data structures and all the rest. How can this language possibly be general-purpose?

What most stops lambda calculus from being a programming language is that it doesn't directly support I/O. However, one can adopt some very simple conventions for representing bits, lists of bits (bytes), and lists of bytes, and for letting a lambda term operate on these [2] which make the so-called Binary Lambda Calculus (BLC) a programming language.

And a very expressive language it is too: a BLC self interpreter [4] can be as small as the 170-bits

    01000110100001000
    00001100000010111
    00110000111111100
    00101110011111110
    00000111100000010
    11101110011011110
    01111111100001111
    11110000101111010
    01110100101111101
    00101101010011010

 which encodes the term

    (λ11)(λ(λλλ1(λλ2(1(λ6(λ2(6(λλ3(λλ23(14))))(7(λ7(λ31(21)))))))(41(111))))(11))
in De Bruijn notatation, with lambda diagram [3]

    ┬─┬ ────────────────────────────────────────────┬─┬
    └── ──────┬───────────────┬──────────────────── β”œβ”€β”˜
      β”‚ ──────┼───┬───────────┼─┬─────────┬──────── β”‚
      β”‚ ┬─────┼───┼───────────┼─┼─────────┼──────── β”‚
      β”‚ β”‚ ┬───┼───┼───────────┼─┼─────────┼──────── β”‚
      β”‚ β”‚ ┼─┬─┼───┼───────────┼─┼─────────┼─┬─┬─┬─┬ β”‚
      β”‚ β”‚ β”‚ β”‚ ┼─┬─┼───────────┼─┼──────── └── └── β”‚ β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ ┼─┼─┬─────────┼─┼─┬──────   β”‚   β”œβ”€β”˜ β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ ┼───────┬ β”‚ ┼─┼───┬──   β”œβ”€β”€β”€β”˜   β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ ┼───┬───┼ β”‚ β”‚ ┼─┬─┼─┬   β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ ┬─┼───┼ β”‚ β”‚ └── β”œβ”€β”˜   β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ ┼─┼─┬─┼ β”‚ β”‚   β”œβ”€β”˜     β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ └── β”œβ”€β”˜ β”‚ β”œβ”€β”€β”€β”˜       β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚   β”œβ”€β”˜   β”œβ”€β”˜           β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€β”€β”˜     β”‚             β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”œβ”€β”˜         β”‚             β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚ └──           β”‚             β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”‚   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚       β”‚
      β”‚ β”‚ β”‚ β”‚ β”œβ”€β”€β”€β”˜                         β”‚       β”‚
      β”‚ β”‚ β”‚ β”œβ”€β”˜                             β”‚       β”‚
      β”‚ β”‚ └──                               β”‚       β”‚
      β”‚ β”‚   β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚
      β”‚ └────                                       β”‚
      β”‚     β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
      β””β”€β”€β”€β”€β”€β”˜
quite a bit smaller than the 7 lines of RSR5 Scheme

    (define (eval e env) (cond
      ((symbol? e)       (cadr (assq e env)))
      ((eq? (car e) 'Ξ»)  (cons e env))
      (else              (apply (eval (car e) env) (eval (cadr e) env)))))
    (define (apply f x)
      (eval (cddr (car f)) (cons (list (cadr (car f)) x) (cdr f))))
    (display (eval (read) '())) (newline)
One of the neatest tricks in the interpreter is how it represents the environment as a list built with

      cons' =  \x\y\zx\zy. zx x (zy y)
which allows a list of bits like "1110" (the code for de Bruijn index 3) to index the environment by simply applying it to the environment.

[1] https://www.mdpi.com/1099-4300/28/5/494 "The Largest Number Representable in 64 Bits"

[2] https://gist.github.com/tromp/86b3184f852f65bfb814e3ab0987d8...

[3] https://tromp.github.io/cl/diagrams.html

[4] https://github.com/tromp/AIT/blob/master/ait/int.lam

catwellβ€’about 1 hour ago
This has been my Twitter / X banner for at least 10 years :)

https://x.com/pchapuis/header_photo

voidUpdateβ€’about 1 hour ago
> "If you've programmed in JavaScript, this form is equivalent to: function (v) { return e ; } "

function (v) { return e ; } -> Uncaught SyntaxError: Function statements require a function name

function a (v) { return e ; } a() -> Uncaught ReferenceError: e is not defined

Am I missing something?

emigreβ€’about 1 hour ago
It's meant as an example. The function receives something, which we call v, and returns something else, which we call e. It's not meant to be taken literally as the variable names - otherwise, you are right, e is undefined in that example.

He is just showing how the syntax of a Scheme function corresponds to the structure of a JavaScript function.

ramon156β€’about 1 hour ago
Its just an example. It doesn't matter what the function name is. And it doesn't matter where e comes from. No need to include it
RandomTeaPartyβ€’about 2 hours ago
"Implement lambda calculus in languages that are pretty much lambda calculus"

How large would implementation be in more usual languages?

utopiahβ€’about 2 hours ago
IMHO this and building an ALU with LEDs and logic gates should be part of ... well honestly any curriculum, even if you don't want to be study CS. Only doing that once in your life is enough to understand you could do it.

It was a "nerd" exploration few decades ago but nowadays so many of the things we do, from buying croissant to voting, is based on hardware and software. People should have a sense that yes it's complex but it's also NOT magic.

bjoliβ€’about 2 hours ago
I think it is a lovely experience just because it forces you to think about which abstractions are the correct ones. I think many people have had the feeling that they would love to change one (or many) aspects of a programming language.

I have been playing with an s-expr based language that compiles to f sharp, and it has made me realize how much I think Rich Hickey made some very lovely choices for clojure. I have never written clojure more than just for fun, but the more in think about my own toy language, the more highly I think of Rich Hickey. Many times because of the choices he made, but even more because of how he compromised to be able to interop with java.