[funds-cvs] r37 - trunk/funds/src/stack

abaine at common-lisp.net abaine at common-lisp.net
Mon Jul 2 22:39:22 UTC 2007


Author: abaine
Date: Mon Jul  2 18:39:22 2007
New Revision: 37

Added:
   trunk/funds/src/stack/
   trunk/funds/src/stack/stack.lisp
Log:
Initial version of stack.

Added: trunk/funds/src/stack/stack.lisp
==============================================================================
--- (empty file)
+++ trunk/funds/src/stack/stack.lisp	Mon Jul  2 18:39:22 2007
@@ -0,0 +1,30 @@
+
+(in-package :funds)
+
+(defun make-stack ()
+  "An empty stack."
+  nil)
+
+(defun stack-push (item stack)
+  "The stack that results when the given item is pushed onto the given stack."
+  (cons item stack))
+
+(defun stack-pop (stack) 
+  "The stack that results when the top item is popped off the given stack."
+  (cdr stack))
+
+(defun stack-top (stack) 
+  "The top item on the given stack."
+  (car stack))
+
+(defun stack-empty-p (stack)
+  "Whether the given stack is empty."
+  (null stack))
+
+(defun stack-length (stack)
+  "The number of items on this stack; note that this is an O(n) operation."
+  (labels ((f (stack accum)
+	     (if (stack-empty-p stack)
+		 accum
+		 (f (stack-pop stack) (1+ accum)))))
+    (f stack 0)))



More information about the Funds-cvs mailing list