On Friday, February 17, 2012 3:36:00 AM UTC+1, WJ wrote:
> Pascal J. Bourguignon wrote:
> > arnuld <sunr...@invalid.address> writes:
> > > 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
> > Read the reference!
> > http://www.lispworks.com/documentation/HyperSpec/Body/s_let_l.htm#let
> > "first evaluates the expressions init-form-1, init-form-2, and so on,
> > in that order, saving the resulting values. Then all of the
> > variables varj are bound to the corresponding values; each binding
> > is lexical unless there is a special declaration to the contrary. "
> > In English, it means that p1 is not visible in the initializing
> > expressions of p2.
> > You should write:
> > (defun second-word2 (str)
> > (let ((p1 (+ 1 (position #\ str))))
> > (let ((p2 (position #\ str :start p1)))
> > (subseq str p1 p2))))
> > instead.
> MatzLisp:
> second_word = lambda{|str| str.split[1]}
> second_word[ "the fever called living" ]
> ==>"fever"
Oh yeah! How did you know I needed a sleeping aid? Yawn.