help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a list


From: Pascal J. Bourguignon
Subject: Re: Creating a list
Date: Thu, 19 Nov 2009 14:59:38 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Cecil Westerhof <address@hidden> writes:

> David Kastrup <address@hidden> 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__


reply via email to

[Prev in Thread] Current Thread [Next in Thread]