Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #2014 > unrolled thread
| Started by | Heike Gramberg <heike.gramberg@gmail.com> |
|---|---|
| First post | 2011-05-01 10:20 +0000 |
| Last post | 2011-05-01 10:20 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: HoldAll/HoldRest Heike Gramberg <heike.gramberg@gmail.com> - 2011-05-01 10:20 +0000
| From | Heike Gramberg <heike.gramberg@gmail.com> |
|---|---|
| Date | 2011-05-01 10:20 +0000 |
| Subject | Re: HoldAll/HoldRest |
| Message-ID | <ipjc5m$iv5$1@smc.vnet.net> |
When you evaluate valueQ[x], x gets evaluated before it's plugged into the function definition, so you're effectively evaluating If[ValueQ[5],5,False] which returns False. To get the right behaviour, you could use Unevaluated, e.g. valueQ[Unevaluated[x]] You could also add the Attribute HoldAll to valueQ SetAttributes[valueQ,HoldAll]; valueQ[x] out: 5 Heike. On 29 Apr 2011, at 12:33, Scot T. Martin wrote: > Some kind of issue going on here between the interactions of HoldAll of ValueQ[...] and HoldRest of If[...]. Anyone know the solution so that Out[3] results in True? > > > In[1]:= valueQ = If[ValueQ[#], #, False] & > > > > Out[1]= If[ValueQ[#1], #1, False] & > > > > In[2]:= x = 5 > > > > Out[2]= 5 > > > > In[3]:= valueQ[5] > > > > Out[3]= False
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web