Lisp HUG Maillist Archive

Funcall setf forms

Hello,

To make some setf forms funcallable, I use

(defun mySetter (accessor object nwval)
    (funcall (fdefinition (list 'setf accessor)) nwval object))

It works, but after delivering at level 4 (with :compact t) I encountered
this error :

Undefined function SETF::\"MYPACKAGE\"\ \"MYFUNCTION\" in form
(SYMBOL-FUNCTION SETF::\" MYPACKAGE\"\ \" MYFUNCTION\")

However, MYPACKAGE and MYFUNCTION are correct and works well when not
delivered.

What I need is simply the possibility to use setf dynamically on accessors.
Is it a better method to do this ?

Thanks

Denis

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



Re: Funcall setf forms

On Fri, 13 Jun 2008 11:29:18 +0200, Denis Pousseur <denis.pousseur@gmail.com> wrote:

> To make some setf forms funcallable, I use
>
> (defun mySetter (accessor object nwval)
>     (funcall (fdefinition (list 'setf accessor)) nwval object))
>
> It works, but after delivering at level 4 (with :compact t) I encountered
> this error :
>
> Undefined function SETF::\"MYPACKAGE\"\ \"MYFUNCTION\" in form
> (SYMBOL-FUNCTION SETF::\" MYPACKAGE\"\ \" MYFUNCTION\")
>
> However, MYPACKAGE and MYFUNCTION are correct and works well when not
> delivered.
>
> What I need is simply the possibility to use setf dynamically on accessors.
> Is it a better method to do this ?

This won't work for you?

  CL-USER 1 > (defun my-first (list)
                (first list))
  MY-FIRST

  CL-USER 2 > (defun (setf my-first) (new-value list)
                (setf (first list) new-value))
  (SETF MY-FIRST)

  CL-USER 3 > (defparameter *list* (list 1 2 3))
  *LIST*

  CL-USER 4 > (setf (my-first *list*) 42)
  42

  CL-USER 5 > *list*
  (42 2 3)

  CL-USER 6 > (funcall #'(setf my-first) 43 *list*)
  43

  CL-USER 7 > *list*
  (43 2 3)


Re: Funcall setf forms

Hi Edi,

The problem is that the name of the function is a variable, as for instance:

(let ((fun 'my-fisrt))
  (funcall #'(setf fun) 43 *list*)

Naturally it doesn't work :

=> Error: Undefined function (SETF FUN) in form (FUNCTION (SETF FUN))

Is there something to do with a backquoted expression ? I really can't find
the right syntax...


Le 13/06/08 11:53, « [NOM] » <[ADRESSE]> a écrit :

> On Fri, 13 Jun 2008 11:29:18 +0200, Denis Pousseur <denis.pousseur@gmail.com>
> wrote:
> 
>> To make some setf forms funcallable, I use
>> 
>> (defun mySetter (accessor object nwval)
>>     (funcall (fdefinition (list 'setf accessor)) nwval object))
>> 
>> It works, but after delivering at level 4 (with :compact t) I encountered
>> this error :
>> 
>> Undefined function SETF::\"MYPACKAGE\"\ \"MYFUNCTION\" in form
>> (SYMBOL-FUNCTION SETF::\" MYPACKAGE\"\ \" MYFUNCTION\")
>> 
>> However, MYPACKAGE and MYFUNCTION are correct and works well when not
>> delivered.
>> 
>> What I need is simply the possibility to use setf dynamically on accessors.
>> Is it a better method to do this ?
> 
> This won't work for you?
> 
>   CL-USER 1 > (defun my-first (list)
>                 (first list))
>   MY-FIRST
> 
>   CL-USER 2 > (defun (setf my-first) (new-value list)
>                 (setf (first list) new-value))
>   (SETF MY-FIRST)
> 
>   CL-USER 3 > (defparameter *list* (list 1 2 3))
>   *LIST*
> 
>   CL-USER 4 > (setf (my-first *list*) 42)
>   42
> 
>   CL-USER 5 > *list*
>   (42 2 3)
> 
>   CL-USER 6 > (funcall #'(setf my-first) 43 *list*)
>   43
> 
>   CL-USER 7 > *list*
>   (43 2 3)

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



Re: Funcall setf forms


Am 13.06.2008 um 12:21 schrieb Denis Pousseur:

>
> Hi Edi,
>
> The problem is that the name of the function is a variable, as for  
> instance:
>
> (let ((fun 'my-fisrt))
>  (funcall #'(setf fun) 43 *list*)
>
> Naturally it doesn't work :
>
> => Error: Undefined function (SETF FUN) in form (FUNCTION (SETF FUN))
>
> Is there something to do with a backquoted expression ? I really  
> can't find
> the right syntax...

Just guessing: your function is gone in delivery while treeshaking.

Say you have a function #'(setf foo)  and #'(setf bar) .

Say you have

(defparameter *setters* (list #'(setf foo)))

Then after treeshaking it could be the #'(setf bar) is gone when it is  
referenced nowhere.
Your code might not reference it, since you compute the name.

#'(setf foo) might still be there since it is referenced in a list by  
a global variable.

Regards,

Rainer Joswig


>
>
>
> Le 13/06/08 11:53, « [NOM] » <[ADRESSE]> a écrit :
>
>> On Fri, 13 Jun 2008 11:29:18 +0200, Denis Pousseur <denis.pousseur@gmail.com 
>> >
>> wrote:
>>
>>> To make some setf forms funcallable, I use
>>>
>>> (defun mySetter (accessor object nwval)
>>>    (funcall (fdefinition (list 'setf accessor)) nwval object))
>>>
>>> It works, but after delivering at level 4 (with :compact t) I  
>>> encountered
>>> this error :
>>>
>>> Undefined function SETF::\"MYPACKAGE\"\ \"MYFUNCTION\" in form
>>> (SYMBOL-FUNCTION SETF::\" MYPACKAGE\"\ \" MYFUNCTION\")
>>>
>>> However, MYPACKAGE and MYFUNCTION are correct and works well when  
>>> not
>>> delivered.
>>>
>>> What I need is simply the possibility to use setf dynamically on  
>>> accessors.
>>> Is it a better method to do this ?
>>
>> This won't work for you?
>>
>>  CL-USER 1 > (defun my-first (list)
>>                (first list))
>>  MY-FIRST
>>
>>  CL-USER 2 > (defun (setf my-first) (new-value list)
>>                (setf (first list) new-value))
>>  (SETF MY-FIRST)
>>
>>  CL-USER 3 > (defparameter *list* (list 1 2 3))
>>  *LIST*
>>
>>  CL-USER 4 > (setf (my-first *list*) 42)
>>  42
>>
>>  CL-USER 5 > *list*
>>  (42 2 3)
>>
>>  CL-USER 6 > (funcall #'(setf my-first) 43 *list*)
>>  43
>>
>>  CL-USER 7 > *list*
>>  (43 2 3)
>
> -------------------------------------------------------
> Denis Pousseur
> 70 rue de Wansijn
> 1180 Bruxelles, Belgique
>
> Tel : 32 (0)2 219 31 09
> Mail :  denis.pousseur@gmail.com
> -------------------------------------------------------
>

Rainer Joswig, Hamburg, Germany
http://lispm.dyndns.org/
mailto:joswig@lisp.de




Re: Funcall setf forms


> Just guessing: your function is gone in delivery while treeshaking.
> 
> Say you have a function #'(setf foo)  and #'(setf bar) .
> 
> Say you have
> 
> (defparameter *setters* (list #'(setf foo)))
> 
> Then after treeshaking it could be the #'(setf bar) is gone when it is
> referenced nowhere.

But is not the declaration of the setf method a kind of reference ?

(defmethod (setf my-method) (nwval (object type)) (do-something))

> Your code might not reference it, since you compute the name.

I precise that I do not compute the name dynamically : The methods are
declared normally. The name is just variable because it follows the context
of the application at different moments (accessing one place or another with
some existing methods).

> #'(setf foo) might still be there since it is referenced in a list by
> a global variable.

Well, in my case it's a lot of works...
> 
> Regards,
> 
> Rainer Joswig


Best

Denis
>> 
>> Le 13/06/08 11:53, « [NOM] » <[ADRESSE]> a écrit :
>> 
>>> On Fri, 13 Jun 2008 11:29:18 +0200, Denis Pousseur <denis.pousseur@gmail.com
>>>> 
>>> wrote:
>>> 
>>>> To make some setf forms funcallable, I use
>>>> 
>>>> (defun mySetter (accessor object nwval)
>>>>    (funcall (fdefinition (list 'setf accessor)) nwval object))
>>>> 
>>>> It works, but after delivering at level 4 (with :compact t) I
>>>> encountered
>>>> this error :
>>>> 
>>>> Undefined function SETF::\"MYPACKAGE\"\ \"MYFUNCTION\" in form
>>>> (SYMBOL-FUNCTION SETF::\" MYPACKAGE\"\ \" MYFUNCTION\")
>>>> 
>>>> However, MYPACKAGE and MYFUNCTION are correct and works well when
>>>> not
>>>> delivered.
>>>> 
>>>> What I need is simply the possibility to use setf dynamically on
>>>> accessors.
>>>> Is it a better method to do this ?
>>> 
>>> This won't work for you?
>>> 
>>>  CL-USER 1 > (defun my-first (list)
>>>                (first list))
>>>  MY-FIRST
>>> 
>>>  CL-USER 2 > (defun (setf my-first) (new-value list)
>>>                (setf (first list) new-value))
>>>  (SETF MY-FIRST)
>>> 
>>>  CL-USER 3 > (defparameter *list* (list 1 2 3))
>>>  *LIST*
>>> 
>>>  CL-USER 4 > (setf (my-first *list*) 42)
>>>  42
>>> 
>>>  CL-USER 5 > *list*
>>>  (42 2 3)
>>> 
>>>  CL-USER 6 > (funcall #'(setf my-first) 43 *list*)
>>>  43
>>> 
>>>  CL-USER 7 > *list*
>>>  (43 2 3)
>> 
>> -------------------------------------------------------
>> Denis Pousseur
>> 70 rue de Wansijn
>> 1180 Bruxelles, Belgique
>> 
>> Tel : 32 (0)2 219 31 09
>> Mail :  denis.pousseur@gmail.com
>> -------------------------------------------------------
>> 
> 
> Rainer Joswig, Hamburg, Germany
> http://lispm.dyndns.org/
> mailto:joswig@lisp.de
> 
> 
> 

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



Re: Funcall setf forms


Am 13.06.2008 um 13:26 schrieb Denis Pousseur:

>
>
>> Just guessing: your function is gone in delivery while treeshaking.
>>
>> Say you have a function #'(setf foo)  and #'(setf bar) .
>>
>> Say you have
>>
>> (defparameter *setters* (list #'(setf foo)))
>>
>> Then after treeshaking it could be the #'(setf bar) is gone when it  
>> is
>> referenced nowhere.
>
> But is not the declaration of the setf method a kind of reference ?
>
>
> (defmethod (setf my-method) (nwval (object type)) (do-something))

Does your code ever use that method (directly!)? If not, why shouldn't  
it be deleted during treeshaking?

>
>> Your code might not reference it, since you compute the name.
>
> I precise that I do not compute the name dynamically : The methods are
> declared normally. The name is just variable because it follows the  
> context
> of the application at different moments (accessing one place or  
> another with
> some existing methods).

Declaration is one thing. But do you use it somewhere? The function  
name is
computed: (list 'setf my-name) . So that's not a direct reference of  
the function.

I guess you need to tell the Lisp system not to remove the definition  
of these
functions and/or the function names.

See:

http://www.lispworks.com/documentation/lw51/DV/html/deluser-71.htm#pgfId-852176

Regards,

Rainer Joswig


>
>
>> #'(setf foo) might still be there since it is referenced in a list by
>> a global variable.
>
> Well, in my case it's a lot of works...
>>
>> Regards,
>>
>> Rainer Joswig
>
>
> Best
>
> Denis
>>>
>>> Le 13/06/08 11:53, « [NOM] » <[ADRESSE]> a écrit :
>>>
>>>> On Fri, 13 Jun 2008 11:29:18 +0200, Denis Pousseur <denis.pousseur@gmail.com
>>>>>
>>>> wrote:
>>>>
>>>>> To make some setf forms funcallable, I use
>>>>>
>>>>> (defun mySetter (accessor object nwval)
>>>>>   (funcall (fdefinition (list 'setf accessor)) nwval object))
>>>>>
>>>>> It works, but after delivering at level 4 (with :compact t) I
>>>>> encountered
>>>>> this error :
>>>>>
>>>>> Undefined function SETF::\"MYPACKAGE\"\ \"MYFUNCTION\" in form
>>>>> (SYMBOL-FUNCTION SETF::\" MYPACKAGE\"\ \" MYFUNCTION\")
>>>>>
>>>>> However, MYPACKAGE and MYFUNCTION are correct and works well when
>>>>> not
>>>>> delivered.
>>>>>
>>>>> What I need is simply the possibility to use setf dynamically on
>>>>> accessors.
>>>>> Is it a better method to do this ?
>>>>
>>>> This won't work for you?
>>>>
>>>> CL-USER 1 > (defun my-first (list)
>>>>               (first list))
>>>> MY-FIRST
>>>>
>>>> CL-USER 2 > (defun (setf my-first) (new-value list)
>>>>               (setf (first list) new-value))
>>>> (SETF MY-FIRST)
>>>>
>>>> CL-USER 3 > (defparameter *list* (list 1 2 3))
>>>> *LIST*
>>>>
>>>> CL-USER 4 > (setf (my-first *list*) 42)
>>>> 42
>>>>
>>>> CL-USER 5 > *list*
>>>> (42 2 3)
>>>>
>>>> CL-USER 6 > (funcall #'(setf my-first) 43 *list*)
>>>> 43
>>>>
>>>> CL-USER 7 > *list*
>>>> (43 2 3)
>>>
>>> -------------------------------------------------------
>>> Denis Pousseur
>>> 70 rue de Wansijn
>>> 1180 Bruxelles, Belgique
>>>
>>> Tel : 32 (0)2 219 31 09
>>> Mail :  denis.pousseur@gmail.com
>>> -------------------------------------------------------
>>>
>>
>> Rainer Joswig, Hamburg, Germany
>> http://lispm.dyndns.org/
>> mailto:joswig@lisp.de
>>
>>
>>
>
> -------------------------------------------------------
> Denis Pousseur
> 70 rue de Wansijn
> 1180 Bruxelles, Belgique
>
> Tel : 32 (0)2 219 31 09
> Mail :  denis.pousseur@gmail.com
> -------------------------------------------------------
>

Rainer Joswig, Hamburg, Germany
http://lispm.dyndns.org/
mailto:joswig@lisp.de




Re: Funcall setf forms



>> But is not the declaration of the setf method a kind of reference ?
>> 
>> 
>> (defmethod (setf my-method) (nwval (object type)) (do-something))
> 
> Does your code ever use that method (directly!)? If not, why shouldn't
> it be deleted during treeshaking?
> 
>> 
>>> Your code might not reference it, since you compute the name.
>> 
>> I precise that I do not compute the name dynamically : The methods are
>> declared normally. The name is just variable because it follows the
>> context
>> of the application at different moments (accessing one place or
>> another with
>> some existing methods).
> 
> Declaration is one thing. But do you use it somewhere? The function
> name is
> computed: (list 'setf my-name) . So that's not a direct reference of
> the function.

Ah yes, I understand... You're right : some of these methods are never
called directly.

> 
> I guess you need to tell the Lisp system not to remove the definition
> of these
> functions and/or the function names.
> 
> See:
> 
> 
http://www.lispworks.com/documentation/lw51/DV/html/deluser-71.htm#pgfId-85217>
6

Yes I did. But in my deliver context, the :keep-function-name default-value
should be T, witch mean "Keep names as strings and retain argument
information.". It's why I thought that my function name must be present in
the image anyway. But I didn't thing to this special case : funcalled
functions are not referenced as others (I suppose it's also why we don't
find it when call the "Function Calls" utility of the IDE).

Thanks for your help !

Denis
> 
> Regards,
> 
> Rainer Joswig
> 
> 
>> 
>> 
>>> #'(setf foo) might still be there since it is referenced in a list by
>>> a global variable.
>> 
>> Well, in my case it's a lot of works...
>>> 
>>> Regards,
>>> 
>>> Rainer Joswig
>> 
>> 
>> Best
>> 
>> Denis
>>>> 
>>>> Le 13/06/08 11:53, « [NOM] » <[ADRESSE]> a écrit :
>>>> 
>>>>> On Fri, 13 Jun 2008 11:29:18 +0200, Denis Pousseur
>>>>> <denis.pousseur@gmail.com
>>>>>> 
>>>>> wrote:
>>>>> 
>>>>>> To make some setf forms funcallable, I use
>>>>>> 
>>>>>> (defun mySetter (accessor object nwval)
>>>>>>   (funcall (fdefinition (list 'setf accessor)) nwval object))
>>>>>> 
>>>>>> It works, but after delivering at level 4 (with :compact t) I
>>>>>> encountered
>>>>>> this error :
>>>>>> 
>>>>>> Undefined function SETF::\"MYPACKAGE\"\ \"MYFUNCTION\" in form
>>>>>> (SYMBOL-FUNCTION SETF::\" MYPACKAGE\"\ \" MYFUNCTION\")
>>>>>> 
>>>>>> However, MYPACKAGE and MYFUNCTION are correct and works well when
>>>>>> not
>>>>>> delivered.
>>>>>> 
>>>>>> What I need is simply the possibility to use setf dynamically on
>>>>>> accessors.
>>>>>> Is it a better method to do this ?
>>>>> 
>>>>> This won't work for you?
>>>>> 
>>>>> CL-USER 1 > (defun my-first (list)
>>>>>               (first list))
>>>>> MY-FIRST
>>>>> 
>>>>> CL-USER 2 > (defun (setf my-first) (new-value list)
>>>>>               (setf (first list) new-value))
>>>>> (SETF MY-FIRST)
>>>>> 
>>>>> CL-USER 3 > (defparameter *list* (list 1 2 3))
>>>>> *LIST*
>>>>> 
>>>>> CL-USER 4 > (setf (my-first *list*) 42)
>>>>> 42
>>>>> 
>>>>> CL-USER 5 > *list*
>>>>> (42 2 3)
>>>>> 
>>>>> CL-USER 6 > (funcall #'(setf my-first) 43 *list*)
>>>>> 43
>>>>> 
>>>>> CL-USER 7 > *list*
>>>>> (43 2 3)
>>>> 
>>>> -------------------------------------------------------
>>>> Denis Pousseur
>>>> 70 rue de Wansijn
>>>> 1180 Bruxelles, Belgique
>>>> 
>>>> Tel : 32 (0)2 219 31 09
>>>> Mail :  denis.pousseur@gmail.com
>>>> -------------------------------------------------------
>>>> 
>>> 
>>> Rainer Joswig, Hamburg, Germany
>>> http://lispm.dyndns.org/
>>> mailto:joswig@lisp.de
>>> 
>>> 
>>> 
>> 
>> -------------------------------------------------------
>> Denis Pousseur
>> 70 rue de Wansijn
>> 1180 Bruxelles, Belgique
>> 
>> Tel : 32 (0)2 219 31 09
>> Mail :  denis.pousseur@gmail.com
>> -------------------------------------------------------
>> 
> 
> Rainer Joswig, Hamburg, Germany
> http://lispm.dyndns.org/
> mailto:joswig@lisp.de
> 
> 
> 

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



Re: Funcall setf forms

On 13 Jun 2008, at 12:26, Denis Pousseur wrote:
>
> But is not the declaration of the setf method a kind of reference ?

It is, but treeshaking is trying to delete references which it thinks  
are never actually used (for instance from the symbol table).

I should think an approach would be to define some kind of DEF- 
REGISTERED-METHOD macro which:
1. Defined a method
2. Arranged for a reference to the appropriate object to be stored in  
some list which you could then be careful was not itself shaken.

--tim


Re: Funcall setf forms




Le 13/06/08 12:51, « [NOM] » <[ADRESSE]> a écrit :

> (defparameter *setters* (list #'(setf foo)))


Well, finally, a global-variable bound to a list containing the functions
AND function names is not sufficient to reference them. In fact, it doesn't
change anything...

But using the delivery keyword :keep-symbols works. So it's ok (but not very
convenient to imagine an automatism).

Best

Denis

-------------------------------------------------------
Denis Pousseur
70 rue de Wansijn
1180 Bruxelles, Belgique

Tel : 32 (0)2 219 31 09
Mail :  denis.pousseur@gmail.com
-------------------------------------------------------



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