Fri Nov 16, 2018 7:54 pm
Login Register Lost Password? Contact Us


using #CONSTANT value in template

Comments and questions related to the Enterprise Control Language

Tue Jul 10, 2018 6:19 pm Change Time Zone

I would think the following should work, but I get the "Constant expression expected" error. Why would max_times not be considered a constant here?

Code: Select all
#CONSTANT('times_Count', 25)

TestFunction() := function

   max_times := 0: stored('times_count');

   #DECLARE(ndx);
   #SET(ndx, 1);

   #LOOP
      #SET(ndx, %ndx% + 1);
      #IF (%ndx% > max_times)
        #BREAK
      #END
   #END

  return %ndx%;

end;


output(TestFunction(), named('result'));
KLB
 
Posts: 3
Joined: Fri Jun 22, 2018 2:16 pm

Wed Jul 11, 2018 6:03 pm Change Time Zone

KLB,

That "Constant expression expected" error is asking for a compile-time constant, not a run-time constant.

Template language generates ECL code, and that generated ECL is then parsed and translated into the appropriate C++ for the job, which is then compiled into the object code that executes on each node.

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1390
Joined: Wed Oct 26, 2011 7:40 pm

Wed Jul 11, 2018 8:04 pm Change Time Zone

Thanks Richard. I think what you said in another thread just made me think it could be used at compile time in Thor...

https://hpccsystems.com/bb/viewtopic.php?f=8&t=1785&p=7841&hilit=%23constant+constant+stored#p7841

When running interactively in Thor, the #STORED takes effect (it's basically a compile-time tool) and you see its value as the result.
KLB
 
Posts: 3
Joined: Fri Jun 22, 2018 2:16 pm

Thu Jul 12, 2018 10:02 am Change Time Zone

I meant to add, what I am really after is a way to include a constant in a BWR that will allow the code that it runs to compile conditionally based on that constant. We don't want to have to modify and sandbox the actual code each time, we'd like to just modify the BWR that runs it. The constant will determine how many times the #LOOP runs. Is that possible?
KLB
 
Posts: 3
Joined: Fri Jun 22, 2018 2:16 pm

Thu Jul 12, 2018 2:48 pm Change Time Zone

KLB,

The short answer is no, the only way to do what you want is to define a constant and edit that constant immediately before you run the BWR. That definition can be separate from the template language code you want to run, but it must be a compile-time constant.

Here's the way I would have written your test function to demonstrate this:
Code: Select all
IMPORT $;
EXPORT TestFunction() := function

   #DECLARE(ndx);
   #SET(ndx, 1);
   #DECLARE(rtn);
   #SET(rtn, '0');

   #LOOP
      #IF (%ndx% > $.max_times)
        #BREAK
      #ELSE
        #APPEND(rtn,',' + %'ndx'% );
      #END
      #SET(ndx, %ndx% + 1);
   #END

  return %'rtn'%;
end;
I added a separate rtn symbol to emulate the code generation that Template language is designed to do. Note that the max_times is now outside the FUNCTION structure and in a separate EXPORT definition:
Code: Select all
EXPORT max_times := 10;
It could be anywhere else in your repository, but I put mine in the same folder as the function. Then the BWR code looks like this:
Code: Select all
IMPORT Test;
//MODIFY test.max_times BEFORE RUNNING THIS
output(test.TestFunction(), named('result'));

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1390
Joined: Wed Oct 26, 2011 7:40 pm


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest