(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>
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/
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/
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/
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
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