Thursday, October 18, 2018

Scheme and Kawa Lisps

I've run some exercises in the interpreter that I downloaded from www.scheme.com


> '(a b c d)
'(a b c d)
> (cons 'a '(b c))
'(a b c)
> (* 5 5)
25
> (define quadruple (lambda (n) (+ n n n n)))
> (quadruple 7)
28
> (cons 'a '(b c))
'(a b c)
> (car (cons 'x '(y z)))
'x
> (define doubler (lambda (f) (lambda (x) (f x x))))
> (define double (doubler +))
> (double 13/2)
13
> (define recip (lambda (n) (and (not (= n 0)) (/ 1 n))))
> (recip 4)
1/4
> (recip 3)
1/3
> (recip 0)
#f
> (define x1 '(one two three))
> (cons 'zero x1)
'(zero one two three)
> (define x2 (cons 'zero x1))
> (cdr x2)
'(one two three)
> (car x2)
'zero

And Kawa which is Scheme implemented on the JVM.

Code saved in First.scm file:
(display (< 7 9))
(newline)
(display (+ 7 11))
(newline)
Run command:
$ java -jar lib/kawa.jar ../src/First.scm
#t
18