Skip to main content

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set a owndown-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

DowValueDownValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an own-value and a down-value, but look what happens when x[42] is evaluated.

x[42]

42[42]

This happens because under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at own-vales first and finds one. It uses that own-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a down-value of x because it doesn't need to.

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set a own-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

DowValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an own-value and a down-value, but look what happens when x[42] is evaluated.

x[42]

42[42]

This happens because under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at own-vales first and finds one. It uses that own-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a down-value of x because it doesn't need to.

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set a down-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

DownValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an own-value and a down-value, but look what happens when x[42] is evaluated.

x[42]

42[42]

This happens because under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at own-vales first and finds one. It uses that own-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a down-value of x because it doesn't need to.

Commonmark migration
Source Link

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

###OwnValue first

OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set a own-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

###DowValue first

DowValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an own-value and a down-value, but look what happens when x[42] is evaluated.

x[42]

42[42]

This happens because under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at own-vales first and finds one. It uses that own-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a down-value of x because it doesn't need to.

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

###OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set a own-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

###DowValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an own-value and a down-value, but look what happens when x[42] is evaluated.

x[42]

42[42]

This happens because under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at own-vales first and finds one. It uses that own-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a down-value of x because it doesn't need to.

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set a own-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

DowValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an own-value and a down-value, but look what happens when x[42] is evaluated.

x[42]

42[42]

This happens because under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at own-vales first and finds one. It uses that own-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a down-value of x because it doesn't need to.

Rollback to Revision 4 - Edit approval overridden by post owner or moderator
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263

Yes, a symbol can have both OwnValuesown-values and DownValuesdown-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

###OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set an OwnValuea own-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

DownValue first

###DowValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an OwnValueown-value and a DownValuedown-value, but look what happens when x[42] is evaluated.

x[42] 

x[42]

42[42]

This happens because, under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at OwnValueown-vales first and finds one. It uses that OwnValueown-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a DownValuedown-value of x because it doesn't need to.

Yes, a symbol can have both OwnValues and DownValues, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

###OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set an OwnValue, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

DownValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an OwnValue and a DownValue, but look what happens when x[42] is evaluated.

x[42] 

42[42]

This happens because, under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at OwnValue first and finds one. It uses that OwnValue to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a DownValue of x because it doesn't need to.

Yes, a symbol can have both own-values and down-values, but it is usually bad practice to give a symbol both. Further, the order in which they are created matters, but there are problems both ways.

###OwnValue first

y = 42; OwnValues @ y 

{HoldPattern[y] :> 42}

But now you can't set a own-value, because

y[42] = 0 

Set::write: Tag Integer in 42[42] is Protected.
0

DownValues @ y 

{}

###DowValue first

x[42] = 0; DownValues @ x 

{HoldPattern[x[42]] :> 0}

x = 42; OwnValues @ x 

{HoldPattern[x] :> 42}

The symbol x has both an own-value and a down-value, but look what happens when x[42] is evaluated.

x[42]

42[42]

This happens because under normal evaluation rules, Mathematica evaluates the head x of x[42] before anything else. When evaluating a symbol such as x, it looks at own-vales first and finds one. It uses that own-value to replace x with 42. It next evaluates the parts (arguments) of expression and of course gets 42, and so x[42] evaluates to 42[42]. Mathematica doesn't look for a down-value of x because it doesn't need to.

Fixed minor typos, gramma: DowValue -> DownValue, down-value -> DownValue, etc.
Source Link
Loading
Added further explanation
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263
Loading
Corrected typos
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263
Loading
deleted 3 characters in body
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263
Loading
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263
Loading