Here is what ACL has created on function called "second-word" which
returns 2nd word of a string. I have edited it to use variable p2 but
that does not work.
PROBLEM: Why p2 is undefined ?
(defun second-word (str)
(let ((p1 (+ 1 (position #\ str))))
(subseq str p1 (position #\ str :start p1))))
(defun second-word2 (str)
(let ((p1 (+ 1 (position #\ str)))
(p2 (position #\ str :start p1)))
(subseq str p1 p2)))
====================== OUTPUT =====================
[35]> (load "second-word.lisp")
;; Loading file second-word.lisp ...
;; Loaded file second-word.lisp
T
[36]> (defvar jkd "Bruce Lee")
JKD
[37]> (second-word jkd)
"Lee"
[38]> (second-word2 jkd)
*** - LET: variable P1 has no value
The following restarts are available:
USE-VALUE :R1 Input a value to be used instead of P1.
STORE-VALUE :R2 Input a new value for P1.
ABORT :R3 Abort main loop
Break 1 [39]> ABORT
[40]> (second-word "Pascal")
*** - +: NIL is not a number
The following restarts are available:
USE-VALUE :R1 Input a value to be used instead.
ABORT :R2 Abort main loop
Break 1 [41]>
--
arnuld
http://LispMachine.Wordpress.com