all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Dude where is my car ?
@ 2012-05-25 22:59 Philippe M. Coatmeur
  2012-05-26  2:51 ` Eric Abrahamsen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Philippe M. Coatmeur @ 2012-05-25 22:59 UTC (permalink / raw
  To: help-gnu-emacs

Hi everyone ;

I have this function that loops trough a list of lists of email
elements to extract them. The list looks like this :

(("<test@adamweb.net>" "Fri, 25 May 2012 23:49:58 +0200" "Re: plopz" "1648")
 ("contact <plop@gmail.com>" "Fri, 25 May 2012 22:21:49 +0000" "tst" "1647"))

(This is what you get if you C-h v with point over mail-bug-unseen-mails-one)

(defun mail-bug-desktop-notify-one ()
  (mapcar
   (lambda (x)
     (if (not (member x mail-bug-advertised-mails-one))
	 (progn
	   (mail-bug-desktop-notification
	    "Mew mail!"
	    (format "%s %s %s"           ;; Produces the values below
		    (car (nthcdr 1 x))   ;; Fri, 25 May 2012 23:49:58 +0200
		    (car (nthcdr 2 x))   ;; Re: plopz
		    (car (nthcdr 3 x)))  ;; 1648
	    "500000" mail-bug-new-mail-icon-one)
	   (add-to-list 'mail-bug-advertised-mails-one x))))
   mail-bug-unseen-mails-one))

And this works fine, so it follows that (car (car x)) is the first
element of each atomic list, right ? but when I try to extract it
emacs (24.1.50 cvs) insults me!? I spent more than a good hour trying
to figure this out

(format "%s %s %s"
 (car (car x))        ;; Should produce <test@adamweb.net>
 (car (nthcdr 2 x))   ;; Re: encor un autre
 (car (nthcdr 3 x)))  ;; 1643

error in process sentinel: format: Wrong type argument: listp, "<test@adamweb.net>"
error in process sentinel: Wrong type argument: listp, "<test@adamweb.net>"

(How am I supposed to interpret this first error ? Does format really
expect a list?) What is it that I'm doing wrong ? Where is my car?

Phil


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dude where is my car ?
  2012-05-25 22:59 Dude where is my car ? Philippe M. Coatmeur
@ 2012-05-26  2:51 ` Eric Abrahamsen
  2012-05-26 14:04 ` Stefan Monnier
       [not found] ` <mailman.1688.1338000714.855.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Abrahamsen @ 2012-05-26  2:51 UTC (permalink / raw
  To: help-gnu-emacs

On Sat, May 26 2012, Philippe M. Coatmeur wrote:

> Hi everyone ;
>
> I have this function that loops trough a list of lists of email
> elements to extract them. The list looks like this :
>
> (("<test@adamweb.net>" "Fri, 25 May 2012 23:49:58 +0200" "Re: plopz" "1648")
>  ("contact <plop@gmail.com>" "Fri, 25 May 2012 22:21:49 +0000" "tst" "1647"))
>
> (This is what you get if you C-h v with point over mail-bug-unseen-mails-one)
>
> (defun mail-bug-desktop-notify-one ()
>   (mapcar
>    (lambda (x)
>      (if (not (member x mail-bug-advertised-mails-one))
> 	 (progn
> 	   (mail-bug-desktop-notification
> 	    "Mew mail!"
> 	    (format "%s %s %s"           ;; Produces the values below
> 		    (car (nthcdr 1 x))   ;; Fri, 25 May 2012 23:49:58 +0200
> 		    (car (nthcdr 2 x))   ;; Re: plopz
> 		    (car (nthcdr 3 x)))  ;; 1648
> 	    "500000" mail-bug-new-mail-icon-one)
> 	   (add-to-list 'mail-bug-advertised-mails-one x))))
>    mail-bug-unseen-mails-one))
>
> And this works fine, so it follows that (car (car x)) is the first
> element of each atomic list, right ? but when I try to extract it
> emacs (24.1.50 cvs) insults me!? I spent more than a good hour trying
> to figure this out
>
> (format "%s %s %s"
>  (car (car x))        ;; Should produce <test@adamweb.net>
>  (car (nthcdr 2 x))   ;; Re: encor un autre
>  (car (nthcdr 3 x)))  ;; 1643
>
> error in process sentinel: format: Wrong type argument: listp, "<test@adamweb.net>"
> error in process sentinel: Wrong type argument: listp, "<test@adamweb.net>"

Since x equals ("<test@adamweb.net>" "Fri, 25 May 2012 23:49:58 +0200"
"Re: plopz" "1648") in your second example, the car of that is
"<test@adamweb.net>", and you can't take the car of that again, because
it fails to pass the listp test. I think where you're going wrong is
that nthcdr returns a list, so you can car it. Car itself returns an
atom, so you can't.

Have I got that right?

Also, the whole thing might be easier to read/debug if you use "first"
"second" "third" "fourth" to extract the list elements. Or, if that
seems too unscientific, then "nth", that also pulls a single element out
of a list.

Eric

-- 
GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.10)
 of 2012-05-25 on pellet




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dude where is my car ?
  2012-05-25 22:59 Dude where is my car ? Philippe M. Coatmeur
  2012-05-26  2:51 ` Eric Abrahamsen
@ 2012-05-26 14:04 ` Stefan Monnier
       [not found] ` <mailman.1688.1338000714.855.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2012-05-26 14:04 UTC (permalink / raw
  To: help-gnu-emacs

> 		    (car (nthcdr 1 x))   ;; Fri, 25 May 2012 23:49:58 +0200
> 		    (car (nthcdr 2 x))   ;; Re: plopz
> 		    (car (nthcdr 3 x)))  ;; 1648

Aka:
	    (nth 1 x)   ;; Fri, 25 May 2012 23:49:58 +0200
	    (nth 2 x)   ;; Re: plopz
	    (nth 3 x))  ;; 1648

-- Stefan


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Dude where is my car ?
       [not found] ` <mailman.1688.1338000714.855.help-gnu-emacs@gnu.org>
@ 2012-05-26 19:00   ` Philippe M. Coatmeur
  0 siblings, 0 replies; 4+ messages in thread
From: Philippe M. Coatmeur @ 2012-05-26 19:00 UTC (permalink / raw
  To: help-gnu-emacs

At Sat, 26 May 2012 10:51:26 +0800,
Eric Abrahamsen wrote:
> Since x equals ("<test@adamweb.net>" "Fri, 25 May 2012 23:49:58 +0200"
> "Re: plopz" "1648") in your second example, the car of that is
> "<test@adamweb.net>", and you can't take the car of that again, because
> it fails to pass the listp test. I think where you're going wrong is
> that nthcdr returns a list, so you can car it. Car itself returns an
> atom, so you can't.
> 
> Have I got that right?
> 
> Also, the whole thing might be easier to read/debug if you use "first"
> "second" "third" "fourth" to extract the list elements. Or, if that
> seems too unscientific, then "nth", that also pulls a single element out
> of a list.
> 
> Eric

I did now know of those "first, second, etc" things, thanks. Turns out
I had to send the vars as such and then do the format at the last
stage of the text processing, witch makes sense. Thanks for your
patience.

Philippe

> 
> -- 
> GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.10)
>  of 2012-05-25 on pellet
> 
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-05-26 19:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-25 22:59 Dude where is my car ? Philippe M. Coatmeur
2012-05-26  2:51 ` Eric Abrahamsen
2012-05-26 14:04 ` Stefan Monnier
     [not found] ` <mailman.1688.1338000714.855.help-gnu-emacs@gnu.org>
2012-05-26 19:00   ` Philippe M. Coatmeur

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.