12

1

I would like to decide whether an option passed to my custom function has the value `Automatic`

or something else. This is my attempt:

```
f[x_, OptionsPattern[{DataRange -> Automatic}]]:=
Module[{opt = OptionValue[DataRange]},{x, If[opt == Automatic, True, opt]}];
```

However,

```
f[x, DataRange -> 20]
```

produces

```
{x, If[20 == Automatic, True, opt$540]}
```

rather than the expected

```
{x, 20}
```

What do I need to change?

2

`SameQ`

of two finite-precision numbers also applies a tolerance; it's just less than that applied by`Equal`

. So it isn't strictly correct to say that`SameQ`

returns`True`

if and only if the expressions are identical. (Also, one can override`SameQ`

, but if you use`TrueQ`

here that is no longer an issue, and the difference between`Equal`

and`SameQ`

is then a moot point.) – Oleksandr R. – 2012-07-28T01:13:05.380@OleksandrR. Is that not the case only for arbitrary precision numbers? If I recall, it considers them to be identical only if they're not

`MachinePrecision`

and differ only in the last bit. – rm -rf – 2012-07-28T01:35:38.893@R.M Problem solved! Thanks! – groovybaby – 2012-07-28T05:28:48.703

1As an alternative, one could also do

`If[opt == Automatic, True, opt, opt]`

for cases where`==`

does not evaluate – rm -rf – 2012-07-30T14:46:30.357@R.M yes, that's right. I would however consider it reasonable to overload

`SameQ`

if different concepts of sameness are needed (which could of course give arbitrary results), whereas`TrueQ`

is a binary distinction that cannot readily admit any other meanings. In this case one could equally well use the fourth argument of`If`

, which is perhaps more succinct than adding`TrueQ`

. – Oleksandr R. – 2012-08-03T13:30:29.673