when should a variable to quoted?
  Home FAQ Contact Sign in
gnu.emacs.help only
 
Advanced search
POPULAR GROUPS

more...

gnu.emacs.help Profile…
 Up
when should a variable to quoted?         


Author: sunway
Date: Sep 13, 2008 02:11

(add-to-list 'll "a")
(delete-dups ll)

The variable "ll" needs be quoted in add-to-list, while not quoted in
delete-dups, why? any special reasons?
4 Comments
Re: when should a variable to quoted?         


Author: Pascal J. Bourguignon
Date: Sep 13, 2008 02:38

sunway gmail.com> writes:
> (add-to-list 'll "a")
> (delete-dups ll)
>
> The variable "ll" needs be quoted in add-to-list, while not quoted in
> delete-dups, why? any special reasons?

Lisp passes its arguments by-value.

Therefore a function cannot modify the variables from which the values
it gets come.

It still can modify the value, when it is mutable, but not the variable.

Usually, when we want to have a variable (or in general, a place)
modified, we have to use a macro, or a special operator.

(setq ll (list 1 2 3)) ; setq is a special operator.
(require 'cl)
(push 0 ll) ; push is a macro

Otherwise, you must take care to get the result and store it back into
the variable:
Show full article (3.21Kb)
no comments
Re: when should a variable to quoted?         


Author: Eli Zaretskii
Date: Sep 13, 2008 03:21

> From: pjb@informatimago.com (Pascal J. Bourguignon)
> Date: Sat, 13 Sep 2008 11:38:18 +0200
>
> (require 'cl)
> (push 0 ll) ; push is a macro

push is indeed a macro, but there's no need to require 'cl anymore,
push is now available in Emacs Lisp.
no comments
Re: when should a variable to quoted?         


Author: sunway
Date: Sep 13, 2008 04:06

"elisp lacks of lexical variable", if this happens to the C
programming language:
int a=10;
foo(a);
may be "a" will be changed to 9 ?

if so, I really hate this feature....

On Sep 13, 5:38 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> sunway gmail.com> writes:
>> (add-to-list 'll "a")
>> (delete-dups ll)
>
>> The variable "ll" needs be quoted...
Show full article (3.74Kb)
no comments
Re: when should a variable to quoted?         


Author: Pascal J. Bourguignon
Date: Sep 13, 2008 05:29

sunway gmail.com> writes:
> "elisp lacks of lexical variable", if this happens to the C
> programming language:
> int a=10;
> foo(a);
> may be "a" will be changed to 9 ?
>
> if so, I really hate this feature....

1- not in C, but in C++ you can have:
void foo(int& v){ v=0; }
void f(){
int a=10;
foo(a);
assert(a==0);
}
Show full article (1.35Kb)
no comments

RELATED THREADS
SubjectArticles qty Group
Re: Heinlein quote "change a diaper"alt.fan.heinlein ·
Quote from "The Village"alt.support.shyness ·