Skip to content

Instantly share code, notes, and snippets.

(let* ((....))
;;; receive : channel0 -> pair term channel1
;;; send : channel0 -> term -> channel1
(lambda (receive send channel)
(let ((loop (Y (lambda (loop channel0))
(let* ((result (receive channel0))
(sexp (first result))
(channel1 (second result))
(term (extract sexp))
(normal (reduce normal-order term))
@b0oh
b0oh / syntax-try0.sml
Last active September 21, 2018 12:11
term/fold var abs app term =
cond
var? term ->
var (var/get-id term)
abs? term ->
abs (abs/get-id term) (abs/get-body term)
app? term ->
app (app/get-abs term) (app/get-arg term)
@b0oh
b0oh / example.scm
Last active December 4, 2018 13:53
(let* ((inc (lambda (num succ zero) (succ (num succ zero))))
(+ (lambda (num1 num2 succ zero) (num1 succ (num2 succ zero))))
(* (lambda (num1 num2 succ zero) (num1 (num2 succ) zero)))
(0 (lambda (succ zero) zero))
(1 (inc 0))
(2 (+ 1 1))
(4 (* 2 2)))
(* 4 4))
@b0oh
b0oh / 010-inc.scm
Last active December 6, 2018 10:11
Parsing simple scm from stdin
(((lambda (zero inc) (inc (inc zero)))
(lambda (next zero) zero))
(lambda (num next zero) (next (num next zero))))
module.exports = {
identity: x => x
}
@b0oh
b0oh / funny.elm
Created April 12, 2019 13:18
funny.elm
zayoba : Decode.Value -> String
zayoba value =
let
decoder = Decode.map (Encode.encode 0) Decode.value
in
case Decode.decodeValue decoder value of
Ok result ->
result
_ ->
((@fun (zero)
((@fun (inc)
(inc zero))
(@fun (nat next init)
(next
(nat next init)))))
(@fun (_next init)
init))
module Pair exposing (..)
type alias Pair1 first second pair =
((first -> second -> pair) -> pair)
type Pair2 first second pair =
Pair2 ((first -> second -> pair) -> pair)
((lambda (zero)
((lambda (inc)
(inc zero))
(lambda (nat next init)
(next
(nat next init)))))
(lambda (next init)
init))
@b0oh
b0oh / abs.py
Last active November 29, 2021 02:02
Small lambda calculus calculator without alpha conversion
def var(name):
return (0, name)
def abs(name, body):
return (1, (name, body))
def app(callee, argument):
return (2, (callee, argument))