Lisp HUG Maillist Archive

documentation strings on lambda expressions

Hello all,

I read in the HyperSpec about lambda:

"Syntax: lambda lambda-list [[declaration* | documentation]] form*
Arguments: ... documentation---a string; not evaluated. ...
Description: ... Documentation is attached to the denoted function (if
any is actually created) as a documentation string."

I'm wondering how to retrieve the docstring though, as
(documentation ... 'function) doesn't seem to do it:

CL-USER 1 >
(defun inc-defun (x)
  "Add one to x."
  (1+ x))
Inc-Defun

CL-USER 2 > (documentation #'inc-defun 'function)
"Add one to x." ;; documentation

CL-USER 3 >
(defparameter *inc-defparameter*
  #'(lambda (x)
      "Add one to x."
      (1+ x)))
*Inc-Defparameter*

CL-USER 4 > (documentation *inc-defparameter* 'function)
Nil ;; no documentation?

Any thoughts? Suggestions? Thanks in advance!

-- 
=====================
Joshua Taylor
tayloj@rpi.edu

"A lot of good things went down one time,
     back in the goodle days."
               John Hartford


Re: documentation strings on lambda expressions

On 9/26/07, Taylor, Joshua <tayloj@cs.rpi.edu> wrote:
> Hello all,
>
> I read in the HyperSpec about lambda:
>
> "Syntax: lambda lambda-list [[declaration* | documentation]] form*
> Arguments: ... documentation---a string; not evaluated. ...
> Description: ... Documentation is attached to the denoted function (if
> any is actually created) as a documentation string."
>
> I'm wondering how to retrieve the docstring though, as
> (documentation ... 'function) doesn't seem to do it:
>
> CL-USER 1 >
> (defun inc-defun (x)
>   "Add one to x."
>   (1+ x))
> Inc-Defun
>
> CL-USER 2 > (documentation #'inc-defun 'function)
> "Add one to x." ;; documentation
>
> CL-USER 3 >
> (defparameter *inc-defparameter*
>   #'(lambda (x)
>       "Add one to x."
>       (1+ x)))
> *Inc-Defparameter*
>
> CL-USER 4 > (documentation *inc-defparameter* 'function)
> Nil ;; no documentation?
>
> Any thoughts? Suggestions? Thanks in advance!
>

Also, I'm currently on LWL5.0
-- 
=====================
Joshua Taylor
tayloj@rpi.edu

"A lot of good things went down one time,
     back in the goodle days."
               John Hartford


Re: documentation strings on lambda expressions

> On Wed, 26 Sep 2007 21:58:42 +0100, Taylor, Joshua <tayloj@cs.rpi.edu>
> wrote:
>
> >
> > On 9/26/07, Taylor, Joshua <tayloj@cs.rpi.edu> wrote:
> >> Hello all,
> >>
> >> I read in the HyperSpec about lambda:
> >>
> >> "Syntax: lambda lambda-list [[declaration* | documentation]] form*
> >> Arguments: ... documentation---a string; not evaluated. ...
> >> Description: ... Documentation is attached to the denoted function (if
> >> any is actually created) as a documentation string."
> >>
> >> I'm wondering how to retrieve the docstring though, as
> >> (documentation ... 'function) doesn't seem to do it:
> >>
> >> CL-USER 1 >
> >> (defun inc-defun (x)
> >>   "Add one to x."
> >>   (1+ x))
> >> Inc-Defun
> >>
> >> CL-USER 2 > (documentation #'inc-defun 'function)
> >> "Add one to x." ;; documentation
> >>
> >> CL-USER 3 >
> >> (defparameter *inc-defparameter*
> >>   #'(lambda (x)
> >>       "Add one to x."
> >>       (1+ x)))
> >> *Inc-Defparameter*
> >>
> >> CL-USER 4 > (documentation *inc-defparameter* 'function)
> >> Nil ;; no documentation?
> >>
> >> Any thoughts? Suggestions? Thanks in advance!
> >>
> >
> > Also, I'm currently on LWL5.0
>
On 9/26/07, Yury Davidouski <dcu-stuff@list.ru> wrote:
> Hi Joshua,
>
> it says "Documentation is attached to the denoted function (if any is
> actually created) as a documentation string." but it is obvious that there
> is no documentation present so I guess in LW we just have the case where
> it is not created.

I did notice that phrase, but I'd think that the location of the
parenthetical meant "if any [function] is created". (Though that
doesn't make too much sense to me either, unless it's a distinction
between compiled and interpreted code, perhaps?)

-- 
=====================
Joshua Taylor
tayloj@rpi.edu

"A lot of good things went down one time,
     back in the goodle days."
               John Hartford


Re: documentation strings on lambda expressions

On 9/26/07, John Thingstad <john.thingstad@chello.no> wrote:
> På Wed, 26 Sep 2007 22:48:09 +0200, skrev Taylor, Joshua
> <tayloj@cs.rpi.edu>:
>
> > CL-USER 3 >
> > (defparameter *inc-defparameter*
> >   #'(lambda (x)
> >       "Add one to x."
> >       (1+ x)))
> > *Inc-Defparameter*
> >
> > CL-USER 4 > (documentation *inc-defparameter* 'function)
> > Nil ;; no documentation?
> >
> > Any thoughts? Suggestions? Thanks in advance!
> >
>
> defparameter also has a documentation field.
>
> With the the original..
> (documentation '*inc-defparameter* 'variable)
> "Add one to x."
>
> or just write
>
> (defparameter *inc-parameter*
>     (lambda (x) (1+ x))
>     "Add one to x.")
>
> Which gives the same result.
>
> Note that the first argument must be quoted.
>
> Functions and variables are in different name spaces.
> The lambda is stored in the variable namespace

Ah, I was using defparameter because setf'ing at the top level doesn't
have well defined meaning, and so I was trying to retrieve the
function documentation for the value of *inc-defparameter* which is,
indeed, a function.

But, it does raise the point that in (defun inc-defun ...) the
documentation is associated with the symbol, where as in (lambda (x)
...) the documentation ought to be associated with the function. So:

(documentation 'inc-defun 'function) should be calling
documentation (x symbol) (doc-type (eql 'function))

whereas

(documentation *inc-defparameter* 'function) should be calling
documentation (x function) (doc-type (eql 'function))

but I'm not getting any documentation in the latter case.

Perhaps "if it is created" does refer to the documentation?

-- 
=====================
Joshua Taylor
tayloj@rpi.edu

"A lot of good things went down one time,
     back in the goodle days."
               John Hartford

Re: documentation strings on lambda expressions

On 9/26/07, Taylor, Joshua <tayloj@cs.rpi.edu> wrote:
> On 9/26/07, John Thingstad <john.thingstad@chello.no> wrote:
> > På Wed, 26 Sep 2007 22:48:09 +0200, skrev Taylor, Joshua
> > <tayloj@cs.rpi.edu>:
> >
> > > CL-USER 3 >
> > > (defparameter *inc-defparameter*
> > >   #'(lambda (x)
> > >       "Add one to x."
> > >       (1+ x)))
> > > *Inc-Defparameter*
> > >
> > > CL-USER 4 > (documentation *inc-defparameter* 'function)
> > > Nil ;; no documentation?
> > >
> > > Any thoughts? Suggestions? Thanks in advance!
> > >
> >
> > defparameter also has a documentation field.
> >
> > With the the original..
> > (documentation '*inc-defparameter* 'variable)
> > "Add one to x."
> >
> > or just write
> >
> > (defparameter *inc-parameter*
> >     (lambda (x) (1+ x))
> >     "Add one to x.")
> >
> > Which gives the same result.
> >
> > Note that the first argument must be quoted.
> >
> > Functions and variables are in different name spaces.
> > The lambda is stored in the variable namespace
>
> Ah, I was using defparameter because setf'ing at the top level doesn't
> have well defined meaning, and so I was trying to retrieve the
> function documentation for the value of *inc-defparameter* which is,
> indeed, a function.
>
> But, it does raise the point that in (defun inc-defun ...) the
> documentation is associated with the symbol, where as in (lambda (x)
> ...) the documentation ought to be associated with the function. So:
>
> (documentation 'inc-defun 'function) should be calling
> documentation (x symbol) (doc-type (eql 'function))
>
> whereas
>
> (documentation *inc-defparameter* 'function) should be calling
> documentation (x function) (doc-type (eql 'function))
>
> but I'm not getting any documentation in the latter case.
>
> Perhaps "if it is created" does refer to the documentation?
>

(Apologies for flooding this evening...)

I do notice in the HyperSpec
(http://www.lisp.org/HyperSpec/Body/stagenfun_doc_umentationcp.html)
that "[a]n implementation is permitted to discard documentation
strings at any time for implementation-defined reasons." It seems that
that is what might be happening in:

Cl-User> (defparameter *inc* #'(lambda (x) "add one to x" (1+ x)))
*Inc*
Cl-User> (documentation *inc* 'function)
Nil
Cl-User> (setf (documentation *inc* 'function) "add one to x")
"add one to x"
Cl-User> (documentation *inc* 'function)
Nil

Can any LispWorks folks chime in as to whether this is a case where
docstrings are discarded?

-- 
=====================
Joshua Taylor
tayloj@rpi.edu

"A lot of good things went down one time,
     back in the goodle days."
               John Hartford

Re: documentation strings on lambda expressions

Unable to parse email body. Email id is 7003

Updated at: 2020-12-10 08:45 UTC