From 4e2a1d21e004ae5b195ef937064d54de5905a333 Mon Sep 17 00:00:00 2001 From: d_m Date: Thu, 11 Apr 2024 18:38:49 -0400 Subject: [PATCH] it's working --- demo.modal | 69 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/demo.modal b/demo.modal index ade1549..5ea513f 100644 --- a/demo.modal +++ b/demo.modal @@ -21,16 +21,16 @@ <> (binary 9) ((1 (0 (0 (1 nil))))) -- ( binary to decimal digit ) -<> (decimal (0 nil)) (0) -<> (decimal (1 nil)) (1) -<> (decimal (0 (1 nil))) (2) -<> (decimal (1 (1 nil))) (3) -<> (decimal (0 (0 (1 nil)))) (4) -<> (decimal (1 (0 (1 nil)))) (5) -<> (decimal (0 (1 (1 nil)))) (6) -<> (decimal (1 (1 (1 nil)))) (7) -<> (decimal (0 (0 (0 (1 nil))))) (8) -<> (decimal (1 (0 (0 (1 nil))))) (9) +<> ((decimal (0 nil))) (0) +<> ((decimal (1 nil))) (1) +<> ((decimal (0 (1 nil)))) (2) +<> ((decimal (1 (1 nil)))) (3) +<> ((decimal (0 (0 (1 nil))))) (4) +<> ((decimal (1 (0 (1 nil))))) (5) +<> ((decimal (0 (1 (1 nil))))) (6) +<> ((decimal (1 (1 (1 nil))))) (7) +<> ((decimal (0 (0 (0 (1 nil)))))) (8) +<> ((decimal (1 (0 (0 (1 nil)))))) (9) -- create nil-terminated list <> (nilify (?h)) ((?h nil)) @@ -58,6 +58,49 @@ <> (f (?u) (?h ?t)) (((mul ?h ?u) f ((mul ?u ten)) ?t)) -- ( to string: TODO, need division for this one ) +<> ((str ?x)) ((str1 (divmod ?x ten) nil)) +<> ((str1 (?q ?r) ?a)) ((str2 ?q (?r ?a))) +<> ((str2 (0 nil) ?a)) ((str3 ?a nil)) +<> ((str2 (0 (?h ?t)) ?a)) ((str1 (divmod (0 (?h ?t)) ten) ?a)) +<> ((str2 (1 ?t) ?a)) ((str1 (divmod (1 ?t) ten) ?a)) +<> ((str3 nil ?a)) ((digitize ?a nil)) +<> ((str3 (?h ?t) nil)) ((str3 ?t (decimal ?h))) +<> ((str3 (?h ?t) (?a ?b))) ((str3 ?t ((decimal ?h) (?a ?b)))) + +<> ((digitize (0 ?t) nil)) ((digitize ?t (0))) +<> ((digitize (1 ?t) nil)) ((digitize ?t (1))) +<> ((digitize (2 ?t) nil)) ((digitize ?t (2))) +<> ((digitize (3 ?t) nil)) ((digitize ?t (3))) +<> ((digitize (4 ?t) nil)) ((digitize ?t (4))) +<> ((digitize (5 ?t) nil)) ((digitize ?t (5))) +<> ((digitize (6 ?t) nil)) ((digitize ?t (6))) +<> ((digitize (7 ?t) nil)) ((digitize ?t (7))) +<> ((digitize (8 ?t) nil)) ((digitize ?t (8))) +<> ((digitize (9 ?t) nil)) ((digitize ?t (9))) + +<> ((digitize (0 ?t) ?a)) ((digitize ?t (0 ?a))) +<> ((digitize (1 ?t) ?a)) ((digitize ?t (1 ?a))) +<> ((digitize (2 ?t) ?a)) ((digitize ?t (2 ?a))) +<> ((digitize (3 ?t) ?a)) ((digitize ?t (3 ?a))) +<> ((digitize (4 ?t) ?a)) ((digitize ?t (4 ?a))) +<> ((digitize (5 ?t) ?a)) ((digitize ?t (5 ?a))) +<> ((digitize (6 ?t) ?a)) ((digitize ?t (6 ?a))) +<> ((digitize (7 ?t) ?a)) ((digitize ?t (7 ?a))) +<> ((digitize (8 ?t) ?a)) ((digitize ?t (8 ?a))) +<> ((digitize (9 ?t) ?a)) ((digitize ?t (9 ?a))) + +<> ((digitize 0 ?a)) ((stringify (0 ?a))) +<> ((digitize 1 ?a)) ((stringify (1 ?a))) +<> ((digitize 2 ?a)) ((stringify (2 ?a))) +<> ((digitize 3 ?a)) ((stringify (3 ?a))) +<> ((digitize 4 ?a)) ((stringify (4 ?a))) +<> ((digitize 5 ?a)) ((stringify (5 ?a))) +<> ((digitize 6 ?a)) ((stringify (6 ?a))) +<> ((digitize 7 ?a)) ((stringify (7 ?a))) +<> ((digitize 8 ?a)) ((stringify (8 ?a))) +<> ((digitize 9 ?a)) ((stringify (9 ?a))) + +<> ((stringify ?*)) (?*) -- ( comparison operartions ) <> ((cmp ?x ?y)) ((cmpc #eq ?x ?y)) @@ -131,8 +174,8 @@ -- ( divmod, i.e. quotient and remainder ) <> ((divmod ?x ?y)) ((divmod1 ?x ?y (cmp ?x ?y))) -<> ((divmod1 ?x ?y #lt)) (zero) -<> ((divmod1 ?x ?y #eq)) (one) +<> ((divmod1 ?x ?y #lt)) ((zero ?x)) +<> ((divmod1 ?x ?y #eq)) ((one zero)) <> ((divmod1 ?x ?y #gt)) ((divmod2 ?x ?y zero (0 ?y))) <> ((divmod2 ?x ?y ?s ?m)) ((divmod3 ?x ?y ?s ?m (cmp ?x ?m))) <> ((divmod3 ?x ?y ?s ?m #lt)) ((divmod4 ?x ?y ?s zero)) @@ -155,4 +198,4 @@ <> ((mod ?x ?y)) ((mod' (divmod ?x ?y))) <> ((mod' (?q ?r))) (?r) -(mod (int 64) (int 13)) +(str (mul (int 235) (int 345)))