From 665ad1f48ddb4513272bfecb372651a4ea96d869 Mon Sep 17 00:00:00 2001 From: elioat Date: Mon, 9 Sep 2024 12:07:00 -0400 Subject: * --- html/playground/scheme.html | 123 +++----------------------------------------- 1 file changed, 6 insertions(+), 117 deletions(-) (limited to 'html/playground') diff --git a/html/playground/scheme.html b/html/playground/scheme.html index dc6fb55..b8ecd6f 100644 --- a/html/playground/scheme.html +++ b/html/playground/scheme.html @@ -83,7 +83,10 @@ -
+
+
+
+
@@ -382,122 +385,8 @@ function mountRepl(playground) { } -mount(mountRepl); - - - -// Testing 'define' and arithmetic operations -console.log(evalScheme("(define x 10)")); // Should define 'x' as 10 -console.log(evalScheme("(+ x 5)")); // Should return 15 -console.log(evalScheme("(- x 3)")); // Should return 7 -console.log(evalScheme("(* x 2)")); // Should return 20 -console.log(evalScheme("(/ x 2)")); // Should return 5 - -// Testing 'eq?' for equality -console.log(evalScheme("(eq? 1 1)")); // Should return true -console.log(evalScheme("(eq? 1 2)")); // Should return false - -// Testing 'car', 'cdr', 'cons', 'null?' -console.log(evalScheme("(car (quote (1 2 3)))")); // Should return 1 -console.log(evalScheme("(cdr (quote (1 2 3)))")); // Should return (2 3) -console.log(evalScheme("(cons 1 (quote (2 3)))")); // Should return (1 2 3) -console.log(evalScheme("(null? (quote ()))")); // Should return true -console.log(evalScheme("(null? (quote (1 2 3)))")); // Should return false - -// Testing 'zero?' for checking zero -console.log(evalScheme("(zero? 0)")); // Should return true -console.log(evalScheme("(zero? 1)")); // Should return false - -// Testing 'atom?' for checking if an element is an atom -console.log(evalScheme("(atom? 1)")); // Should return true -console.log(evalScheme("(atom? (quote (1 2 3)))")); // Should return false - -// Testing 'number?' for checking if an element is a number -console.log(evalScheme("(number? 42)")); // Should return true -console.log(evalScheme("(number? (quote hello))")); // Should return false - -// Testing 'add1' and 'sub1' -console.log(evalScheme("(add1 5)")); // Should return 6 -console.log(evalScheme("(sub1 5)")); // Should return 4 - -// Testing 'quote' for returning unevaluated expressions -console.log(evalScheme("(quote (1 2 3))")); // Should return (1 2 3) - -// Testing 'and' and 'or' -console.log(evalScheme("(and true true)")); // Should return true -console.log(evalScheme("(and true false)")); // Should return false -console.log(evalScheme("(or false false)")); // Should return false -console.log(evalScheme("(or true false)")); // Should return true - -// Testing 'lambda' with a function definition -console.log(evalScheme("(define add1 (lambda (x) (+ x 1)))")); // Should define add1 function -console.log(evalScheme("(add1 10)")); // Should return 11 - -// Testing 'if' for conditional expressions -console.log(evalScheme("(if (eq? 1 1) (quote yes) (quote no))")); // Should return 'yes -console.log(evalScheme("(if (eq? 1 2) (quote yes) (quote no))")); // Should return 'no - -// Testing 'cond' for multiple conditions -console.log(evalScheme("(cond ((eq? 1 2) (quote no)) ((eq? 2 2) (quote yes)))")); // Should return 'yes -console.log(evalScheme("(cond ((eq? 1 2) (quote no)) ((eq? 3 2) (quote nope)))")); // Should return null (no matching condition) - -// Testing 'letrec' for recursive bindings -console.log(evalScheme("(letrec ((factorial (lambda (n) (if (zero? n) 1 (* n (factorial (sub1 n))))))) (factorial 5))")); -// Should return 120 (5!) -
15
7
20
5
true
false
{ - "type": "NumberLiteral", - "value": 1 -}
{ - "type": "List", - "value": [ - { - "type": "NumberLiteral", - "value": 2 - }, - { - "type": "NumberLiteral", - "value": 3 - } - ] -}
{ - "type": "List", - "value": [ - 1, - { - "type": "NumberLiteral", - "value": 2 - }, - { - "type": "NumberLiteral", - "value": 3 - } - ] -}
true
false
true
false
true
false
true
false
6
4
{ - "type": "List", - "value": [ - { - "type": "NumberLiteral", - "value": 1 - }, - { - "type": "NumberLiteral", - "value": 2 - }, - { - "type": "NumberLiteral", - "value": 3 - } - ] -}
true
false
false
true
11
{ - "type": "Symbol", - "value": "yes" -}
{ - "type": "Symbol", - "value": "no" -}
{ - "type": "Symbol", - "value": "yes" -}
null
120
+mount(mountRepl); +