Re: Rule-based programming: declare variables to be a number
- To: mathgroup at smc.vnet.net
- Subject: [mg80832] Re: Rule-based programming: declare variables to be a number
- From: Szabolcs <szhorvat at gmail.com>
- Date: Tue, 4 Sep 2007 03:35:04 -0400 (EDT)
- Organization: University of Bergen
- References: <fb83lf$82d$1@smc.twtelecom.net> <200709020651.CAA25850@smc.twtelecom.net> <fbgmuq$9d7$1@smc.vnet.net>
Andrzej Kozlowski wrote: > NumericQ has clearly been designed with this in mind. Note, for > example, that althou NumericQ is Protected, a definition like > > NumericQ[a]=True > > does not require unprotecting NumericQ. Moreover, it does not add a > DownValue to NumericQ. > > NumericQ[g] = True; > DownValues[NumericQ] > {} > > > There are plenty of other reasons to believe that all all > theseproperties of NumericQ are designed precisely for this type of > use. Besides, I have another reason to think that no probems of the > kind you are imagining would happen in this case: I have been using > NumericQ inprecisly this way for about 10 years in numerous notebooks > without any problems. > > Note alo the post from Carl Woll which, I think, can be regarded as > an "offcial" WRI authorization for this kind of usage ;-) > > (However, note also that using Carl's definition: > > In[19]:= g /: NumericQ[g] = True; > > Dos not actually add an UpValue to g: > > UpValues[g] > {} > > and I don't think it has any advantage over the more straightforward > > NumericQ[g] = True; > > > I am sure all this is deliberate design, and even though it may not > be easy to explain, it is very convenient. > > Andrzej Kozlowski > Thanks for the explanation! But this is very curious. If neither the UpValues or Attributes of g, or the DownValues of NumericQ are changed, then where is this information about g stored? Is this something that is implemented at a lower level than the Mathematica language? Is it possible to create other custom properties, that can be set with a command as simple as someProperty[g] = True (without using g /: someProperty[g] = True)? Perhaps NumericQ itself behaves similarly to DownValues, OwnValues, etc., where it is also possible to write OwnValues[a]={a->3} directly, but when 'a' is removed, its OwnValues are gone too. (When 'g' is Removed, the information that NumericQ[g] === True is gone too.) Szabolcs
- References:
- Re: Rule-based programming: declare variables to be a number
- From: David Bailey <dave@Remove_Thisdbailey.co.uk>
- Re: Rule-based programming: declare variables to be a number