; ; Lisp experiments ; Usage:- clisp -repl douglisp.txt ; ; Within clisp use: ; usage: (load "douglisp.txt") ; ; use repl to print out value "hello world" ; use a function to print out a value (print "hello world" ) (setf *doug* 10.234 ) ; ; Define a function (defun hello-world () (format t "hello, world") ) ; call function just defined (hello-world ) (print "hello world" ) (format t " num: ~d /n \nstr: ~a \nvar: ~d" (/ 10.0 20.0 7.0 ) "hello doug" *doug* ) ; Simple list iteration (dolist (i (list 1 2 3 4 5 6 7 )) (print i)) (print "=========================================================" ) ; (loop for i from min to max by step do (print i ) ) (loop for i from 0 to 10 by 3 do (print "i: " ) ) (print "=========================================================" ) ; use #' to print out the source code (print #'hello-world ) ; ; ; (print "=========================================================" ) (let ((in (open "dougdb.txt" :if-does-not-exist nil))) (when in (format t "/b0:" "") (format t "/b1: ~a~%" (read-line in)) (format t "/b2: ~a~%" (read-line in)) (close in) ) ) (print "=========================================================" ) (setf *db* "hello doug how are, you?" ) (print *db* ) ; file handling (defun save-db ( filename ) (with-open-file (out filename :direction :output ) (with-standard-io-syntax (print *db* out) (print *db* out) (print *db* out) (print *db* out) (print *db* out) (print *db* out) ) (close out ) )) (save-db "dougdb.txt") (print "=========================================================" ) (setf *db* nil ) (print *db* ) ; file handling (defun load-db ( filename ) (with-open-file (in filename :direction :input ) (with-standard-io-syntax (print (read-line in )) (setf *db* (read-line in )) ) ) ) (load-db "dougdb.txt") (print *db* ) (print "=========================================================" ) ; exit ( exit )