From: globalrev
Subject: defun(using mapcar, equal, setf) going wrong...
Date: 
Message-ID: <d2aa4550-deca-4fa6-8ae9-4db18cd14062@2g2000hsn.googlegroups.com>
(defun encrypt (phrase)
	(mapcar (lambda (x)
		(if (equal x "hej")
			(setf x "right")
			(setf x "wrong")))
				'(phrase)))

returns wrong for whatever i call encrypt with... but (equal "hi"
"hi") returns T.
what ami doing wrong here?
the final function will take a list of strings or chars and replace
consonants with consonant+o+consonant.




an oddity:
first time:
"hej"
hej

then hej "hej". why?

CL-USER> (if (= 1 1)
	     (princ "hej")
	     (princ "bye"))
"hej"
hej
CL-USER> (if (= 1 2)
	     (princ "hej")
	     (princ "bye"))
bye
"bye"
CL-USER> (if (= 1 2)
	     (princ "hej")
	     (princ "bye"))
bye
"bye"
CL-USER> (if (= 1 1)
	     (princ "hej")
	     (princ "bye"))
hej
"hej"
CL-USER>

From: danb
Subject: Re: defun(using mapcar, equal, setf) going wrong...
Date: 
Message-ID: <9f09bfe6-4b6e-4480-a493-034b6c341fea@y21g2000hsf.googlegroups.com>
On May 13, 11:30 pm, globalrev <·········@yahoo.se> wrote:
>   '(phrase)))
> what ami doing wrong here?

Don't quote phrase, and don't put it inside
a list.  phrase is a variable, and its value
should already be a list.

* (defun encrypt (phrase)
    (mapcar (lambda (x)
              (if (equal x "hej")
                  (setf x "right")
                  (setf x "wrong")))
             phrase))
ENCRYPT
* (encrypt '("hej" "foo" "bar"))
("right" "wrong" "wrong")

--Dan

------------------------------------------------
Dan Bensen  http://www.prairienet.org/~dsb/

cl-match:  expressive pattern matching in Lisp
http://common-lisp.net/project/cl-match/
From: Rainer Joswig
Subject: Re: defun(using mapcar, equal, setf) going wrong...
Date: 
Message-ID: <joswig-2ECB34.09202114052008@news-europe.giganews.com>
In article 
<····································@y21g2000hsf.googlegroups.com>,
 danb <·········@gmail.com> wrote:

> On May 13, 11:30 pm, globalrev <·········@yahoo.se> wrote:
> >   '(phrase)))
> > what ami doing wrong here?
> 
> Don't quote phrase, and don't put it inside
> a list.  phrase is a variable, and its value
> should already be a list.
> 
> * (defun encrypt (phrase)
>     (mapcar (lambda (x)
>               (if (equal x "hej")
>                   (setf x "right")
>                   (setf x "wrong")))
>              phrase))
> ENCRYPT
> * (encrypt '("hej" "foo" "bar"))
> ("right" "wrong" "wrong")
> 
> --Dan
> 
> ------------------------------------------------
> Dan Bensen  http://www.prairienet.org/~dsb/
> 
> cl-match:  expressive pattern matching in Lisp
> http://common-lisp.net/project/cl-match/

While we are at it, we should also get rid of the SETFs. They
don't contribute anything useful in this example.

...
  (if (equal x "hej") "right" "wrong")
...

is enough.

-- 
http://lispm.dyndns.org/
From: Mikael Jansson
Subject: Re: defun(using mapcar, equal, setf) going wrong...
Date: 
Message-ID: <3054d112-bb90-46eb-89fd-a537c101ee28@k13g2000hse.googlegroups.com>
On May 14, 6:30 am, globalrev <·········@yahoo.se> wrote:
> (defun encrypt (phrase)
>         (mapcar (lambda (x)
>                 (if (equal x "hej")
>                         (setf x "right")
>                         (setf x "wrong")))
>                                 '(phrase)))
>
By the way, you should use an editor that indents your Lisp code
properly, and moreover, use something better than the REPL
directly. :)

* Lisp-in-a-box w/ Emacs, SBCL and SLIME at http://gigamonkeys.com/book
* Limp for Vim at http://mikael.jansson.be/hacking/limp

Those will give you easier way of communicating with your Lisp
process, with SLIME being the far more feature-complete of the two of
them.

--
Mikael Jansson
http://mikael.jansson.be/
From: Florian Brucker
Subject: Re: defun(using mapcar, equal, setf) going wrong...
Date: 
Message-ID: <482b60ed$0$6508$9b4e6d93@newsspool4.arcor-online.net>
Mikael Jansson wrote:
> * Limp for Vim at http://mikael.jansson.be/hacking/limp

Uhhhhhhh, nice! Thanks for that hint, I was looking for something like 
that, but unsuccessfully. And as you're the author: Thanks (in advance) 
for creating it -- I'm sure I will appreciate every bit of it.


Regards,
Florian
From: Mikael Jansson
Subject: Re: defun(using mapcar, equal, setf) going wrong...
Date: 
Message-ID: <295b135b-0fb4-45c1-9b41-7f38ba5e4aff@i76g2000hsf.googlegroups.com>
On May 15, 1:00 am, Florian Brucker <····@torfbold.com> wrote:
> Mikael Jansson wrote:
> > * Limp for Vim athttp://mikael.jansson.be/hacking/limp
>
> Uhhhhhhh, nice! Thanks for that hint, I was looking for something like
> that, but unsuccessfully. And as you're the author: Thanks (in advance)
> for creating it -- I'm sure I will appreciate every bit of it.
>
Thanks!

Let me know if you have any problems setting it up.  There's also an
issue tracker at http://monostate.net/project/limp

--
Mikael Jansson
http://mikael.jansson.be