Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6235005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:35:46+00:00 2026-05-24T10:35:46+00:00

For cases where one has already assigned DownValues associated with the name ‘a’, is

  • 0

For cases where one has already assigned DownValues associated with the name ‘a’, is there an accepted way to block the assignment of OwnValues to the same name? (I originally came across this issue while playing with someone’s attempt at implementing a data dictionary.)

Here’s what I mean to avoid:

Remove[a];
a[1] := somethingDelayed
a[2] = somethingImmediate;
DownValues[a]
a[1]
a[2]

Returns…

{HoldPattern[a[1]] :> somethingDelayed, 
 HoldPattern[a[2]] :> somethingImmediate}
somethingDelayed
somethingImmediate

And now if we were to evaluate:

a = somethingThatScrewsUpHeads;
(* OwnValues[a] above stored in OwnValues *)
a[1]
a[2]

We get…

somethingThatScrewsUpHeads[1]
somethingThatScrewsUpHeads[2]

Is there an easy/flexible way to prevent OwnValues for any Name in DownValues? (Lemme guess… it’s possible, but there’s going to be a performance hit?)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:35:46+00:00Added an answer on May 24, 2026 at 10:35 am

    I don’t know if this is an “accepted” way, but you could define a rule that prevents Set and SetDelayed from acting upon a:

    Remove[a];
    a[1] := somethingDelayed
    a[2] = somethingImmediate;
    
    a /: HoldPattern[(Set|SetDelayed)[a, _]] := (Message[a::readOnly]; Abort[])
    
    a::readOnly = "The symbol 'a' cannot be assigned a value.";
    

    With this rule in place, any attempt to assign an OwnValue to a will fail:

    In[17]:= a = somethingThatScrewsUpHeads;
    
    During evaluation of In[17]:= a::readOnly:
      The symbol 'a' cannot be assigned a value.
    
    Out[17]= $Aborted
    
    In[18]:= a := somethingThatScrewsUpHeads;
    
    During evaluation of In[18]:= a::readOnly:
      The symbol 'a' cannot be assigned a value.
    
    Out[18]= $Aborted
    

    However, this rule will still allow new DownValues for a:

    In[19]:= a[3] = now;
             a[4] := later
    
    In[20]:= a[3]
    
    Out[20]= now
    
    In[21]:= a[4]
    
    Out[21]= later
    

    Performance

    The rule does not seem to have an appreciable impact on the performance of Set and SetDelayed, presumably since the rule is installed as an up-value on a. I tried to verify this by executing…

    Timing@Do[x = i, {i, 100000000}]
    

    … both before and after the installation of the rule. There was no observable change in the timing. I then tried installing Set-related up-values on 10,000 generated symbols, thus:

    Do[
      With[{s=Unique["s"]}
      , s /: HoldPattern[(Set|SetDelayed)[s, _]] :=
          (Message[s::readOnly]; Abort[])
      ]
    , {10000}]
    

    Again, the timing did not change even with so many up-value rules in place. These results suggest that this technique is acceptable from a performance standpoint, although I would strongly advise performing performance tests within the context of your specific application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to use one CASE statement and return 2 different values?
If this has already been asked, please link and close this one. I'm currently
Let's say that any C function has a pointer already declared, but not assigned
In my database, Concessions have a many-to-one relationship with Firms (each Concession has a
My application already has unit test for domain layer I would like to know
Case One: new Date(Date.parse(Jul 8, 2005)); Output: Fri Jul 08 2005 00:00:00 GMT-0700 (PST)
Case One Say you have a little class: class Point3D { private: float x,y,z;
I can imagine one case, in which the input parameter could be NULL so
I have two functions whose underlying logic is the same but in one case
This one is a case of not doing your homework.:-) Apart from dynamic loading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.