[armedbear-devel] SETF for JFEILDS

logicmoo at gmail.com logicmoo at gmail.com
Mon Nov 23 14:47:35 UTC 2009


So actually

(defun (setf jfield)  (newvalue class-ref-or-field field-or-instance &optional ( instance :noinst) unusedvalue)
  (if (eq instance :noinst)
   (jfield class-ref-or-field field-or-instance newvalue)
   (jfield class-ref-or-field field-or-instance instance newvalue)))

Would be a little better.. good eye.


----- Original Message ----- 
From: <dmiles at users.sourceforge.net>
To: "Alessio Stalla" <alessiostalla at gmail.com>
Cc: "Armed Bear" <armedbear-devel at common-lisp.net>
Sent: Monday, November 23, 2009 6:27 AM
Subject: Re: [armedbear-devel] SETF for JFEILDS


> 
> ----- Original Message ----- 
> From: "Alessio Stalla" <alessiostalla at gmail.com>
> To: <dmiles at users.sourceforge.net>
> Cc: "Armed Bear" <armedbear-devel at common-lisp.net>
> Sent: Monday, November 23, 2009 5:42 AM
> Subject: Re: [armedbear-devel] SETF for JFEILDS
> 
> 
> On Mon, Nov 23, 2009 at 2:36 PM,  <logicmoo at gmail.com> wrote:
>>> Does anyone object to adding this to java.lisp? If not could it be done?
>>>
>>> (defun (setf jfield)
>>> (newvalue class-ref-or-field field-or-instance &optional ( instance :noinst) (value :novalue))
>>> (if (eq instance :noinst)
>>> (jfield class-ref-or-field field-or-instance newvalue)
>>> (jfield class-ref-or-field field-or-instance instance newvalue)))
> 
>>It seems a nice idea to me, but there are a couple of things that I
>>don't understand:
> 
> A>- why :noinst and not simply nil?
> 
> JFIELD is defined as:   class-ref-or-field field-or-instance &optional instance value
> The valid argument patterns for this operation are: 
>  (class-ref  field-name): to retrieve the value of a static field. 
>  (class-ref  field-name  instance-ref): to retrieve the value of a class field of the instance. 
>  (class-ref  field-name  primitive-value:) to store primitive-value in a static field. 
>  (class-ref  field-name  instance-ref  value): to store value in a class field of the instance. 
>  (class-ref  field-name  nil  value): to store value in a static field (when value may be confused with an instance-ref). 
>  (field-name  instance): to retrieve the value of a field of the instance. The class is derived from the instance. 
>  (field-name  instance  value): to store value in a field of the instance. The class is derived from the instance. 
> 
> JFIELD doesn't distingusih between static and non static fields
> 
> Also cases of  "class-ref  field-name  instance-ref  value"  (accessing  superclass field)
> 
> Depending on how the field is defined
> 
>  (setf (jfield  *MyClass* "someStaticBooleanField") NIL)
>      it is distinguable from   
>  (setf (jfield  *MySuperClass* "nonStaticBooleanField" *my-instance* ) NIL)
> 
> 
> --------------------------------------------------------------------------------------------------------------------------
> A>- value is not used, what's the point of it?  
> 
> correct the  "default :novalue" is not needed.    
> (I was debugging and trying to find corner cases with all those bizzare legal jfield signatures )
> 
> 
>   but... "value" as an &optional was needed to match the signature of what is legal for jfield so things like this can work:
> 
> (define-symbol-macro %iscold (jfield "org.armedbear.lisp.Lisp" "cold"))
>    %iscold ;; ==> NIL    
>    (setq %iscold T) ;; ==> T    
>    %iscold ;; ==> T     
>    (setq %iscold NIL) ;; ==> NIL
> 
>




More information about the armedbear-devel mailing list