MathGroup Archive 1996

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

Search the Archive

Evaluation control in Switch

  • To: mathgroup at
  • Subject: [mg4913] Evaluation control in Switch
  • From: sch at (Stu Schaffner)
  • Date: Fri, 4 Oct 1996 00:17:47 -0400
  • Organization: The MITRE Corp.
  • Sender: owner-wri-mathgroup at

I am trying to build two-level function evaluations, where a function f[x,y]
is called many times with the same first (say) value and where nontrivial
processing is done on that first value. For example

    twoLevelFunction[ p_?IntegerQ ] := Function[
      Evaluate[ expensiveProg[ p ] * x ]

This works, that is, the Function expression itself is not evaluated but
the expensiveProg is called on the actual value for p.  However, suppose
that I wanted to add parameter type checking on the returned function.
Maybe there are much better ways, but one way is

    twoLevelFunction[ p_?IntegerQ ] := Function[
        _?IntegerQ, expensiveProg[ p ] * x,
        _, 42

If anybody knows a better way to add type checking to pure functions I
would appreciate a hint.  However, it does point up something I don't
know how to do.  How can you force selective evaluation of terms in a
Switch without causing the Switch itself to be evaluated? I've tried
various combinations of Hold and Evaluate without much success.

Stu Schaffner
The MITRE Corp.
sch at


  • Prev by Date: Comparison of Mathematica on Various Computers
  • Next by Date: Re: Re: programming competition
  • Previous by thread: Comparison of Mathematica on Various Computers
  • Next by thread: Re: functional code