[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Supplying DOC string in a `defun' using `defvar'
From: |
Jean Louis |
Subject: |
Re: Supplying DOC string in a `defun' using `defvar' |
Date: |
Tue, 1 Jun 2021 03:35:40 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* Jean Louis <bugs@gnu.support> [2021-06-01 03:28]:
> * 2QdxY4RzWzUUiLuE@potatochowder.com <2QdxY4RzWzUUiLuE@potatochowder.com>
> [2021-06-01 03:15]:
> > > It did not work, but I think it should.
> >
> > Consider the following:
> >
> > (defvar *string* "hello, world")
> > (defun foo ()
> > *string*)
> >
> > What would foo return? What would its doc string be?
>
> That one did not work, it was demonstration that it does not work.
>
> And here again the solution which does work:
>
> (defvar my-doc "Hello there")
>
> (defmacro my-fun ()
> `(defun my-fun ()
> ,my-doc
> (ignore)))
>
> To define function run: (my-fun) ⇒ my-fun
>
> (documentation 'my-fun) ⇒ "Hello there"
>
> Funny, as to define the function one defines macro that
> overwrites itself by the function calling the macro first time.
Now I wonder could it be all written this way:
;; -*- lexical-binding: t; -*-
(defvar my-doc "Hello there again2")
(let ()
(defmacro my-fun ()
`(defun my-fun ()
,my-doc
(ignore)))
(my-fun))
;; (documentation 'my-fun) ⇒ "Hello there again2"
So it works that way even with lexical-binding: t
But that is, while funny, not practical and not elegant, Drew's
solution is there, did you read it?
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
- Supplying DOC string in a `defun' using `defvar', ludvig-faddeev, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar', 2QdxY4RzWzUUiLuE, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar', Jean Louis, 2021/05/31
- Supplying DOC string in a `defun' using `defvar', ludvig-faddeev, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar', 2QdxY4RzWzUUiLuE, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar', Jean Louis, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar',
Jean Louis <=
- Re: Supplying DOC string in a `defun' using `defvar', Michael Heerdegen, 2021/05/31
- Supplying DOC string in a `defun' using `defvar', ludvig-faddeev, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar', Jean Louis, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar', Michael Heerdegen, 2021/05/31
- Re: Supplying DOC string in a `defun' using `defvar', Jean Louis, 2021/05/31
Re: Supplying DOC string in a `defun' using `defvar', Stefan Monnier, 2021/05/31
RE: [External] : Supplying DOC string in a `defun' using `defvar', Drew Adams, 2021/05/31