all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Names to defun, defvar, defconst
@ 2024-07-01 20:14 uzibalqa
  2024-07-01 20:37 ` CToID
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: uzibalqa @ 2024-07-01 20:14 UTC (permalink / raw)
  To: uzibalqa via Users list for the GNU Emacs text editor


Names to defun, defvar, and defconst, can include numbers (digits).  Right?




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Names to defun, defvar, defconst
  2024-07-01 20:14 Names to defun, defvar, defconst uzibalqa
@ 2024-07-01 20:37 ` CToID
       [not found] ` <1914797742.11180.1719865741072@mail.yahoo.com>
  2024-07-01 23:21 ` tpeplt
  2 siblings, 0 replies; 9+ messages in thread
From: CToID @ 2024-07-01 20:37 UTC (permalink / raw)
  To: uzibalqa; +Cc: help-gnu-emacs@gnu.org

> Names to defun, defvar, and defconst, can include numbers (digits).  Right?

As long as there are other non-digit characters in the name, yes.  See the name of the function `1+`.

---

Best,

ID



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Names to defun, defvar, defconst
       [not found]   ` <N-WomROhsQbqycJ7xelPXzdxPQS1v1PljZZaDu0i0G8PGR73Qjrb49DeBX1K7POfXnnwqQT_7bLksXzvgbf4eN1HyWPv82hEW-E9Y7CJbqU=@proton.me>
@ 2024-07-01 20:42     ` CToID
  2024-07-01 21:48       ` uzibalqa
  0 siblings, 1 reply; 9+ messages in thread
From: CToID @ 2024-07-01 20:42 UTC (permalink / raw)
  To: uzibalqa; +Cc: help-gnu-emacs@gnu.org

> So these are all valid names
> 
> (defun func1
> 
> (defvar var2
> 
> (defconst const3

Of course they are, I believe these kind of names are valid in almost every single programming language.

---

Best,

ID



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Names to defun, defvar, defconst
  2024-07-01 20:42     ` CToID
@ 2024-07-01 21:48       ` uzibalqa
  2024-07-01 22:32         ` [External] : " Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: uzibalqa @ 2024-07-01 21:48 UTC (permalink / raw)
  To: CToID; +Cc: help-gnu-emacs@gnu.org

On Monday, July 1st, 2024 at 8:42 PM, CToID <funk443@yahoo.com.tw> wrote:

> > So these are all valid names
> > 
> > (defun func1
> > 
> > (defvar var2
> > 
> > (defconst const3
> 
> 
> Of course they are, I believe these kind of names are valid in almost every single programming language.
> 
> ---
> 
> Best,
> 
> ID

Latex L3 Programming Layer does not allow numbers, and neither underscores or dashes.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [External] : Re: Names to defun, defvar, defconst
  2024-07-01 21:48       ` uzibalqa
@ 2024-07-01 22:32         ` Drew Adams
  2024-07-01 22:41           ` Drew Adams
  2024-07-02  3:34           ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 9+ messages in thread
From: Drew Adams @ 2024-07-01 22:32 UTC (permalink / raw)
  To: uzibalqa, CToID; +Cc: help-gnu-emacs@gnu.org

> > So these are all valid names
> > (defun func1
> > (defvar var2
> > (defconst const3
>
> Of course they are, I believe these kind of names
> are valid in almost every single programming language.

You can use pretty much any chars.  Some chars
(e.g. SPC) you need to escape, with \.  E.g.

 (defun \;not\ a\ comment ()
   (message "A function.")
   42)

This prints "A function." and returns 42:

 (\;not\ a\ comment)

You can't use a keyword name (e.g. `:foo')
with defconst.

You _can_ use a keyword name with defvar, but
it doesn't do anything.  Symbols with keyword
names as their `symbol-name' always evaluate
to themselves.

To me, using defvar with a keyword name should
be a BUG, just as it is with defconst.

(defvar :foo 42 "101010") raises no error, and
evaluating `:foo' as a variable returns `:foo',
not 42, because it's a keyword, i.e., a constant.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [External] : Re: Names to defun, defvar, defconst
  2024-07-01 22:32         ` [External] : " Drew Adams
@ 2024-07-01 22:41           ` Drew Adams
  2024-07-02  3:34           ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2024-07-01 22:41 UTC (permalink / raw)
  To: Drew Adams, uzibalqa, CToID; +Cc: help-gnu-emacs@gnu.org

> You _can_ use a keyword name with defvar, but
> it doesn't do anything.  Symbols with keyword
> names as their `symbol-name' always evaluate
> to themselves.
> 
> To me, using defvar with a keyword name should
> be a BUG, just as it is with defconst.
> 
> (defvar :foo 42 "101010") raises no error, and
> evaluating `:foo' as a variable returns `:foo',
> not 42, because it's a keyword, i.e., a constant.

This bug was fixed in Emacs 28.  Prior to that
what I said was true.  (I still use Emacs 26.)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Names to defun, defvar, defconst
  2024-07-01 20:14 Names to defun, defvar, defconst uzibalqa
  2024-07-01 20:37 ` CToID
       [not found] ` <1914797742.11180.1719865741072@mail.yahoo.com>
@ 2024-07-01 23:21 ` tpeplt
  2 siblings, 0 replies; 9+ messages in thread
From: tpeplt @ 2024-07-01 23:21 UTC (permalink / raw)
  To: uzibalqa; +Cc: uzibalqa via Users list for the GNU Emacs text editor

uzibalqa <uzibalqa@proton.me> writes:

> Names to defun, defvar, and defconst, can include numbers (digits).  Right?

From:

   (info "(elisp) Symbol Type")

   "A symbol name can contain any characters whatever.  Most symbol names
    are written with letters, digits, and the punctuation characters
    ‘-+=*/’.  Such names require no special punctuation; the characters
    of the name suffice as long as the name does not look like a number.
    (If it does, write a ‘\’ at the beginning of the name to force
    interpretation as a symbol.)  The characters ‘_~!@$%^&:<>{}?’ are less
    often used but also require no special punctuation.  Any other
    characters may be included in a symbol's name by escaping them with a
    backslash.  In contrast to its use in strings, however, a backslash in
    the name of a symbol simply quotes the single character that follows the
    backslash."

There is more in that subsection of the chapter on Lisp data types.

-- 
The lyf so short, the craft so long to lerne.
- Geoffrey Chaucer, The Parliament of Birds.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [External] : Re: Names to defun, defvar, defconst
  2024-07-01 22:32         ` [External] : " Drew Adams
  2024-07-01 22:41           ` Drew Adams
@ 2024-07-02  3:34           ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-07-02  3:42             ` Drew Adams
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-07-02  3:34 UTC (permalink / raw)
  To: help-gnu-emacs

> You can't use a keyword name (e.g. `:foo') with defconst.

Except for (defconst :foo :foo)


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [External] : Re: Names to defun, defvar, defconst
  2024-07-02  3:34           ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-07-02  3:42             ` Drew Adams
  0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2024-07-02  3:42 UTC (permalink / raw)
  To: Stefan Monnier, 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'

[-- Attachment #1: Type: text/plain, Size: 135 bytes --]

> > You can't use a keyword name (e.g. `:foo') with defconst.
> 
> Except for (defconst :foo :foo)

Hah!  Indeed.
Thank you. ;-)

[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 14506 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-07-02  3:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-01 20:14 Names to defun, defvar, defconst uzibalqa
2024-07-01 20:37 ` CToID
     [not found] ` <1914797742.11180.1719865741072@mail.yahoo.com>
     [not found]   ` <N-WomROhsQbqycJ7xelPXzdxPQS1v1PljZZaDu0i0G8PGR73Qjrb49DeBX1K7POfXnnwqQT_7bLksXzvgbf4eN1HyWPv82hEW-E9Y7CJbqU=@proton.me>
2024-07-01 20:42     ` CToID
2024-07-01 21:48       ` uzibalqa
2024-07-01 22:32         ` [External] : " Drew Adams
2024-07-01 22:41           ` Drew Adams
2024-07-02  3:34           ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-07-02  3:42             ` Drew Adams
2024-07-01 23:21 ` tpeplt

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.