From: Gijs Hillenius
Subject: error in unless
Date: 
Message-ID: <873aq7gwaa.fsf@hillenius.net>
Hello,

I'm a beginner in lisp & programming, which explains why I'm not
seeing the mistake in the following bit of code:

I would like to add this to my .gnus:

(defun audacious-now-playing ()
  "Insert the title of the song I'm currently listening to."
  (let ((track (shell-command-to-string "audtool --current-song")))
    (unless (string-equal "no song playing." track) 
      (save-excursion
	(goto-char (point-min))
	(re-search-forward "^--text follows this line--")
	(forward-line 0)
	(insert "X-Now-Playing: " track)))))

(add-hook 'message-setup-hook 'audacious-now-playing)

The way I adapted this existing bit of code, the unless condition does
not work like intended and I end up with a "X-Now-Playing: No song
playing." x-header in emails.

I would appreciate it if someone could point out what I'm doing
wrong. 

Thx

Gijs






-- 
Homer: Someday you'll thank me for this, son.
Bart:  Not bloody likely.
		-- "Itchy and Scratchy:  The Movie"

From: Ken Tilton
Subject: Re: error in unless
Date: 
Message-ID: <47f0a046$0$15163$607ed4bc@cv.net>
Gijs Hillenius wrote:
> Hello,
> 
> I'm a beginner in lisp & programming, which explains why I'm not
> seeing the mistake in the following bit of code:
> 
> I would like to add this to my .gnus:
> 
> (defun audacious-now-playing ()
>   "Insert the title of the song I'm currently listening to."
>   (let ((track (shell-command-to-string "audtool --current-song")))
>     (unless (string-equal "no song playing." track) 
>       (save-excursion
> 	(goto-char (point-min))
> 	(re-search-forward "^--text follows this line--")
> 	(forward-line 0)
> 	(insert "X-Now-Playing: " track)))))
> 
> (add-hook 'message-setup-hook 'audacious-now-playing)
> 
> The way I adapted this existing bit of code, the unless condition does
> not work like intended and I end up with a "X-Now-Playing: No song
> playing." x-header in emails.
> 
> I would appreciate it if someone could point out what I'm doing
> wrong. 
> 

What I like to do in cases like this is, just before the unless, print 
out both the value of track and then the actual condition copied 
directly from the unless:

    (print `(hunh? ,track ,(string-equal ...etc...)))

I am guessing you'll see a nil after the track value and then you can 
stop worrying about UNLESS and start worrying about your typing or 
something else.

kt

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Ken Tilton
Subject: Re: error in unless
Date: 
Message-ID: <47f0acde$0$25039$607ed4bc@cv.net>
Ken Tilton wrote:
> 
> 
> Gijs Hillenius wrote:
> 
>> Hello,
>>
>> I'm a beginner in lisp & programming, which explains why I'm not
>> seeing the mistake in the following bit of code:
>>
>> I would like to add this to my .gnus:
>>
>> (defun audacious-now-playing ()
>>   "Insert the title of the song I'm currently listening to."
>>   (let ((track (shell-command-to-string "audtool --current-song")))
>>     (unless (string-equal "no song playing." track)       (save-excursion
>>     (goto-char (point-min))
>>     (re-search-forward "^--text follows this line--")
>>     (forward-line 0)
>>     (insert "X-Now-Playing: " track)))))
>>
>> (add-hook 'message-setup-hook 'audacious-now-playing)
>>
>> The way I adapted this existing bit of code, the unless condition does
>> not work like intended and I end up with a "X-Now-Playing: No song
>> playing." x-header in emails.
>>
>> I would appreciate it if someone could point out what I'm doing
>> wrong.
> 
> 
> What I like to do in cases like this is, just before the unless, print 
> out both the value of track and then the actual condition copied 
> directly from the unless:
> 
>    (print `(hunh? ,track ,(string-equal ...etc...)))
> 
> I am guessing you'll see a nil after the track value and then you can 
> stop worrying about UNLESS and start worrying about your typing or 
> something else.


Oh, hang on, UNLESS goes the other way, so I am guessing you see a t 
after the track value.

kt

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Gijs Hillenius
Subject: Re: error in unless
Date: 
Message-ID: <87prtbkyux.fsf@hillenius.net>
> Oh, hang on, UNLESS goes the other way, so I am guessing you see a t
> after the track value.

No, not in my original set up. I get a nil.

I guess my variable 'track' gets canned before it get to the unless
macro. I'm starting anew.

thx


-- 
<Knghtbrd> If I start writing essays about Free Software for slashdot,
           please shoot me.
From: Ken Tilton
Subject: Re: error in unless
Date: 
Message-ID: <47f0b59b$0$25047$607ed4bc@cv.net>
Gijs Hillenius wrote:
>>Oh, hang on, UNLESS goes the other way, so I am guessing you see a t
>>after the track value.
> 
> 
> No, not in my original set up. I get a nil.

heh-heh, I was right the first time.

kt

-- 
http://smuglispweeny.blogspot.com/
http://www.theoryyalgebra.com/

"In the morning, hear the Way;
  in the evening, die content!"
                     -- Confucius
From: Holger Schauer
Subject: Re: error in unless
Date: 
Message-ID: <36n6c5-91f.ln1@ID-153070.user.individual.de>
On Mon, 31 Mar 2008, Gijs Hillenius wrote:
> I would like to add this to my .gnus:

Gnus is an Emacs application, so your query would be more on-topic in
gnu.emacs.help, but anyway:
 
> (defun audacious-now-playing ()
>   "Insert the title of the song I'm currently listening to."
>   (let ((track (shell-command-to-string "audtool --current-song")))
>     (unless (string-equal "no song playing." track) 
> The way I adapted this existing bit of code, the unless condition
> does not work like intended and I end up with a "X-Now-Playing: No
> song playing." x-header in emails.

Apparently "No song playing" is not string-equal to "no song playing".

HTH,

  Holger

-- 
---          http://www.coling.uni-freiburg.de/~schauer/            ---
"Ich glaube ich werde mir demn�chst zwei Hamster besorgen die ich `Drag'
 und `Drop' nenne. Obwohl `Look' und `Feel' auch nicht zu verachten w�re."
                  -- Ralph Angenendt in de.comp.os.unix.linux.misc
From: Gijs Hillenius
Subject: Re: error in unless
Date: 
Message-ID: <87fxu7i4fc.fsf@hillenius.net>
On 31 Mar 2008, Holger Schauer wrote:

> Gnus is an Emacs application, so your query would be more on-topic in
> gnu.emacs.help, but anyway:

I figured I'm having issues with my lisp, not gnus..

> Apparently "No song playing" is not string-equal to "no song playing".

Hm. But I read that string-equal is supposed not to regard case. Or?


-- 
Those lovable Brits department:
	They also have trouble pronouncing `vitamin'.
From: Thomas F. Burdick
Subject: Re: error in unless
Date: 
Message-ID: <fa197a58-36ad-4acb-8496-8f18c88b968f@s13g2000prd.googlegroups.com>
On Mar 31, 12:16 pm, Gijs Hillenius <··············@gmail.com> wrote:
> On 31 Mar 2008, Holger Schauer wrote:
>
> > Gnus is an Emacs application, so your query would be more on-topic in
> > gnu.emacs.help, but anyway:
>
> I figured I'm having issues with my lisp, not gnus..
>
> > Apparently "No song playing" is not string-equal to "no song playing".
>
> Hm. But I read that string-equal is supposed not to regard case. Or?

No, it's case sensitive.  See the elisp manual:
http://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Comparison.html#Text-Comparison

For case-insensitive comparison in Emacs lisp, you want to use compare-
strings, eg, (compare-strings track 0 nil "no song playing" 0 nil t)

As an aside, Elisp can be really ugly as far as Lisps go.
From: Gijs Hillenius
Subject: Re: error in unless
Date: 
Message-ID: <87k5jjdqkx.fsf@hillenius.net>
> No, it's case sensitive.

Ok thanks, (y'all). Meanwhile, the error:
(unless (string-equal "No song playing.\n" track)

is not the same as:

(unless (string-equal "No song playing." track)



-- 
Mate, this parrot wouldn't VOOM if you put four million volts through it!
		-- Monty Python
From: Mark Wooding
Subject: Re: error in unless
Date: 
Message-ID: <slrnfv2oq9.7g2.mdw@metalzone.distorted.org.uk>
Gijs Hillenius <··············@gmail.com> wrote:

> Hm. But I read that string-equal is supposed not to regard case. Or?

True in Common Lisp.  Not true in Emacs Lisp.  Use

  (eq (compare-strings track 0 nil "no track playing." 0 nil t) t)

if you really need a case-insensitive comarison, or just get the case
right.

-- [mdw]
From: Thomas F. Burdick
Subject: Re: error in unless
Date: 
Message-ID: <cbdde8b2-3f1c-450c-ab5b-d97b8c63c246@i7g2000prf.googlegroups.com>
On Apr 1, 12:18 am, Mark Wooding <····@distorted.org.uk> wrote:
> Gijs Hillenius <··············@gmail.com> wrote:
> > Hm. But I read that string-equal is supposed not to regard case. Or?
>
> True in Common Lisp.  Not true in Emacs Lisp.  Use
>
>   (eq (compare-strings track 0 nil "no track playing." 0 nil t) t)
>
> if you really need a case-insensitive comarison, or just get the case
> right.

For any non-Elisping Common Lispers looking on, note that (eq (c-
s ...) t) is correct and non-redundant here.  Anyone care to horror[*]
a guess as to why?

[*] like hazarding a guess, but more horrible.



... spoiler ahead ...










(apparently one of the reasons rms steared clear of CL for Emacs was
because keywords and multiple values are somehow "wrong", which really
boggles the mind when presented the alternative)