
<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="0.92">
<channel>
	<title>i-cjw .:. Lispersion</title>
	<link>http://i-cjw.com/lisp</link>
	<description></description>
	<lastBuildDate>Mon, 09 Jun 2008 12:10:08 +0000</lastBuildDate>
	<docs>http://backend.userland.com/rss092</docs>
	<language>en</language>
	
	<item>
		<title>Iteration &#038; Block Structure</title>
		<description>---------------------------------------------------------
Chapter 11
---------------------------------------------------------

Iteration and Block Structure

(dotimes (i 4)
	(format t "~&I is ~S." i))
I is 0.
I is 1...

(dolist (x '(red green blue) 'flowers)
	(format t "~&Roses are ~S" x))
Roses are RED
Roses are BLUE
Roses are GREEN
FLOWERS

dolist returns the final symbol in its parameters (i.e. Flowers, above)

RETURN can be used to break the loop - ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/iteration-block-structure/</link>
			</item>
	<item>
		<title>Assignment</title>
		<description>---------------------------------------------------------
Chapter 10
---------------------------------------------------------

Global Variables

(SETF *my-global-variable* 0) -> initializes to zero

(defun sell (n)
 (SETF *my-global-variable* (+ *my-global-variable* n))
 (format t "Sold ~S glasses today" *my-global-variable*))

If variable set to FOO, then will fail when try to increment.  If variable not initialized to zero, then will fail when incremented.

For simple incrementing and decrementing, ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/assignment/</link>
			</item>
	<item>
		<title>Input/Output</title>
		<description>---------------------------------------------------------
Chapter 9
---------------------------------------------------------

Input/Output

Strings - double quoted:
(setf a "this is a string") -> "this is a string"
(stringp a) -> T

(format t a) -> this is a string -> NIL

tilde character leads to special operations
~% -> forces newline

(format t "time flies~%like an arrow") ->
time flies
like an arrow
NIL

~& forces a newline, unless the cursor ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/inputoutput/</link>
			</item>
	<item>
		<title>Recursion</title>
		<description>---------------------------------------------------------
Chapter 8
---------------------------------------------------------

Recursion:

Double-tail recursion returns one of two results:
(DEFUN anyoddp (x)
	(COND 	((null x) NIL)
			((oddp (first x)) T)
			(T (anyoddp (rest x)))))

Single-tail recursion returns one result:
(DEFUN find-first-atom (x)
	(COND	((atom x) x)
			(T (find-first-atom (rest x)))))

Augmenting recusion loops using the result to build the final answer:
(DEFUN fib (x)
	(COND	((NULL x) 0)
			(T (+ x (fib (- x 1))))))

List ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/recursion/</link>
			</item>
	<item>
		<title>Applicative Programming</title>
		<description>---------------------------------------------------------
Chapter 7
---------------------------------------------------------

FUNCALL calls a function on some inputs:

(FUNCALL #'cons 'a 'b) -> (a . b)

Can also map a function to a symbol:
(SETF fn #'cons)
(FUNCALL fn 'a 'b) -> (a . b)

only ordinary functions should be quoted with #' - macros, symbols or special functions will generate an error (#'IF -> ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/applicative-programming/</link>
			</item>
	<item>
		<title>List Data Structures</title>
		<description>---------------------------------------------------------
Chapter 6
---------------------------------------------------------

(APPEND '(1 2 3) '(4 5 6)) -> (1 2 3 4 5 6)
(APPEND NIL '(1 2 3)) -> (1 2 3)
(APPEND '(1 2 3) NIL) -> (1 2 3)
(APPEND NIL NIL) -> NIL
(APPEND '((1 2) (3 4)) '((5 6) (7 8))) -> ((1 2) (3 4) (5 6) ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/list-data-structures/</link>
			</item>
	<item>
		<title>Variables &#038; Side Effects</title>
		<description>---------------------------------------------------------
Chapter 5
---------------------------------------------------------

SETF assigns a global variable:
(SETF n 1)
(SETF x '(1 2 3))
(LENGTH x) -> 3
(REST x) -> (2 3)

variables have scope - to create a local variable use LET:

(DEFUN MANIP (op x y)
	(LET ( (SUM (+ x y)) (PROD (* x y)) )
		(COND 	((EQUAL op 'AVG) (/ SUM 2.0))
				((EQUAL op ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/variables-side-effects/</link>
			</item>
	<item>
		<title>Conditionals</title>
		<description>---------------------------------------------------------
Chapter 4
---------------------------------------------------------

Conditionals - IF:

(IF (ODDP 5) 'odd 'even) -> odd

COND

(DEFUN COMPARE-TO (x y)
	(COND 	((EQUAL x y) 'equal)
			((> x y) 'x-greater-than-y)
			(( 2 1) (< 3 4)) ->T
(OR (> 1 2) (< 3 4)) -> T

AND progresses until it hits a NIL (in which case it returns NIL) or the end of ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/conditionals/</link>
			</item>
	<item>
		<title>EVAL notation</title>
		<description>---------------------------------------------------------
Chapter 3
---------------------------------------------------------

Numbers, and the symbols NIL and T, evaluate to themselves:

1 -> 1
T -> T
NIL -> NIL

Evaluation rule for lists - the first element is the function to call, the rest are arguments to the function.

(DEFUN my-function (x)
	(* x 2))

Evaluation rule for symbols - a symbol evaluates to the value ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/eval-notation/</link>
			</item>
	<item>
		<title>Lists</title>
		<description>---------------------------------------------------------
Chapter 2
---------------------------------------------------------

Each element of a LIST is a CONS cell, linked to the next one and terminated with NIL

LENGTH returns the number of elements in a LIST
(LENGTH '(1 2 3 4)) -> 4
(LENGTH '(1 (2 3) 4) -> 3

(FIRST '(1 2 3)) -> 1
(SECOND '(1 2 3)) -> 2
(THIRD '(1 ...</description>
		<link>http://i-cjw.com/lisp/2008/06/08/lists/</link>
			</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.585 seconds -->
