MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Bad design in Set?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118534] Bad design in Set?
  • From: Alexey <lehin.p at gmail.com>
  • Date: Mon, 2 May 2011 06:50:36 -0400 (EDT)

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?


  • Prev by Date: Re: Why Indeterminate?
  • Next by Date: Re: Undo/Redo
  • Previous by thread: Re: Help Define a Constant I get from Mathematica
  • Next by thread: Re: Bad design in Set?