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

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

Re: Calling a function with undefined symbol


From: tomas
Subject: Re: Calling a function with undefined symbol
Date: Mon, 31 Oct 2022 09:42:53 +0100

On Mon, Oct 31, 2022 at 08:15:32AM +0000, Heime wrote:
> 
> Have written a function named "mbcomplt" that takes a symbol.

The function takes an argument, that's what it does.

> (defun mbcomplt (sgnl)
>   "DOC."

sgnl here is a variable. Or a variable name. Depending on how
you look at it.

> (if (eq sgnl 'go)
>     (message "go")
>   (message "nogo")))

Now you are comparing sgnl's /value/ to something (which happens
to be a symbol).

> I can call this function with
> 
> (mbcomplt 'go)

Yes. You could call it also with (mbcomplt 23). Or (mbcomplt "This is not a 
pipe").
So?

> This even though the symbol "'go" does not exist.  What is happening here?

As soon as you do 'go, the symbol exists.

> My understanding about symbols is that I can make a symbol using
> 
> (defvar seqr 3)  ; set symbol seqr with value 3

No, no. You are making a variable. Which is a binding of a symbol
to a value.

> (setq seqr 5)    ; set symbol seqr with value 5

No, you set the variable's value to 5. The symbol is not "set" to
anything. It is an immutable thing, as far as Lisp is concerned.

The symbol 'seqr is just taking the job of variable name here.
Like you are called Heime (or whatever it is this week). That
name is not you.

> (symbol-value 'seqr) ; get value of symbol (returns 5)
> (symbol-name 'seqr)  ; get name of symbol (returns "seqr")

Symbol-value returns the value associated to the symbol. The
association itself is called a "variable".

Please go re-read the manuals. You have got all of it confused :)

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


reply via email to

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