19
$\begingroup$

In this Wolfram talk video titled "Professor Richard J. Gaylord's Wolfram Language Fundamentals Part Two" he shows at time 36:45 the following

enter image description here

Where there are two definitions for w one after that other, then he says that both are entered in the global rules database and then when one is called, the first is called as you see from the screen shot above.

I thought this was strange, because when I tried it on V 13.1, only one definition was entered into the global rules database:

enter image description here enter image description here

The video is from 2014. So look like it was around version 10 of Mathematica.

My question is: When did this change happen? And is it documented? Notice that different result is obtained than what shows in the video.

code

ClearAll[w,x]
w[x_]:=x^4
w[_]:=RandomReal[]
$\endgroup$

1 Answer 1

16
$\begingroup$

With Mathematica 5.2 I reproduce the behavior from the talk:

screenshot

But with version 6.0 we do not:

screenshot2

So the change happened in 6.0.

$\endgroup$
7
  • $\begingroup$ Is this desired behavior? $\endgroup$
    – QuantumDot
    Sep 2, 2022 at 1:47
  • 6
    $\begingroup$ @QuantumDot I think so. The previous behavior looks like a bug. $\endgroup$ Sep 2, 2022 at 2:07
  • 5
    $\begingroup$ @QuantumDot - there is no expression that would not match x_ but does match _. So in the original output from the image in the OP, there are two definitions given for ?w but the second would never come into play. To me it seems like a good change, a bug fix really. (edit: my browser says alexey beat me to this by 20 seconds) $\endgroup$
    – Jason B.
    Sep 2, 2022 at 2:08
  • 3
    $\begingroup$ I take the liberty to add the testing result, feel free to rollback if you don't like it :) . $\endgroup$
    – xzczd
    Sep 2, 2022 at 2:34
  • 3
    $\begingroup$ If you did want to have both definitions for whatever reason, you could assign them this way: DownValues[w] = {HoldPattern[w[x_]] :> x^4, HoldPattern[w[_]] :> RandomReal[]}; $\endgroup$
    – Greg Hurst
    Sep 2, 2022 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.