mes/test.mes

335 lines
6.1 KiB
Scheme

;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
;;;
;;; test.mes: This file is part of Mes.
;;;
;;; Mes is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; Mes is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
;; The Maxwell Equations of Software -- John McCarthy page 13
;; http://www.softwarepreservation.org/projects/LISP/book/LISP%201.5%20Programmers%20Manual.pdf
(display 123)
4
(newline)
(cons (display 'one-) (display 'two))
(newline)
(display 'hello-display-symbol)
(newline)
(display '(0 1 2))
(newline)
(display (- 12 3))
(newline)
(display (+ 3 4))
(newline)
(display "(and): ")
(display (and))
(newline)
(display "(and 1): ")
(display (and 1))
(newline)
(display "(and 1 (= 0 1)): ")
(display (and 1 (= 0 1)))
(newline)
(display "(or): ")
(display (or))
(newline)
(display "(or 1): ")
(display (or 1))
(newline)
(display "(or #f (= 0 1) 3): ")
(display (or #f (= 0 1) 3))
(newline)
(display (or (= 0 1) #f (and (display "YEAH") (newline) 'woet)))
(newline)
(let ((p 5)
(q 6))
(display 'let-p:3-q:4)
(newline)
(display 'p:)
(display p)
(newline)
(display 'q:)
(display q)
(newline))
(display
(let ((p 5)
(q 6))
(display 'hallo)
(display p)
(display 'daar)
(display q)
(display 'dan)))
(newline)
(display 'let-dun)
(newline)
(let loop ((lst '(3 2 1)))
(display "loop")
(newline)
(if (null? lst) (begin (display "dun") 'dun)
(begin
(display "looping: ")
(display (car lst))
(newline)
(loop (cdr lst)))))
(newline)
(define c 'b)
`(aa bb ,c)
(display `(pp qq ,c))
(newline)
(display
(let* ((aa 2)
(bb (+ aa 3))
#! boo !#
;;(bb 4)
)
(display 'allo:)
bb))
(newline)
(display 'let*-dun)
(newline)
(map display '(1 2 3 4))
(newline)
(map (lambda (x) (display x) (newline)) '(5 6 7 8))
(newline)
(map (lambda (i a) (display i) (display ':) (display a) (newline)) '(1 2 3 4) '(a b c d))
(newline)
(define a 0)
(display 'a=0:)
(display a)
(newline)
(display "set!")
(display (set! a 1))
(set! a 1)
(display 'a=1:)
(display a)
(newline)
(display
((lambda (x)
(display 'x:)
(display x)
(newline)
(display 'setting-x=2)
(newline)
(set! x 2)
(display 'x:)
(display x)
(newline))
1))
(display (+ 11 12))
(newline)
(display (* 3 3))
(newline)
(display (/ 9 3))
(newline)
(display (= 3 '3))
(newline)
(display (if #t 'true))
(newline)
(display (if (eq? 0 '0) 'true 'false))
(newline)
(display (if (= 1 2) 'true 'false))
(newline)
(display 'factorial4=)
(display
(letrec ((factorial (lambda (n)
;; (display 'factorial:)
;; (display n)
;; (newline)
(if (= n 1) 1
(* n (factorial (- n 1)))))))
(factorial 4)))
(newline)
(define a 2)
(begin
(display 'a+3=)
(display (+ a 3)))
(newline)
" a b c"
(display "string me")
(newline)
(display (string-append "a" "b" "c"))
(newline)
(display (string-length (string-append "a" "b" "c")))
(newline)
#\m
(display #\m)
(newline)
(display #\101)
(newline)
(display #\newline)
(newline)
(display #\space)
(newline)
(display (string #\a #\space #\s #\t #\r #\i #\n #\g #\newline))
(newline)
(display "length of nil: ")
(display (length '()))
(newline)
(display "length of '(a b c): ")
(display (length '(a b c)))
(newline)
#(a b c)
(display #(0 1 2))
(newline)
(define v #("a" "b" "c"))
(display "vector?: ")
(display (vector? v))
(newline)
(display "length of ")
(display v)
(display ": ")
(display (vector-length v))
(newline)
(display "as list: ")
(define lv (vector->list v))
(display lv)
(newline)
(display "again as vector: ")
(display (list->vector lv))
(newline)
(display "(vector 0 1 2): ")
(display (vector 0 1 2))
(newline)
(display "v[1]: ")
(display (vector-ref v 1))
(newline)
(display "v[1]=q: ")
(vector-set! v 1 'q)
(display v)
(newline)
(display "memq a: ")
(display (memq 'a '(a b c)))
(newline)
(display "memq b: ")
(display (memq 'b '(a b c)))
(newline)
(display "memq c: ")
(display (memq 'c '(a b c)))
(newline)
(display "memq d: ")
(display (memq 'd '(a b c)))
(newline)
(display "plus: ")
(display (+ 1 1 1 1))
(newline)
;; works, but debugging is foo
;; (cond ((defined? 'loop2)
;; (display "mes:values broken after loop2")
;; (newline))
;; (#t
;; (values 0 1)
;; (display "(values 0 1): ")
;; (display (values 0 1))
;; (newline)
;; (display "call-with-values ==> 6: ")
;; (display
;; (call-with-values (lambda () (values 1 2 3))
;; (lambda (a b c) (+ a b c))))
;; (newline)
;; (display "call-with-values ==> 1: ")
;; (display ((lambda (x) x) (values 1 2 3)))
;; (newline)))
(display "(procedure? builtin?: ")
(display (procedure? builtin?))
(newline)
(display "(procedure? procedure?): ")
(display (procedure? procedure?))
(newline)
(define *gensym* 0)
(define (gensym)
(set! *gensym* (+ *gensym* 1))
(string->symbol (string-append "g" (number->string *gensym*))))
(display (gensym))
(newline)
(display (gensym))
(newline)
(display (gensym))
(newline)
(display "unquote:")
(display `,(list 1 2 3 4))
(newline)
(display `('boo ,@'(bah baz) 1 2))
(newline)
(display "splice:")
(display `(1 ,@(list 2 3) 4))
(newline)
(define s-r '(2 3))
(display "splice:")
(display `(1 ,@s-r 4))
(newline)
(display "`(1 2 '(,(+ 1 2))): ")
(display `(1 2 '(,(+ 1 2))))
(newline)
(display "when:")
(when #t
(display "true")
(newline))
(when #f
(display "must not see")
(newline))
'()