Added lisp along with some study work
This commit is contained in:
BIN
lisp/land-of-lisp/ch2/Schedule June 2017.xlsx
Normal file
BIN
lisp/land-of-lisp/ch2/Schedule June 2017.xlsx
Normal file
Binary file not shown.
23
lisp/land-of-lisp/ch2/guess-my-number-game.lisp
Normal file
23
lisp/land-of-lisp/ch2/guess-my-number-game.lisp
Normal file
@ -0,0 +1,23 @@
|
||||
(defparameter *small* 1)
|
||||
(defparameter *big* 100)
|
||||
|
||||
(defun guess-my-number ()
|
||||
;; ash is the artithmetic shift function
|
||||
;; Halvs the sum of the limits and shortens the result
|
||||
;; ash, here, shifts the binary bits left or right (well, right in this case)
|
||||
;; Which leads to the right most binary falling off
|
||||
;; This is a binary search
|
||||
(ash (+ *small* *big*) -1))
|
||||
|
||||
(defun smaller ()
|
||||
(setf *big* (1- (guess-my-number)))
|
||||
(guess-my-number))
|
||||
|
||||
(defun bigger ()
|
||||
(setf *small* (1+ (guess-my-number)))
|
||||
(guess-my-number))
|
||||
|
||||
(defun start-over ()
|
||||
(defparameter *small* 1)
|
||||
(defparameter *big* 100)
|
||||
(guess-my-number))
|
30
lisp/land-of-lisp/ch2/notes.txt
Normal file
30
lisp/land-of-lisp/ch2/notes.txt
Normal file
@ -0,0 +1,30 @@
|
||||
;; List of variables that are surrounded by parens
|
||||
|
||||
(let ((a 5)
|
||||
(b 6))
|
||||
(+ a b))
|
||||
|
||||
;; Local functions
|
||||
;; It's like let. A list of functions and their descriptions,
|
||||
;; followed by some stuff to do with them
|
||||
(flet ((function_name (args)
|
||||
...Function Body...))
|
||||
body)
|
||||
;;example
|
||||
(flet ((f (n)
|
||||
(+ n 10)))
|
||||
(f 5))
|
||||
|
||||
>> 15
|
||||
|
||||
;; labels -- like flet, but allow functions to call other
|
||||
;; defined functions or themselves
|
||||
;; Same basic structure as flet
|
||||
|
||||
(labels ((a (n)
|
||||
(+ n 5))
|
||||
(b (n)
|
||||
(+ (a n) 6)))
|
||||
(b 10))
|
||||
>> 21
|
||||
|
Reference in New Issue
Block a user