MathGroup Archive 2008

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

Search the Archive

Writing a HoldAll function that evaluates its arguments

What is the simplest and most elegant way of implementing a function 
that has HoldAll, but it still evaluates each of its arguments exactly 
once (and does not go into infinite evaluation)?

I can come up with some ways (explicitly checking whether evaluation 
changes the arguments), but neither of them are particularly elegant.

The function should evaluate like this:

Attributes[f] === {HoldAll}
f[] --> f[]
f[3] --> f[3]
f[1+2] --> f[3]
f[1,2] --> f[1,2]
f[0+1,1+1] --> f[1,2]

Let me explain my motivation for asking this seemingly absurd question 
with an example:

One built-in function that has this behaviour is And[].  This special 
behaviour was needed to make And[] a "short-circuiting" function:  it 
evaluates the arguments one by one, and it returns False *immediately* 
when one argument evaluates to False, without evaluating any further 


  • Prev by Date: Re: Manipulate
  • Next by Date: Re: Insufficient capacity
  • Previous by thread: Re: v6: Input Cell Word Wrapping: how to set global default?
  • Next by thread: Re: Writing a HoldAll function that evaluates its arguments