* basic help evaluating function in an alist
@ 2012-12-01 22:57 Matt Price
2012-12-01 23:12 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Matt Price @ 2012-12-01 22:57 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
i'm trying to figure out what's wrong with this simple code:
(add-to-list 'my-winlist
'(guide . (selected-window) )
)
(windmove-right)
(select-window(cdr(assoc 'guide my-winlist)) )
So, what I would hope happens here is that I add an element (guide .
(selected-window)) to an alist, but that the second element would be
the actual window object in question, not the text string
"(selected-window)". Lisp puzzles me pretty thoroughly so I know I'm
missing a very basic feature, but I can't figure it out by flipping
through the info pages... Thanks everyone!
Matt
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: basic help evaluating function in an alist
2012-12-01 22:57 basic help evaluating function in an alist Matt Price
@ 2012-12-01 23:12 ` Drew Adams
2012-12-02 2:40 ` Matt Price
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2012-12-01 23:12 UTC (permalink / raw)
To: 'Matt Price', help-gnu-emacs
> i'm trying to figure out what's wrong with this simple code:
> (add-to-list 'my-winlist
> '(guide . (selected-window)))
> (windmove-right)
> (select-window(cdr(assoc 'guide my-winlist)) )
Break it down. Forget about `windmove-right'. Just check the value of
`my-winlist' after you added the element.
(setq my-winlist ())
(add-to-list 'my-winlist
'(guide . (selected-window)))
`C-h v my-winlist' shows:
((guide selected-window))
That's the same as ((guide . (selected-window)))
Already you can see the problem: no window, just a list with the symbol
`selected-window' as its sole element.
If you want, try `M-: (cdr (assoc 'guide my-winlist))', to see that element:
(selected-window).
You need to evaluate `(selected-window)', not just use that list as the cdr of
your element. Here's what you need:
(setq my-winlist ())
(add-to-list 'my-winlist
(cons 'guide (selected-window)))
`C-h v my-winlist' shows a list with one element, which is a dotted pair (aka
cons cell), whose cdr is a window:
((guide . #<window 84 on *scratch*>))
With backquote syntax you can express the same thing this way:
(setq my-winlist ())
(add-to-list 'my-winlist
`(guide ,(selected-window)))
I recommend that you read this manual that comes with Emacs (use `C-h i'):
`Emacs Lisp Intro'. HTH.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: basic help evaluating function in an alist
[not found] <mailman.14266.1354402640.855.help-gnu-emacs@gnu.org>
@ 2012-12-01 23:12 ` WJ
2012-12-02 1:06 ` WJ
0 siblings, 1 reply; 7+ messages in thread
From: WJ @ 2012-12-01 23:12 UTC (permalink / raw)
To: help-gnu-emacs
Matt Price wrote:
> Hi,
>
> i'm trying to figure out what's wrong with this simple code:
>
> (add-to-list 'my-winlist
> '(guide . (selected-window) )
> )
> (windmove-right)
> (select-window(cdr(assoc 'guide my-winlist)) )
>
> So, what I would hope happens here is that I add an element (guide .
> (selected-window)) to an alist, but that the second element would be
> the actual window object in question, not the text string
> "(selected-window)". Lisp puzzles me pretty thoroughly so I know I'm
> missing a very basic feature, but I can't figure it out by flipping
> through the info pages... Thanks everyone!
> Matt
: (setq mylist '((b . 2)))
((b . 2))
: (add-to-list 'mylist (cons 'c (sqrt 3)))
((c . 1.7320508075688772) (b . 2))
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: basic help evaluating function in an alist
2012-12-01 23:12 ` WJ
@ 2012-12-02 1:06 ` WJ
0 siblings, 0 replies; 7+ messages in thread
From: WJ @ 2012-12-02 1:06 UTC (permalink / raw)
To: help-gnu-emacs
WJ wrote:
> Matt Price wrote:
>
> > Hi,
> >
> > i'm trying to figure out what's wrong with this simple code:
> >
> > (add-to-list 'my-winlist
> > '(guide . (selected-window) )
> > )
> > (windmove-right)
> > (select-window(cdr(assoc 'guide my-winlist)) )
> >
> > So, what I would hope happens here is that I add an element (guide .
> > (selected-window)) to an alist, but that the second element would be
> > the actual window object in question, not the text string
> > "(selected-window)". Lisp puzzles me pretty thoroughly so I know I'm
> > missing a very basic feature, but I can't figure it out by flipping
> > through the info pages... Thanks everyone!
> > Matt
>
> : (setq mylist '((b . 2)))
> ((b . 2))
> : (add-to-list 'mylist (cons 'c (sqrt 3)))
> ((c . 1.7320508075688772) (b . 2))
Another way:
: (require 'cl)
cl
: (setq mylist '((b . 2)))
((b . 2))
: (setq mylist (acons 'c (sqrt 3) mylist))
((c . 1.7320508075688772) (b . 2))
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: basic help evaluating function in an alist
2012-12-01 23:12 ` Drew Adams
@ 2012-12-02 2:40 ` Matt Price
2012-12-02 3:44 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Matt Price @ 2012-12-02 2:40 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
On Sat, Dec 1, 2012 at 6:12 PM, Drew Adams <drew.adams@oracle.com> wrote:
>> i'm trying to figure out what's wrong with this simple code:
>> (add-to-list 'my-winlist
>> '(guide . (selected-window)))
>> (windmove-right)
>> (select-window(cdr(assoc 'guide my-winlist)) )
>
> Break it down. Forget about `windmove-right'. Just check the value of
> `my-winlist' after you added the element.
>
> (setq my-winlist ())
> (add-to-list 'my-winlist
> '(guide . (selected-window)))
>
> `C-h v my-winlist' shows:
>
> ((guide selected-window))
>
> That's the same as ((guide . (selected-window)))
>
> Already you can see the problem: no window, just a list with the symbol
> `selected-window' as its sole element.
>
> If you want, try `M-: (cdr (assoc 'guide my-winlist))', to see that element:
> (selected-window).
>
> You need to evaluate `(selected-window)', not just use that list as the cdr of
> your element. Here's what you need:
>
> (setq my-winlist ())
> (add-to-list 'my-winlist
> (cons 'guide (selected-window)))
>
> `C-h v my-winlist' shows a list with one element, which is a dotted pair (aka
> cons cell), whose cdr is a window:
>
> ((guide . #<window 84 on *scratch*>))
>
> With backquote syntax you can express the same thing this way:
>
> (setq my-winlist ())
> (add-to-list 'my-winlist
> `(guide ,(selected-window)))
>
> I recommend that you read this manual that comes with Emacs (use `C-h i'):
> `Emacs Lisp Intro'. HTH.
>
that helps a lot. I still don't quite understand what it is in the
syntax that causes the function (selected-window) to be evaluated in
one case and not the other, but I'll try to wrap my head around the
manual a little better thanks to both of you!
matt
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: basic help evaluating function in an alist
2012-12-02 2:40 ` Matt Price
@ 2012-12-02 3:44 ` Drew Adams
2012-12-04 14:41 ` Matt Price
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2012-12-02 3:44 UTC (permalink / raw)
To: 'Matt Price'; +Cc: help-gnu-emacs
> > '(guide . (selected-window))
> >
> > (cons 'guide (selected-window))
>
> I still don't quite understand what it is in the
> syntax that causes the function (selected-window) to be evaluated in
> one case and not the other
In the first case, the dotted pair `(guide . (selected-window))' is quoted.
When evaluated, the sexp `(quote (guide . (selected-window)))' returns that
dotted pair: `(guide . (selected-window))'. `quote' returns its argument
without evaluating it.
In the second case, the sexp `(cons 'guide (selected-window))' is evaluated,
which means applying function `cons' to its two arguments, after evaluating each
of them.
Evaluation of the first argument, which is `(quote guide)', returns the symbol
`guide'. Evaluation of the second arg, `(selected-window)', returns the
selected window. Function `cons' then creates a cons cell whose car is the
symbol `guide' and whose cdr is that window.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: basic help evaluating function in an alist
2012-12-02 3:44 ` Drew Adams
@ 2012-12-04 14:41 ` Matt Price
0 siblings, 0 replies; 7+ messages in thread
From: Matt Price @ 2012-12-04 14:41 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
On Sat, Dec 1, 2012 at 10:44 PM, Drew Adams <drew.adams@oracle.com> wrote:
>> > '(guide . (selected-window))
>> >
>> > (cons 'guide (selected-window))
>>
>> I still don't quite understand what it is in the
>> syntax that causes the function (selected-window) to be evaluated in
>> one case and not the other
>
> In the first case, the dotted pair `(guide . (selected-window))' is quoted.
> When evaluated, the sexp `(quote (guide . (selected-window)))' returns that
> dotted pair: `(guide . (selected-window))'. `quote' returns its argument
> without evaluating it.
>
> In the second case, the sexp `(cons 'guide (selected-window))' is evaluated,
> which means applying function `cons' to its two arguments, after evaluating each
> of them.
>
> Evaluation of the first argument, which is `(quote guide)', returns the symbol
> `guide'. Evaluation of the second arg, `(selected-window)', returns the
> selected window. Function `cons' then creates a cons cell whose car is the
> symbol `guide' and whose cdr is that window.
>
Drew, I forgot to write and say thank you. this was a big help.
matt
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-12-04 14:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-01 22:57 basic help evaluating function in an alist Matt Price
2012-12-01 23:12 ` Drew Adams
2012-12-02 2:40 ` Matt Price
2012-12-02 3:44 ` Drew Adams
2012-12-04 14:41 ` Matt Price
[not found] <mailman.14266.1354402640.855.help-gnu-emacs@gnu.org>
2012-12-01 23:12 ` WJ
2012-12-02 1:06 ` WJ
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).