all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Creating a list
Date: Thu, 19 Nov 2009 14:59:38 +0100	[thread overview]
Message-ID: <873a4aipit.fsf@galatea.local> (raw)
In-Reply-To: 873a4afyi0.fsf@Traian.DecebalComp

Cecil Westerhof <Cecil@decebal.nl> writes:

> David Kastrup <dak@gnu.org> writes:
>
>>>>> At the moment I create a list with:
>>>>>       (setq ret-val (cons total-amount (cons current-amount ())))
>>>>> I thought about doing it with:
>>>>>       (setq ret-val (cons total-amount '(current-amount)))
>>>>>
>>>>> But then the second value is the string current-amount
>>>>
>>>> Wrong.  The _symbol_ current-amount.
>>>
>>> When evaluating I got:
>>>     (1570378.2570192777 current-amount)
>>> That is why I thought I got the string.
>>
>> A string would have quote marks around it.
>
> Off course.
>
> But I have a few questions on my mind.
> - Why is the first shown as value and the second as _symbol_?

Both floating point numbers and symbols ARE VALUES!

The first object is a floating point number, the second object is a
symbol.  Therefore it shows a floating point number and a symbol.


The rules of evaluation of lisp include:

(defun eval (expression)
   (cond
     ((symbolp expression)  (symbol-value expression)) ; symbols evaluate to their value
     ((atom expression)     expression))               ; atoms are self evaluating
     (t  (case (first expression)
           ((quote)  (second expression))              ; (quote x) returns x unchanged.
           ; ... other special operators
           (else
              (cond
                 ((and (listp (first expression))
                       (eq 'lambda (first (first expression))))
                    ;; ... process ((lambda (...) ...) ...)
                    )
                 ((macro-function (first expression))
                    ;; ... expand the macro call
                    )
                 ((and (symbolp (first expression)) (fboundp (first expression)))
                   (apply (symbol-function (first expression))
                          (mapcar (function eval) (rest expression)) ; evaluate the arguments
                          )))))))


When you evaluate  (cons current-amount ()), since cons is a symbol
that is fbound, the arguments are evaluated:
    since current-amount is a symbol, its symbol-value is returned.
    since () is a symbol, its symbol-value is returned (it's nil).
    the function  #<subr cons> is called with the above values.

When you evalute (quote (current-value)), the list (current-value) is
returned. The evaluation doesn't even look at what's inside the list!



> - current-amount is a local variable. How is it possible that the symbol
>   is still defined?

You exist.  How is it possible your name still exists?


-- 
__Pascal Bourguignon__


  parent reply	other threads:[~2009-11-19 13:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-19  7:38 Creating a list Cecil Westerhof
2009-11-19  8:35 ` David Kastrup
2009-11-19 10:59   ` Cecil Westerhof
2009-11-19 11:41     ` David Kastrup
2009-11-19 13:13       ` Cecil Westerhof
2009-11-19 13:47         ` Barry Margolin
2009-11-19 15:11           ` Cecil Westerhof
2009-11-19 19:26             ` Pascal J. Bourguignon
2009-11-19 13:57         ` David Kastrup
2009-11-19 15:14           ` Cecil Westerhof
2009-11-19 13:59         ` Pascal J. Bourguignon [this message]
2009-11-19 11:59   ` Gnus: Some new mails are automatically marked as 'O' Wang Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873a4aipit.fsf@galatea.local \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.