Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4022296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:27:27+00:00 2026-05-20T10:27:27+00:00

In Maple (version 14, if it matters), I define a procedure that uses a

  • 0

In Maple (version 14, if it matters), I define a procedure that uses a globally-defined expression in maple, but when I go to code generation, it assumes the variable is not what I am expecting.

a:=x+y*x
p := proc (x::float, y::float); return a; end proc;
C(p)

What I expect is a C function with the expression inserted into the code, but instead I get…

double p (double x, double y)
{
  return(a);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:27:27+00:00Added an answer on May 20, 2026 at 10:27 am

    This is one of those ‘by design’ things. Even though it may seem awkward to you in this particular situation, this lexical scoping behaviour on (modern) Maple’s part is more often an advantage and is quite deliberate. And there are several ways around it, to get your expectation.

    The simplest workaround, in this case, might be just this:

    restart:
    a:=x+y*x:
    p := proc(x::float, y::float) return a; end proc;
    
              p := proc(x::float, y::float) return a end proc;
    
    CodeGeneration:-C( subs('a'=a,eval(p)) );
    
      double cg (double x, double y)
      {
         return(x + y * x);
      }
    

    What is accomplished above is that subs('a'=a,eval(p)) forms a new instance of the proc p in which a is replaced in the proc body by the explicit value of a (ie. what a evaluates to). Note the output of the following, and compare with the output above when p was initially created,

    subs('a'=a,eval(p));
    
       proc(x::float, y::float) return x + y*x end proc;
    

    Keep in mind that, even though it’s not apparent in this very simple workaround example, the given substitution for the global names x and y into that copy of p is actually playing a tricky game with Maple’s scoping rules. In more complicated scoping situations this might go amok. But if what you really want is inlining, then you can get that in more explicit and controlled ways. Look at the echoed output of p when initially created in this next example,

    restart:
    a := proc(A,B) option inline; A+B*A: end proc;
              a := proc(A, B) option inline; A + B*A end proc;
    
    p := proc(x::float, y::float) return a(x,y); end proc;
           p := proc(x::float, y::float) return x + y*x end proc;
    
    CodeGeneration:-C( p );
    
       double p (double x, double y)
       {
         return(x + y * x);
       }
    

    Hopefully, those two approaches are enough to see you through.

    Let’s briefly return to your original example, just to notice something. The global names x and y as they appear in the value of a are very much not the same as the names of the two formal parameters of the initially created procedure p. They are quite different instances of what merely appear to be the same name. Consider,

    restart:
    a:=x+y*x:
    
    p := proc(x::float, y::float) return a; end proc;
    
              p := proc(x::float, y::float) return a end proc;
    
    p(4.0, 5.0);
                                   x + y x
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that has several build configurations (FREE version, male-only, female-only, etc.).
I see no problem in the code. Help? preferences.xml <?xml version=1.0 encoding=utf-8?> <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android>
Consider the following script for outputting some XML code: var xmlAsString = '<?xml version=1.0?><person><name
I keep getting that error. Here's the code (it's for GCD): Euc := proc
How to input such system into maple so that it would solve it? BTW
So I want to share some of my maple code files with world. I
I have an ORU R01 version 2.4 message that I'm trying to get through,
I just received this VBS code that appends a line to my table in
So I am learning MVC3 and EF4. I tried the code first method but
I am trying to get the number of children that a node has but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.