Re: Bad design in Set?
- To: mathgroup at smc.vnet.net
- Subject: [mg118566] Re: Bad design in Set?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Tue, 3 May 2011 05:45:36 -0400 (EDT)
Calls to Java are made for ABSOLUTELY everything Mathematica does, are
they not?
Bobby
On Mon, 02 May 2011 05:50:36 -0500, Alexey <lehin.p at gmail.com> wrote:
> Recently I discovered that in Mathematica 7.01 the built-in function
> Set is overloaded by default in a **very** strange way:
>
> In[1]:= DownValues[Set]
>
> Out[1]= {HoldPattern[
> JLink`Private`sym_Symbol[JLink`Private`arg_Symbol] =
> JLink`Private`val_] :>
> With[{JLink`Private`obj = JLink`Private`sym},
> JLink`CallJava`Private`setField[
> JLink`Private`obj[JLink`Private`arg], JLink`Private`val] /;
> Head[JLink`Private`obj] === Symbol &&
> StringMatchQ[Context[JLink`Private`obj], "JLink`Objects`*"]]}
>
> The l.h.s of this definition matches any expression of the form
> 'a[b]=c' that is a very general and commonly-used form of assignment.
> Moreover, in the r.h.s of this definition we see an expression of the
> form
>
> JLink`CallJava`Private`setField[_]/;condition
>
> It is easy to see that the call to Java will be made regardless of the
> 'condition', IOW **always** when the l.h.s matches:
>
> Print["!"]/;False
>
> prints "!".
>
> Is it reasonable to make a call to Java every time when a user makes
> an assignment of the form 'a[b]=c'?
>
> The other problem is that it changes the default behavior of Set in
> some cases.
>
> Consider:
>
> In[4]:= a:=(a=.;5);
> a[b]=1
> DownValues[a]
> Out[5]= 1
> Out[6]= {HoldPattern[a[b]]:>1}
>
> Afrter removing the above-mentioned definition for Set we get another
> behavior which is consistent with the behavior of Mathematica 5:
>
> In[1]:= Unprotect[Set];Clear[Set];
> a:=(a=.;5);
> a[b]=1
> DownValues[a]
> During evaluation of In[1]:= Set::write: Tag Integer in 5[b] is
> Protected. >>
> Out[3]= 1
> Out[4]= {}
>
> At large, this looks like an extremely bad design of some Java-related
> functionality, is not it? What are your thoughts?
>
--
DrMajorBob at yahoo.com