Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2011 > unrolled thread

Re: thoughts on how to explain this functionality?

Started byAndrzej Kozlowski <akoz@mimuw.edu.pl>
First post2011-05-01 10:22 +0000
Last post2011-05-01 10:22 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: thoughts on how to explain this functionality? Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-05-01 10:22 +0000

#2011 — Re: thoughts on how to explain this functionality?

FromAndrzej Kozlowski <akoz@mimuw.edu.pl>
Date2011-05-01 10:22 +0000
SubjectRe: thoughts on how to explain this functionality?
Message-ID<ipjc9n$j2e$1@smc.vnet.net>
On 30 Apr 2011, at 11:51, Scot T. Martin wrote:

> In[1]:= x = 5
>
> Out[1]= 5
>
>
> In[2]:= With[{valueQ = If[ValueQ[ReleaseHold[Hold[#]]], #, False] &}, valueQ@x]
>
> Out[2]= 5
>
>
> In[3]:= With[{valueQ = If[ValueQ[#], #, False] &}, valueQ@x]
>
> Out[3]= False
>
>
> Anyone have thoughts on why Out[2] and Out[3] are different?
>
> It seems to me that a ReleaseHold[Hold[...]] formulation would net out to no effect, yet the effect is apparent.
>
> My desired output is Out[2] but the formulation of ReleaseHold[Hold[...]] is not elegant.

The point is that ValueQ has the HoldAll attribute, but your valueQ does not. You can give it the HoldAll attribute like this:

With[{valueQ =
   Function[x, If[ValueQ[x], x, False], HoldAll]}, valueQ@x]

5

Note also that your ReleaseHold approach does not really work (it only seems so). Just compare what happen when you try it on a symbol y which has no value assigned to it:

 With[{valueQ = If[ValueQ[ReleaseHold[Hold[#]]], #, False] &},
  valueQ@y]

 y

By contrast:

With[{valueQ =
   Function[x, If[ValueQ[x], x, False], HoldAll]}, valueQ@y]

False

Your approach will never return False for it does not really do what you intended it to do (I think).

Andrzej Kozlowski


[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web