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

[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:23:10 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-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.


-- 
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/



reply via email to

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