[Top][All Lists]

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

Re: How to quote a list of functions?

From: Pascal J. Bourguignon
Subject: Re: How to quote a list of functions?
Date: Tue, 18 Aug 2015 03:43:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Emanuel Berg <address@hidden> writes:

> "Pascal J. Bourguignon" <address@hidden>
> writes:
>> NO! This is the point exactly!
>> upcase-region is NOT a function. It is a symbol that
>> _designates_ a function.
> OK. But this isn't how I think. Is this - 1 - one?
> Or is is a char that designates the digit one?

Well, you better get up to speed, because this is how things are.

    '(#x1 #o1 #b1 1 1.) ; are all different representations of 1!
    --> (1 1 1 1 1)

But in lisp, we often just don't consider the textual representation of
the object, since both the source code and the data are sexps, we
consider rather those lisp objects. 1 is 1, and "#x1" and "1" are two
textual representation of the same object.  In this case, there's no
"number designator".  But you could define such a thing and say for
example that a string containing a representation of a number could
designate a number, and you could define functions taking number

    (defun number-designator-p (object)
       (or (numberp object)
           (numberp (car (read-from-string object)))))

    (list (number-designator-p 42)
          (number-designator-p "42")) --> (t t)

    (defun designated-number (nd)
       (assert (number-designator-p nd))
       (if (numberp nd)
           (car (read-from-string nd))))

    (defun plus (nda ndb)
      (+ (designated-number nda) (designated-number ndb)))

    (plus 1 "42") --> 43

> And, are you suggesting every time a function or
> "function symbol designation" is used, the programmer
> should check the context to determine if what is
> expected is the function, or a symbol designating
> a function?

Yes, you should think about the type of the objects you pass to

To a function that takes a function designator, you can pass a symbol
naming a function, or a function.

To a function that takes a symbol, you can only pass a symbol.

(quote    f) returns  the symbol f.
(function f) returns the function named by f in the lexical scope.

Therefore you cannot pass (function f) to put.

Again, (cl-flet ((f () 'hi)) (put (function f) 'disabled nil))
Debugger entered--Lisp error: (wrong-type-argument symbolp (lambda nil (quote 

> And again, when and why are functions refered to not
> using symbols to designate them?

When you use themselves to refer to themselves.

(let ((f (symbol-function 'sin)))
  (funcall f (/ pi 3))) --> 0.8660254037844386

> Isn't the most natural way to refer to a function (or
> anything else) just to type its name?

No, not in a language that treats functions as first class objects.

> What are we gaining from having people and not
> computers deal with this distinction?

You are gaining that you can manipulate functions, have anonymous
functions, write high order functions, etc.

__Pascal Bourguignon__       
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

reply via email to

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