still looking
This commit is contained in:
parent
446aa1395b
commit
d209f3113b
|
@ -135,13 +135,18 @@
|
|||
|
||||
(make-bootstrapped-primitive-code
|
||||
'append
|
||||
'(letrec ([append (lambda (l1 l2)
|
||||
(if (null? l1)
|
||||
l2
|
||||
(cons (car l1) (append (cdr l1) l2))))])
|
||||
append))
|
||||
|
||||
|
||||
'(letrec ([append-many (lambda (lsts)
|
||||
(if (null? lsts)
|
||||
null
|
||||
(if (null? (cdr lsts))
|
||||
(car lsts)
|
||||
(append-2 (car lsts)
|
||||
(append-many (cdr lsts))))))]
|
||||
[append-2 (lambda (l1 l2)
|
||||
(if (null? l1)
|
||||
l2
|
||||
(cons (car l1) (append-2 (cdr l1) l2))))])
|
||||
(lambda args (append-many args))))
|
||||
|
||||
|
||||
|
||||
|
|
22
runtime.js
22
runtime.js
|
@ -359,7 +359,13 @@
|
|||
Primitives['display'] = function(MACHINE) {
|
||||
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
||||
var outputPort = MACHINE.params.currentOutputPort;
|
||||
if (MACHINE.argcount === 2) {
|
||||
if (MACHINE.argcount === 2) {
|
||||
testArgument(MACHINE,
|
||||
'isOutputPort',
|
||||
isOutputPort,
|
||||
MACHINE.env.length-2,
|
||||
1,
|
||||
'display');
|
||||
outputPort = MACHINE.env[MACHINE.env.length-2];
|
||||
}
|
||||
outputPort.write(MACHINE, firstArg);
|
||||
|
@ -371,6 +377,12 @@
|
|||
Primitives['newline'] = function(MACHINE) {
|
||||
var outputPort = MACHINE.params.currentOutputPort;
|
||||
if (MACHINE.argcount === 1) {
|
||||
testArgument(MACHINE,
|
||||
'isOutputPort',
|
||||
isOutputPort,
|
||||
MACHINE.env.length-1,
|
||||
1,
|
||||
'newline');
|
||||
outputPort = MACHINE.env[MACHINE.env.length-1];
|
||||
}
|
||||
outputPort.write(MACHINE, "\n");
|
||||
|
@ -382,7 +394,13 @@
|
|||
Primitives['displayln'] = function(MACHINE){
|
||||
var firstArg = MACHINE.env[MACHINE.env.length-1];
|
||||
var outputPort = MACHINE.params.currentOutputPort;
|
||||
if (MACHINE.argcount === 2) {
|
||||
if (MACHINE.argcount === 2) {
|
||||
testArgument(MACHINE,
|
||||
'isOutputPort',
|
||||
isOutputPort,
|
||||
MACHINE.env.length-2,
|
||||
1,
|
||||
'displayln');
|
||||
outputPort = MACHINE.env[MACHINE.env.length-2];
|
||||
}
|
||||
outputPort.write(MACHINE, firstArg);
|
||||
|
|
|
@ -72,9 +72,29 @@ EOF
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(test '(display 42)
|
||||
"42")
|
||||
|
||||
(test '(displayln (+))
|
||||
"0\n")
|
||||
|
||||
(test '(displayln (*))
|
||||
"1\n")
|
||||
|
||||
(test '(displayln (- 3))
|
||||
"-3\n")
|
||||
|
||||
(test '(displayln (- 3 4))
|
||||
"-1\n")
|
||||
|
||||
(test '(displayln (- 3 4 -10))
|
||||
"9\n")
|
||||
|
||||
|
||||
(test '(display (+ 3 4))
|
||||
"7")
|
||||
|
||||
|
@ -383,6 +403,67 @@ EOF
|
|||
"x\n")
|
||||
|
||||
|
||||
(test '(begin (displayln (vector-length (vector))))
|
||||
"0\n")
|
||||
|
||||
(test '(begin (displayln (vector-length (vector 3 1 4))))
|
||||
"3\n")
|
||||
|
||||
(test '(begin (displayln (vector-ref (vector 3 1 4) 0)))
|
||||
"3\n")
|
||||
|
||||
(test '(begin (displayln (vector-ref (vector 3 1 4) 1)))
|
||||
"1\n")
|
||||
|
||||
(test '(begin (displayln (vector-ref (vector 3 1 4) 2)))
|
||||
"4\n")
|
||||
|
||||
(test '(begin (define v (vector "hello" "world"))
|
||||
(vector-set! v 0 'hola)
|
||||
(displayln (vector-ref v 0)))
|
||||
"hola\n")
|
||||
|
||||
(test '(begin (define v (vector "hello" "world"))
|
||||
(vector-set! v 0 'hola)
|
||||
(displayln (vector-ref v 1)))
|
||||
"world\n")
|
||||
|
||||
|
||||
|
||||
(test '(begin (define l (vector->list (vector "hello" "world")))
|
||||
(displayln (length l))
|
||||
(displayln (car l))
|
||||
(displayln (car (cdr l))))
|
||||
"2\nhello\nworld\n")
|
||||
|
||||
|
||||
(test '(displayln (equal? '(1 2 3)
|
||||
(append '(1) '(2) '(3))))
|
||||
"true\n")
|
||||
|
||||
|
||||
(test '(displayln (equal? '(1 2 3)
|
||||
(append '(1 2) '(3))))
|
||||
"true\n")
|
||||
|
||||
(test '(displayln (equal? '(1 2 3)
|
||||
(append '(1 2) 3)))
|
||||
"false\n")
|
||||
|
||||
(test '(displayln (equal? "hello"
|
||||
(string-append "he" "llo")))
|
||||
"true\n")
|
||||
|
||||
|
||||
(test '(displayln (equal? '(1 2 (3))
|
||||
'(1 2 (3))))
|
||||
"true\n")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#;(test (read (open-input-file "tests/conform/program0.sch"))
|
||||
|
|
Loading…
Reference in New Issue
Block a user