Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
irasnyd@duallie lisp $ cat hw13.lisp;Written By: Ira Snyder;Due Date: 03-04-2005;Homework #: HW13 (Exercise #15a);;; Examples of the INC* macro input, and what it is transformed into;; Input: (INC* x y z); Output: (progn; (setf z (1+ z)); (setf y (1+ y)); (setf x (1+ x)); );; Input: (INC* a); Output: (progn (setf a (1+ a)));; Input: (INC*); Output: (progn);;;;;; The INC* macro takes an unlimited number of already initialized;;; variables and increments them by 1. Note that variables that do not;;; already have a value CAN NOT BE INCREMENTED.(defmacro INC* (&rest VARS)(do ((VARS VARS (cdr VARS))(RET nil))((null VARS) (cons 'progn RET))(setf RET (cons `(setf ,(car VARS) (1+ ,(car VARS))) RET))))irasnyd@duallie lisp $ clisp -q[1]> (load 'hw13.lisp);; Loading file hw13.lisp ...;; Loaded file hw13.lispT[2]> (setf x 0 y 1 z 3)3[3]> x0[4]> y1[5]> z3[6]> (INC* x y z)1[7]> x1[8]> y2[9]> z4[10]> (macroexpand-1 '(INC* x y z))(PROGN (SETF Z (1+ Z)) (SETF Y (1+ Y)) (SETF X (1+ X))) ;T[11]> (setf a 0)0[12]> a0[13]> (inc* a)1[14]> a1[15]> (macroexpand-1 '(INC* a))(PROGN (SETF A (1+ A))) ;T[16]> (INC*)NIL[17]> (macroexpand-1 '(INC*))(PROGN) ;T[18]> (bye)irasnyd@duallie lisp $