Drop backslash from lambda definitions

This commit is contained in:
2025-04-15 10:34:38 -05:00
parent 5024a2be4c
commit f2beb86d8a
16 changed files with 181 additions and 182 deletions

View File

@ -11,11 +11,11 @@ demo_true = t t
not_TC? = t (t (t t) (t t t)) (t t (t t t))
-- /demos/toSource.tri contains an explanation of `triage`
demo_triage = \a b c : t (t a b) c
demo_matchBool = (\ot of : demo_triage
demo_triage = a b c : t (t a b) c
demo_matchBool = (ot of : demo_triage
of
(\_ : ot)
(\_ _ : ot)
(_ : ot)
(_ _ : ot)
)
-- Lambda representation of the Boolean `not` function
not_Lambda? = demo_matchBool demo_false demo_true

View File

@ -18,47 +18,47 @@ main = exampleTwo
-- / / \
-- 4 5 6
label = \node : head node
label = node : head node
left = (\node : if (emptyList? node)
[]
(if (emptyList? (tail node))
[]
left = (node : if (emptyList? node)
[]
(if (emptyList? (tail node))
[]
(head (tail node))))
right = (\node : if (emptyList? node)
[]
(if (emptyList? (tail node))
[]
(if (emptyList? (tail (tail node)))
[]
right = (node : if (emptyList? node)
[]
(if (emptyList? (tail node))
[]
(if (emptyList? (tail (tail node)))
[]
(head (tail (tail node))))))
processLevel = y (\self queue : if (emptyList? queue)
[]
(pair (map label queue) (self (filter
(\node : not? (emptyList? node))
processLevel = y (self queue : if (emptyList? queue)
[]
(pair (map label queue) (self (filter
(node : not? (emptyList? node))
(append (map left queue) (map right queue))))))
levelOrderTraversal_ = \a : processLevel (t a t)
levelOrderTraversal_ = a : processLevel (t a t)
toLineString = y (\self levels : if (emptyList? levels)
""
(append
(append (map (\x : append x " ") (head levels)) "")
toLineString = y (self levels : if (emptyList? levels)
""
(append
(append (map (x : append x " ") (head levels)) "")
(if (emptyList? (tail levels)) "" (append (t (t 10 t) t) (self (tail levels))))))
levelOrderToString = \s : toLineString (levelOrderTraversal_ s)
levelOrderToString = s : toLineString (levelOrderTraversal_ s)
flatten = foldl (\acc x : append acc x) ""
flatten = foldl (acc x : append acc x) ""
levelOrderTraversal = \s : append (t 10 t) (flatten (levelOrderToString s))
levelOrderTraversal = s : append (t 10 t) (flatten (levelOrderToString s))
exampleOne = levelOrderTraversal [("1")
[("2") [("4") t t] t]
exampleOne = levelOrderTraversal [("1")
[("2") [("4") t t] t]
[("3") [("5") t t] [("6") t t]]]
exampleTwo = levelOrderTraversal [("1")
[("2") [("4") [("8") t t] [("9") t t]]
[("6") [("10") t t] [("12") t t]]]
exampleTwo = levelOrderTraversal [("1")
[("2") [("4") [("8") t t] [("9") t t]]
[("6") [("10") t t] [("12") t t]]]
[("3") [("5") [("11") t t] t] [("7") t t]]]

View File

@ -3,11 +3,11 @@
main = size size
size = (\x :
(y (\self x :
size = (x :
(y (self x :
compose succ
(triage
(\x : x)
(x : x)
self
(\x y : compose (self x) (self y))
(x y : compose (self x) (self y))
x)) x 0))

View File

@ -18,7 +18,7 @@ main = toSource not?
sourceLeaf = t (head "t")
-- Stem case
sourceStem = (\convert : (\a rest :
sourceStem = (convert : (a rest :
t (head "(") -- Start with a left parenthesis "(".
(t (head "t") -- Add a "t"
(t (head " ") -- Add a space.
@ -26,7 +26,7 @@ sourceStem = (\convert : (\a rest :
(t (head ")") rest)))))) -- Close with ")" and append the rest.
-- Fork case
sourceFork = (\convert : (\a b rest :
sourceFork = (convert : (a b rest :
t (head "(") -- Start with a left parenthesis "(".
(t (head "t") -- Add a "t"
(t (head " ") -- Add a space.
@ -36,7 +36,7 @@ sourceFork = (\convert : (\a b rest :
(t (head ")") rest)))))))) -- Close with ")" and append the rest.
-- Wrapper around triage
toSource_ = y (\self arg :
toSource_ = y (self arg :
triage
sourceLeaf -- `triage` "a" case, Leaf
(sourceStem self) -- `triage` "b" case, Stem
@ -44,7 +44,7 @@ toSource_ = y (\self arg :
arg) -- The term to be inspected
-- toSource takes a single TC term and returns a String
toSource = \v : toSource_ v ""
toSource = v : toSource_ v ""
exampleOne = toSource true -- OUT: "(t t)"
exampleTwo = toSource not? -- OUT: "(t (t (t t) (t t t)) (t t (t t t)))"