Created
June 15, 2013 19:21
-
-
Save nsmaciej/5789260 to your computer and use it in GitHub Desktop.
My experimental lisp file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;Guess my number REPL game | |
(defun guess-my-number () | |
(ash (+ *small* *big*) -1) | |
) | |
(defun smaller () | |
(setf *big* (1- (guess-my-number))) ;(1+ x) is same us (+ 1 x) | |
(guess-my-number) | |
) | |
(defun bigger () | |
(setf *small* (1+ (guess-my-number))) | |
(guess-my-number) | |
) | |
(defun start-over () | |
(defparameter *small* 1) | |
(defparameter *big* 100) | |
t | |
* ;Return reuslt of last evaluation | |
) | |
;;Addational guess-my-number experiments | |
(defun smaller2 () | |
(let ((newBig (1- (guess-my-number)))) ;Let 'inherits' return | |
(setf *big* newBig) | |
(guess-my-number) | |
) | |
) | |
;;Let experiments | |
(defun let-test () | |
(let ((*small* 100) | |
(*big* 1) | |
(proper-name 50)) | |
;; ~% is new line ~a is a value | |
(format t "New small: ~a~%New big: ~a~%" *small* *big*)) | |
(let () | |
(format t "Old small: ~a~%Old big: ~a~%" *small* *big*)) | |
(print "Extra stuff") ;Print appends ~% auto | |
t | |
) | |
(defun raw_input (str) | |
(format t "~a" str) ;Has to have format string: Prevents auto ~% | |
(force-output) | |
(read-line) | |
) | |
;;; (eq) compares all (=) only numbers | |
(defun test-prints () | |
(let ((test-string (list "2" :hi 3))) | |
(print test-string);Normal print | |
(prin1 test-string);print + no ~% | |
(princ test-string);Human freindly (print) | |
) | |
() | |
) | |
;;; Control statements 'n' shit | |
(defun test-progn () | |
(princ (if (eq () nil) (progn (format t "Woah dude~%") 'Yey) 'Ney)) | |
) | |
(defun when-and-unless (magic) | |
(when (eq magic 'Yey) (format t "One thing~%") 'We-returned!) | |
(unless (eq magic 'Yey) (format t "Thank god magic isn't 'Yey~%") 'Stuff) | |
(if (eq magic 'Yey) (format t "Yup~%") (progn (format t "Print shit~%") 'Woah)) | |
(case magic | |
('Yey (format t "Case works~%")) | |
(otherwise (format t "It still works~%")) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment