From: Thaddeus L Olczyk
Subject: Stupid question: how do you create a list with a variable at the begining?
Date: 
Message-ID: <3aa3bcb5.410038781@nntp.interaccess.com>
While working on a emacs function, I got stuck in a part.
Since it is a purely lisp  question I thought I would ask
here.
The basic question is how do you create a list whose first element
is am argument of the function that holds the list.

I wrote this function:

(defun make-new-comment (mode color1 color2)
  (font-lock-add-keywords
   mode
   '(("\\(FIXME\\)" 1 'font-lock-fixme-face)))
  (modify-face 'font-lock-fixme-face color1 color2 nil t nil t nil
nil)
)

and it has some bugs, but it basically works.

When  I tried to replace the function with this:
(defun make-new-comment (commentstr mode color1 color2)
  (font-lock-add-keywords
   mode
   '((commentstr 1 'font-lock-fixme-face)))
  (modify-face 'font-lock-fixme-face color1 color2 nil t nil t nil
nil)
)

I can't get this function to execute because it keeps think commentstr
is a function. No matter what I do, I have not been able to find a way
to convince it otherwise.
I've tried quoting and backquoting commentstr,  quoting the list, etc.
I've even tried replacing the line with

   '((cdr ("" commentstr 1 'font-lock-fixme-face))))

and other variations on that theme to no avail.
Can someone help?

From: Johann Hibschman
Subject: Re: Stupid question: how do you create a list with a variable at the begining?
Date: 
Message-ID: <mtwva4kt2t.fsf@astron.berkeley.edu>
Thaddeus L Olczyk writes:

> While working on a emacs function, I got stuck in a part.
> Since it is a purely lisp  question I thought I would ask
> here.
> The basic question is how do you create a list whose first element
> is am argument of the function that holds the list.

Yes!  An easy question!  I can answer those!

There are two ways: the "list" function and backquote-with-comma.

(let ((comment "string"))
  (list comment 'a 'b 'c))
=> '("string" a b c)

List is a function that evaluates all of its arguments (so symbols
need quotes) and collects them in a list.

(let ((comment "string"))
  `(,comment 'a 'b 'c))
=> '("string" a b c)

Inside a backquote, prefacing an expression with a "," means that it
will be evaluated and the result interpolated into the list at that
point.

You may want to check one of the emacs newsgroups, such as comp.emacs,
in the future.

-- 
Johann Hibschman                           ······@physics.berkeley.edu
From: Johann Hibschman
Subject: Re: Stupid question: how do you create a list with a variable at the begining?
Date: 
Message-ID: <mtsnksksze.fsf@astron.berkeley.edu>
Johann Hibschman writes:

> (let ((comment "string"))
>   `(,comment 'a 'b 'c))
> => '("string" a b c)

That's what I get for cutting and pasting quickly.  This should be:

(let ((comment "string"))
  `(,comment a b c))
=> '("string" a b c)


-- 
Johann Hibschman                           ······@physics.berkeley.edu
From: Janis Dzerins
Subject: Re: Stupid question: how do you create a list with a variable at the begining?
Date: 
Message-ID: <87zof0m7bw.fsf@asaka.latnet.lv>
Johann Hibschman <······@physics.berkeley.edu> writes:

> Johann Hibschman writes:
> 
> > (let ((comment "string"))
> >   `(,comment 'a 'b 'c))
> > => '("string" a b c)
> 
> That's what I get for cutting and pasting quickly.  This should be:
> 
> (let ((comment "string"))
>   `(,comment a b c))
> => '("string" a b c)

And that should be:

(let ((comment "string"))
  `(,comment a b c))
=> ("string" a b c)

(no quote before result).

-- 
Janis Dzerins

  If million people say a stupid thing it's still a stupid thing.
From: Pierre R. Mai
Subject: Re: Stupid question: how do you create a list with a variable at the begining?
Date: 
Message-ID: <8766houm1m.fsf@orion.bln.pmsf.de>
······@interaccess.com (Thaddeus L Olczyk) writes:

> The basic question is how do you create a list whose first element
> is am argument of the function that holds the list.

Or put another way:  How do I create lists at run-time, instead of
just using quoted literals.  The possible answers include

- Use list:

(defun silly-function (argument1 argument2)
  (list argument1 'symbol 42 argument2))

(silly-function 5 'strange)

=> (5 symbol 42 strange)

- If the lists you create contain much that is constant and especially
  if they are deeply nested, you might want to using the backquote
  mechanism instead:

(defun silly-function2 (argument1 argument2)
  `((,argument1 'symbol 42 ,argument2)))

(silly-function2 5 'strange)

=> ((5 symbol 42 strange))

Regs, Pierre.

-- 
Pierre R. Mai <····@acm.org>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein