From: ············@gmail.com
Subject: export setf expansion
Date: 
Message-ID: <1105182319.035344.63580@c13g2000cwb.googlegroups.com>
Hi,

when I defun setf expansion, do I bind a symbol? Do I have to export it
if I want to use it outside of the package? Can I export a function and
not its' setf expansion? Can I export setf expansion for a function but
not the function?

David

From: Kalle Olavi Niemitalo
Subject: Re: export setf expansion
Date: 
Message-ID: <87acrkdo48.fsf@Astalo.kon.iki.fi>
·············@gmail.com" <············@gmail.com> writes:

> when I defun setf expansion, do I bind a symbol?

You seem to be using "setf expansion" with some other meaning
than the one given in the glossary of the Common Lisp HyperSpec.

Do you mean like (defun (setf foo) ...)?  I don't know whether it
would be right to say the function is bound to the symbol FOO.
However, to access the function, you need that symbol.

> Do I have to export it if I want to use it outside of the
> package?

No, you can refer to package::symbol even if it is not exported.
However, exporting can be a convenient way to indicate which
symbols can be expected retain their semantics in future versions
of the module.

> Can I export a function and not its' setf expansion?
> Can I export setf expansion for a function but not the function?

Only symbols can be exported; functions cannot.  I think the best
you can do here is to bind another symbol to the same function
(or to a wrapper) and then export that.  If you have many such
symbols, it would be good to name them consistently: for example
FOO for the exported symbol and %FOO for the internal one.
From: ············@gmail.com
Subject: Re: export setf expansion
Date: 
Message-ID: <1105198043.612168.55000@c13g2000cwb.googlegroups.com>
'setf expansion function' is how it is called in Common Lisp the
Langauge, the Second Edition, 5.3.1.  Is there a separate symbol that
corresponds to setf expansion function? Or is it a property of the
symbol that is bound for the function for which setf expansioin is
defined?

David Tolpin
From: Pascal Bourguignon
Subject: Re: export setf expansion
Date: 
Message-ID: <87brbzj4iv.fsf@thalassa.informatimago.com>
·············@gmail.com" <············@gmail.com> writes:

> 'setf expansion function' is how it is called in Common Lisp the
> Langauge, the Second Edition, 5.3.1.  

setf function n. a function whose name is (setf symbol).

setf expander n. a function used by setf to compute the setf expansion
                   of a place.

There is no 'setf expansion function' in the glossary...

> Is there a separate symbol that
> corresponds to setf expansion function? Or is it a property of the
> symbol that is bound for the function for which setf expansioin is
> defined?

This is an implementation specific detail. In part:

http://www.lispworks.com/reference/HyperSpec/Body/05_aab.htm

    Also, it follows from this that it is implementation-dependent
    whether the name (setf F) is fbound.


clisp-2.33 attaches setf functions to symbols such as:
'|(SETF COMMON-LISP-USER:TOTO)| for (setf toto),
both (fboundp '(setf toto)) and (fboundp '|(SETF COMMON-LISP-USER:TOTO)|)
return T and (symbol-plist 'toto) contains:
(SYSTEM::SETF-FUNCTION |(SETF COMMON-LISP-USER:TOTO)|)

But another implementation could as well keep them in a hashtable
under eg. the 'toto key.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This is a signature virus.  Add me to your signature and help me to live
From: ············@gmail.com
Subject: Re: export setf expansion
Date: 
Message-ID: <1105200310.260813.201650@c13g2000cwb.googlegroups.com>
'setf expansion function' is in Common Lisp the Language, Second
Edition, 5.3.1. Is that a typo?
So, if I define a setf function in a package, how can I export it?
From: Christopher C. Stacy
Subject: Re: export setf expansion
Date: 
Message-ID: <ufz1b94dh.fsf@news.dtpq.com>
·············@gmail.com" <············@gmail.com> writes:

> 'setf expansion function' is in Common Lisp the Language, Second
> Edition, 5.3.1. Is that a typo?
> So, if I define a setf function in a package, how can I export it?

If you read the introductory part of that book, don't miss the part
where it says that it's not describing any actual Common Lisp language,
and in particular, not ANSI Common Lisp.  (It's an inconsistent snapshot
of the ANSI process at a random moment in time.)
From: Kalle Olavi Niemitalo
Subject: Re: export setf expansion
Date: 
Message-ID: <87hdlrdckz.fsf@Astalo.kon.iki.fi>
·············@gmail.com" <············@gmail.com> writes:

> 'setf expansion function' is in Common Lisp the Language, Second
> Edition, 5.3.1. Is that a typo?

I suppose that's just old terminology.  CLHS calls those things
"setf functions" instead.  Likewise, "setf method" was changed to
"setf expander".
From: Thomas A. Russ
Subject: Re: export setf expansion
Date: 
Message-ID: <ymiwtul2mxm.fsf@sevak.isi.edu>
·············@gmail.com" <············@gmail.com> writes:


> 'setf expansion function' is in Common Lisp the Language, Second
> Edition, 5.3.1. Is that a typo?
> So, if I define a setf function in a package, how can I export it?

It seems that you have a fundamental confusion about what it means to
export something from a package.  This is actually not infrequent for
people coming to Lisp from other programming languages where packages
and exporting mean something different.

In Common Lisp, packages concern themselves solely with the mapping of
strings to symbols.  You can export symbols from a package, which will
make the symbol an external symbol of that package.  Functions, global
special values, and class or type names are among the things that are
named by symbols, but those objects are not "exported" in the Common
Lisp sense.  It is merely the symbol that names them that is exported.

The effects of exporting are that one can refer to the symbol using the
exported symbol reader syntax of a single colon, rather than the double
colon needed for internal symbols.  Also, exported symbols are the ones
that are made available if another package chooses to "use" the package
that exports them.

Regardless of whether you export the symbol, in Common Lisp the
underlying function, setf expander, etc. is always available for use.

Package exporting is meant as a means of visibility control.  It is not
a form of access control.

Now, addressing your particular question:

If you define a setf expander like,

  (defun (setf FOO) ...)

the question then is really whether you want to export the symbol FOO or
not.  (The symbol SETF is already an exported symbol of the Common Lisp
package).

If you export FOO, then the symbol FOO is visible as an external symbol
and can be used as an external symbol to refer to anything else that
uses the same symbol as its name:

  (setf (my-package:foo x) ...)        ; If there is a setf expander
  (print (my-package:foo x))           ; If there is an accessor or function
  (make-instance 'my-package:foo)      ; Assuming a class FOO exists



-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pascal Bourguignon
Subject: Re: export setf expansion
Date: 
Message-ID: <873bx9gjvz.fsf@thalassa.informatimago.com>
···@sevak.isi.edu (Thomas A. Russ) writes:
> If you export FOO, then the symbol FOO is visible as an external symbol
> and can be used as an external symbol to refer to anything else that
> uses the same symbol as its name:
> 
>   (setf (my-package:foo x) ...)        ; If there is a setf expander
>   (print (my-package:foo x))           ; If there is an accessor or function
>   (make-instance 'my-package:foo)      ; Assuming a class FOO exists

It can even be used to name local things out of the my-package package:

    (let ((my-package:foo :hehe) ;(unless it's a constant)
          (h (make-hash-table)))
      (tagbody
          (setf (gethash 'my-package:foo h) 3)
        my-package:foo
          (print my-package:foo)
          (when (zerop (decf (gethash 'my-package:foo))) 
              (go my-package:foo))))
    
-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

The world will now reboot.  don't bother saving your artefacts.
From: Steven M. Haflich
Subject: Re: export setf expansion
Date: 
Message-ID: <IFZDd.9550$5R.2003@newssvr21.news.prodigy.com>
Pascal Bourguignon wrote:
> 
> clisp-2.33 attaches setf functions to symbols such as:
> '|(SETF COMMON-LISP-USER:TOTO)| for (setf toto),
> both (fboundp '(setf toto)) and (fboundp '|(SETF COMMON-LISP-USER:TOTO)|)
> return T and (symbol-plist 'toto) contains:
> (SYSTEM::SETF-FUNCTION |(SETF COMMON-LISP-USER:TOTO)|)

I consider this to be a violation of the ANS, although objectively not
an important or consequential one:  If I happened to write this legal
and portable code

   (defun |(SETF COMMON-LISP-USER:TOTO) (&rest args) args)
   (defsetf common-lisp-usr::toto (&rest args) (evil-witch-of-the-rest ...))

then I would be unhappy if the implementation overwrote one definition with
the other.
From: Pascal Bourguignon
Subject: Re: export setf expansion
Date: 
Message-ID: <87oefyh4tr.fsf@thalassa.informatimago.com>
"Steven M. Haflich" <·················@alum.mit.edu> writes:

> Pascal Bourguignon wrote:
> > clisp-2.33 attaches setf functions to symbols such as:
> > '|(SETF COMMON-LISP-USER:TOTO)| for (setf toto),
> > both (fboundp '(setf toto)) and (fboundp '|(SETF COMMON-LISP-USER:TOTO)|)
> > return T and (symbol-plist 'toto) contains:
> > (SYSTEM::SETF-FUNCTION |(SETF COMMON-LISP-USER:TOTO)|)
> 
> I consider this to be a violation of the ANS, although objectively not
> an important or consequential one:  If I happened to write this legal
> and portable code
> 
>    (defun |(SETF COMMON-LISP-USER:TOTO) (&rest args) args)
>    (defsetf common-lisp-usr::toto (&rest args) (evil-witch-of-the-rest ...))
> 
> then I would be unhappy if the implementation overwrote one definition with
> the other.

Indeed, #:|(SETF COMMON-LISP-USER:TOTO)| should rather be used...

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This is a signature virus.  Add me to your signature and help me to live
From: Steven M. Haflich
Subject: Re: export setf expansion
Date: 
Message-ID: <sBJEd.614$8Z1.597@newssvr14.news.prodigy.com>
Pascal Bourguignon wrote:

> Indeed, #:|(SETF COMMON-LISP-USER:TOTO)| should rather be used...

This somewhat muddies the issue.

The setf function could be defined on an uninterned symbol, but if so,
that begs the question how that symbol would be found when it is needed.
Probably the symbol would be put on some property on the setter function's
name property list, but if so, the function could be just as well be
defined on a gensym with a null-string name.  Nearly everything in existing
CL that depends upon gensym would continue to work if gensym had been defined

(defun gensym (&rest ignore)
   (declare (ignore ignore))
   (make-symbol ""))

The name of an uninterned symbol rarely matters (in the sense of having useful
semantics) except if the purpose of the symbol is to be printed, in which case
Lisp programming fo the past 30 years would generally prefer using strings :-).
The name might be useful if and when it appears in the debugger etc., and that
use may be justification enough for generating an interesting name.  But in
the case of a name for a setf function there is no obvious region in the symbol
namespace that can be used unambiguously to name and retrieve setf function
names from the name of the setter function.  Some other mechanism such as
property lists is necessary.

But as I wrote earlier, this is mostly a theoretical problem, not an important
one in practice.
From: Pascal Bourguignon
Subject: Re: export setf expansion
Date: 
Message-ID: <87r7ksf4b6.fsf@thalassa.informatimago.com>
"Steven M. Haflich" <·················@alum.mit.edu> writes:

> Pascal Bourguignon wrote:
> 
> > Indeed, #:|(SETF COMMON-LISP-USER:TOTO)| should rather be used...
                                                                 ...by clisp.
should I have added.

> 
> This somewhat muddies the issue.

Yes, the important part in my answer was "#:".


> The setf function could be defined on an uninterned symbol, but if so,
> that begs the question how that symbol would be found when it is needed.

The point is that clisp puts this symbol on the property list of TOTO anyway!

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

The world will now reboot.  don't bother saving your artefacts.
From: Jeff
Subject: Re: export setf expansion
Date: 
Message-ID: <KyTDd.1982$Xx1.1960@attbi_s04>
············@gmail.com wrote:


> when I defun setf expansion, do I bind a symbol? 

I truely don't know what happens under the hood, but I believe all that
happens is that it tells the compiler to add another form to setf.

> Do I have to export it?

No, so long as the symbol is exported that is used by the setf. It is a
kind of all-or-none approach.

Remember, setf expansions are macros, and they don't have to set
anything. For example, in my CPW package (see website in .sig), I use
setf to call settable callback functions:

(export 'cpw-reshape-callback)

(define-foreign-function cpw-reshape-callback (function)
  "Sets the window resizing callback to function."
  ...)

(defsetf cpw-reshape-callback () (function)
  `(cpw-reshape-callback (do-something-complex ,function)))

Of course, it is actually more complicated than this, but this is just
for an example, I just rework the function call so that using a setf
does everything needed to the passed function.

HTH,
Jeff M.

-- 
http://www.retrobyte.org
··············@gmail.com