Some special characters in ids; new demos
All checks were successful
Test and Build / test (push) Successful in 4m39s
Test and Build / build (push) Successful in 1m44s

Adds support for several special characters in identifiers. Adds a demo
for converting values to source code and another for checking equality.
Updates the existing demo and tests to reflect new names for functions
returning booleans.
This commit is contained in:
James Eversole
2025-01-23 15:46:40 -06:00
parent 419d66b4d1
commit 03e2f6b93e
7 changed files with 159 additions and 86 deletions

24
demos/equality.tri Normal file
View File

@ -0,0 +1,24 @@
false = t
true = t t
triage = (\a b c : t (t a b) c)
matchBool = (\ot of : triage
of
(\_ : ot)
(\_ _ : ot)
)
not_TC? = t (t (t t) (t t t)) (t t (t t t))
not_Lambda? = matchBool false true
areEqual? = equal not_TC not_Lambda
true_TC? = not_TC false
false_TC? = not_TC true
true_Lambda? = not_Lambda false
false_Lambda? = not_Lambda true
areTrueEqual? = equal true_TC true_Lambda
areFalseEqual? = equal false_TC false_Lambda

View File

@ -17,20 +17,15 @@
-- 4 5 6
--
isLeaf = (\node :
lOr
(emptyList node)
(emptyList (tail node)))
label = (\node : head node)
getLabel = (\node : head node)
getLeft = (\node : if (emptyList node)
left = (\node : if (emptyList node)
[]
(if (emptyList (tail node))
[]
(head (tail node))))
getRight = (\node : if (emptyList node)
right = (\node : if (emptyList node)
[]
(if (emptyList (tail node))
[]
@ -40,11 +35,11 @@ getRight = (\node : if (emptyList node)
processLevel = y (\self queue : if (emptyList queue)
[]
(pair (map getLabel queue) (self (filter
(pair (map label queue) (self (filter
(\node : not (emptyList node))
(lconcat (map getLeft queue) (map getRight queue))))))
(lconcat (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)
""
@ -52,17 +47,19 @@ toLineString = y (\self levels : if (emptyList levels)
(lconcat (map (\x : lconcat x " ") (head levels)) "")
(if (emptyList (tail levels)) "" (lconcat (t (t 10 t) t) (self (tail levels))))))
levelOrderToString = (\s : toLineString (levelOrderTraversal s))
levelOrderToString = (\s : toLineString (levelOrderTraversal_ s))
flatten = foldl (\acc x : lconcat acc x) ""
flatLOT = (\s : lconcat (t 10 t) (flatten (levelOrderToString s)))
exampleOne = flatLOT [("1")
[("2") [("4") t t] t]
[("3") [("5") t t] [("6") t t]]]
levelOrderTraversal = (\s : lconcat (t 10 t) (flatten (levelOrderToString s)))
exampleTwo = flatLOT [("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]]]
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]]]
[("3") [("5") [("11") t t] t] [("7") t t]]]
exampleTwo

46
demos/toSource.tri Normal file
View File

@ -0,0 +1,46 @@
-- Thanks to intensionality, we can inspect the structure of a given value
-- even if it's a function. This includes lambdas which are eliminated to
-- Tree Calculus (TC) terms during evaluation.
-- Triage takes four arguments: the first three represent behaviors for each
-- structural case in Tree Calculus (Leaf, Stem, and Fork).
-- The fourth argument is the value whose structure is inspected. By evaluating
-- the Tree Calculus term, `triage` enables branching logic based on the term's
-- shape, making it possible to perform structure-specific operations such as
-- reconstructing the terms' source code representation.
triage = (\a b c : t (t a b) c)
-- Base case of a single Leaf
sourceLeaf = t (head "t")
-- Stem case
sourceStem = (\convert : (\a rest :
t (head "(") -- Start with a left parenthesis "(".
(t (head "t") -- Add a "t"
(t (head " ") -- Add a space.
(convert a -- Recursively convert the argument.
(t (head ")") rest)))))) -- Close with ")" and append the rest.
-- Fork case
sourceFork = (\convert : (\a b rest :
t (head "(") -- Start with a left parenthesis "(".
(t (head "t") -- Add a "t"
(t (head " ") -- Add a space.
(convert a -- Recursively convert the first arg.
(t (head " ") -- Add another space.
(convert b -- Recursively convert the second arg.
(t (head ")") rest)))))))) -- Close with ")" and append the rest.
-- Wrapper around triage
toSource_ = y (\self arg :
triage
sourceLeaf -- Triage `a` case, Leaf
(sourceStem self) -- Triage `b` case, Stem
(sourceFork self) -- Triage `c` case, Fork
arg) -- The term to be inspected
-- toSource takes a single TC term and returns a String
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)))"