Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Do we need a When function?
Replies: 9   Last Post: Mar 23, 2014 5:01 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
David Bailey

Posts: 714
Registered: 11/7/08
Re: Do we need a When function?
Posted: Mar 13, 2014 3:11 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.