<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, Function as a parameter in proc</title>
    <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Sat, 13 Jun 2026 20:06:04 GMT</lastBuildDate>
    <pubDate>Sat, 13 Jun 2026 20:06:04 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, Function as a parameter in proc</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, Function as a parameter in proc</title>
      <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc</link>
    </image>
    <item>
      <title>two solutions</title>
      <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc?ref=Feed:MaplePrimes:Function as a parameter in proc:Comments#answer76175</link>
      <itunes:summary>

test:=proc(h)
 unapply(h,x)(1.1)
end proc;

test(x^3);

# Another solution:

test:=proc(h)
  eval(h,op(indets(h))=1.1)
end proc;

test(t^3);
</itunes:summary>
      <description>

test:=proc(h)
 unapply(h,x)(1.1)
end proc;

test(x^3);

# Another solution:

test:=proc(h)
  eval(h,op(indets(h))=1.1)
end proc;

test(t^3);
</description>
      <guid>76175</guid>
      <pubDate>Tue, 31 Jul 2007 16:04:34 Z</pubDate>
      <itunes:author>djc</itunes:author>
      <author>djc</author>
    </item>
    <item>
      <title>second is better</title>
      <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc?ref=Feed:MaplePrimes:Function as a parameter in proc:Comments#answer76174</link>
      <itunes:summary>That second approach is so much better than the first, djc, if I might offer an opinion.

Consider that Sandor used the term "function", and yet the example clearly shows an expression not any function. Indeed, if he had not used the term function, you might well have not considered that first solution at all. :)

And good job on using eval(). There's been a bit too much suggestion to use subs(), when 2-argument eval() is what's called for, around here. It does appear that Sandor is after mathematical evaluation, and not substituton into a structure.

acer</itunes:summary>
      <description>That second approach is so much better than the first, djc, if I might offer an opinion.

Consider that Sandor used the term "function", and yet the example clearly shows an expression not any function. Indeed, if he had not used the term function, you might well have not considered that first solution at all. :)

And good job on using eval(). There's been a bit too much suggestion to use subs(), when 2-argument eval() is what's called for, around here. It does appear that Sandor is after mathematical evaluation, and not substituton into a structure.

acer</description>
      <guid>76174</guid>
      <pubDate>Tue, 31 Jul 2007 16:27:10 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>suggestions</title>
      <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc?ref=Feed:MaplePrimes:Function as a parameter in proc:Comments#answer76173</link>
      <itunes:summary>Neither approach is particularly, or even approximately, robust.  As a minimum, you would want to restrict the indeterminates returned by indets to names, otherwise it will fail with, say, sin(x).  Slightly better would be to also eliminate constants, so that, for example, Pi doesn't get returned.   I'd also check for a single indeterminate.  Hence something like
&lt;pre&gt;
test := proc(h)
local vars;
   vars := indets(h,'And(name,Not(constant))');
   if nops(vars) &amp;gt; 1 then
      error "too many indeterminates";
   elif vars = {} then
      error "no indeterminates";
   end if;
   eval(h, op(vars)=1.1)
end proc:
&lt;/pre&gt;
If the indeterminate name is already known, which I suspect is the case, then unapply is the way to go.</itunes:summary>
      <description>Neither approach is particularly, or even approximately, robust.  As a minimum, you would want to restrict the indeterminates returned by indets to names, otherwise it will fail with, say, sin(x).  Slightly better would be to also eliminate constants, so that, for example, Pi doesn't get returned.   I'd also check for a single indeterminate.  Hence something like
&lt;pre&gt;
test := proc(h)
local vars;
   vars := indets(h,'And(name,Not(constant))');
   if nops(vars) &amp;gt; 1 then
      error "too many indeterminates";
   elif vars = {} then
      error "no indeterminates";
   end if;
   eval(h, op(vars)=1.1)
end proc:
&lt;/pre&gt;
If the indeterminate name is already known, which I suspect is the case, then unapply is the way to go.</description>
      <guid>76173</guid>
      <pubDate>Tue, 31 Jul 2007 18:53:38 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>not really my point</title>
      <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc?ref=Feed:MaplePrimes:Function as a parameter in proc:Comments#answer76171</link>
      <itunes:summary>Why use all the heavy machinery of function-creation, to do a mere evaluation of an expression? It's not known whether the procedure will do evaluations of the expression at many points, or whether the procedure itself might be called for many distinct expressions. One could probably construct examples where each were "worthwhile".

Argument checking is good to add, of course. Almost every example procedure posted here on mapleprimes could do with more robust validation of arguments. A user who does not understand that an expression is not a maple function probably will find the simplest example most clear to begin with.

My point was that using eval() is likely what the poster should use here, as opposed to subs(). And I would suggest that the original poster appeared unclear as to whether x^2 were an expression or a function. It is good of the first responder to show the difference, as far as evaluation goes.

acer</itunes:summary>
      <description>Why use all the heavy machinery of function-creation, to do a mere evaluation of an expression? It's not known whether the procedure will do evaluations of the expression at many points, or whether the procedure itself might be called for many distinct expressions. One could probably construct examples where each were "worthwhile".

Argument checking is good to add, of course. Almost every example procedure posted here on mapleprimes could do with more robust validation of arguments. A user who does not understand that an expression is not a maple function probably will find the simplest example most clear to begin with.

My point was that using eval() is likely what the poster should use here, as opposed to subs(). And I would suggest that the original poster appeared unclear as to whether x^2 were an expression or a function. It is good of the first responder to show the difference, as far as evaluation goes.

acer</description>
      <guid>76171</guid>
      <pubDate>Tue, 31 Jul 2007 19:12:00 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>function, expression</title>
      <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc?ref=Feed:MaplePrimes:Function as a parameter in proc:Comments#answer76170</link>
      <itunes:summary>Probably I caused a bit confusion. Sorry. 
Thanks for your valuable answers.
Acer, is right. I meant expression (which defines a math function).
Joe, the indeterminate name is not known, it is the choice of a user.
Here I consider only one-variable (math) functions (=expressions). Later, maybe, I want to consider vector or multi-variable (math) functions (=expressions).
And I want to allow the constant math functions, also, so if Pi gets 
returned, then it is good. 
 I will investigate your suggestions.
Acer, "It's not known whether the procedure will do evaluations of the expression at many points" .  This is the situation.
Knowing these, what is your advice?</itunes:summary>
      <description>Probably I caused a bit confusion. Sorry. 
Thanks for your valuable answers.
Acer, is right. I meant expression (which defines a math function).
Joe, the indeterminate name is not known, it is the choice of a user.
Here I consider only one-variable (math) functions (=expressions). Later, maybe, I want to consider vector or multi-variable (math) functions (=expressions).
And I want to allow the constant math functions, also, so if Pi gets 
returned, then it is good. 
 I will investigate your suggestions.
Acer, "It's not known whether the procedure will do evaluations of the expression at many points" .  This is the situation.
Knowing these, what is your advice?</description>
      <guid>76170</guid>
      <pubDate>Wed, 01 Aug 2007 00:45:24 Z</pubDate>
      <itunes:author>SandorSzabo</itunes:author>
      <author>SandorSzabo</author>
    </item>
    <item>
      <title>nor mine</title>
      <link>http://www.mapleprimes.com/questions/41046-Function-As-A-Parameter-In-Proc?ref=Feed:MaplePrimes:Function as a parameter in proc:Comments#comment85213</link>
      <itunes:summary>Yes, I realized that shortly after posting.  Thanks for clarifying.  I was interested in what the poster asked for (generating a procedure from an expression), not what he meant (evaluating an expression at a point).   As you say, eval is the way to evaluate an expression at a point, usually better than subs and much better than unapply followed by application.  The point of my response was mainly pedalogical, to show how to restrict the values returned by indets to those of interest.</itunes:summary>
      <description>Yes, I realized that shortly after posting.  Thanks for clarifying.  I was interested in what the poster asked for (generating a procedure from an expression), not what he meant (evaluating an expression at a point).   As you say, eval is the way to evaluate an expression at a point, usually better than subs and much better than unapply followed by application.  The point of my response was mainly pedalogical, to show how to restrict the values returned by indets to those of interest.</description>
      <guid>85213</guid>
      <pubDate>Tue, 31 Jul 2007 19:31:26 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
  </channel>
</rss>