MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Do we need a When function?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132429] Re: Do we need a When function?
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Thu, 13 Mar 2014 03:10:50 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20140308074231.0A4506A0B@smc.vnet.net> <lfjtkc$hhc$1@smc.vnet.net>

On 10/03/2014 08:37, Itai Seggev wrote:> On Sat, Mar 08, 2014 at 02:42:31AM
 >
 > I'm not sure what your use case is.  F[x] will of course stay 
unevluated until
 > x has some value which F knows what to do with...
 >
 > --
 > Itai Seggev
 > Mathematica Algorithms R&D
 > 217-398-0700
 >
A typical use would be an expression like When[NumberQ[x],ToString[x]]

Somehow everyone seems to be missing the point here - of course I can 
solve the problem by writing some code - indeed I gave a solution in my 
original post - but lots of Mathematica functions can be replaced by 
other expressions using more primitive functions, but such functions are 
provided for convenience and expressiveness.

Supplying an expression that only evaluates when some condition is true, 
seems a pretty useful feature.

The difference between If and When, is obvious:

If[NumberQ[x],f[x]]
Null



When[NumberQ[x],f[x]]

When[NumberQ[x],f[x]]

When delays evaluation until is condition is True.

If you want to hold an expression until (and unless) some condition is 
satisfied, When would seem to me to be the most expressive way to write 
this.

David Bailey
http://www.dbaileyconsultancy.co.uk






  • Prev by Date: Re: What's in an expression?
  • Next by Date: Re: MathWorld Utility Packages
  • Previous by thread: Re: Do we need a When function?
  • Next by thread: Re: Do we need a When function?