(Need to go deeper!) macroexpansion confusion
Posted: Thu May 10, 2012 2:00 am
I think I mostly avoided using macros until now, but here's something I tried and it doesn't look good to me, particularly the '(,@whites) part - that shouldn't need so much of ASCII art, must be a better way to handle it!
Code: Select all
(defmacro with-words-in-string
((word start end
&aux (whites '(#\Space #\Tab #\Newline #\Rubout)))
s
&body body)
`(do ((,end 0 (1+ ,end))
(,start 0)
(,word)
(len 0))
((= ,end (1+ (length ,s))))
(if (or (= ,end (length ,s)) (find (aref ,s ,end) '(,@whites)))
(if (> len 0)
(progn
(setf ,word (subseq ,s ,start ,end))
,@body
(setf len 0 ,start (1+ ,end)))
(incf ,start))
(incf len))))
(with-words-in-string (word start end)
"Quick brown fox jumped over the lazy dog"
(format t "word: ~s, start: ~s, end: ~s~&" word start end))