Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
ACL - secntion 4.4 example
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
arnuld  
View profile  
 More options Feb 6, 1:41 am
Newsgroups: comp.lang.lisp
From: arnuld <sunr...@invalid.address>
Date: 06 Feb 2012 06:41:54 GMT
Local: Mon, Feb 6 2012 1:41 am
Subject: ACL - secntion 4.4 example
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Feb 6, 2:06 am
Newsgroups: comp.lang.lisp
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Mon, 06 Feb 2012 08:06:19 +0100
Local: Mon, Feb 6 2012 2:06 am
Subject: Re: ACL - secntion 4.4 example

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.

Or if you're lazy Read the reference!, and use LET*.

--
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Feb 6, 2:49 am
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <k...@kylheku.com>
Date: Mon, 6 Feb 2012 07:49:26 +0000 (UTC)
Local: Mon, Feb 6 2012 2:49 am
Subject: Re: ACL - secntion 4.4 example
On 2012-02-06, arnuld <sunr...@invalid.address> wrote:

> 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-word2 (str)
>   (let ((p1 (+ 1 (position #\  str)))
>    (p2 (position #\  str :start p1)))
>     (subseq str p1 p2)))

Research the difference between let and let*

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Feb 16, 9:36 pm
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 17 Feb 2012 02:36:00 GMT
Subject: Re: ACL - secntion 4.4 example

MatzLisp:

second_word = lambda{|str| str.split[1]}

second_word[ "the fever called living" ]
    ==>"fever"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Feb 17, 11:13 am
Newsgroups: comp.lang.lisp
From: Marco Antoniotti <marc...@gmail.com>
Date: Fri, 17 Feb 2012 08:13:30 -0800 (PST)
Local: Fri, Feb 17 2012 11:13 am
Subject: Re: ACL - secntion 4.4 example

Oh yeah!  How did you know I needed a sleeping aid?  Yawn.

Cheers
--
MA


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Mar 6, 5:12 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 6 Mar 2012 10:12:53 GMT
Local: Tues, Mar 6 2012 5:12 am
Subject: Re: ACL - secntion 4.4 example

NewLisp:

(define (second-word str)  ((parse str " ") 1))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Mar 24, 12:24 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 24 Mar 2012 04:24:11 GMT
Local: Sat, Mar 24 2012 12:24 am
Subject: Re: ACL - secntion 4.4 example

Clojure:

user=> (second (.split "the fever called living" " "))
"fever"

user=> (-> "the fever called living" (.split " ") second)
"fever"


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »