Question: How to handle unrecognized types and default values with CodeGeneration

Hello,

Im exporting procedures defined in Maple to an external software and was planning to use the CodeGeneration -tools for that. How ever, i encountered quite surprising limitations.

 

First is default value for procedure parameter. The documentation explains that procedure parameter can be set to have a default value with syntax parameterName::type := defaultValue. And indeed, it works:

 

DefaultValueTest := proc(parameterWithDefaultValue::integer:=1)::integer;
	return parameterWithDefaultValue *2;
end proc;
DefaultValueTest();
                               2
DefaultValueTest(2);
                               4

However, apparently the CodeGenerator -package cannot handle it.

CSharp(DefaultValueTest);
Error, (in CodeGeneration:-IssueError) cannot translate initial value

This is not related to the chosen language, it wont work with Java or JavaScript translation either. Without the default value the generated code looks like this, as expected:

CSharp(DefaultValueTest);
public class CodeGenerationClass {
  public static System.Int32 DefaultValueTest (System.Int32 parameterWithDefaultValue)
  {
    return 2 * parameterWithDefaultValue;
  }
}

Whats up with this? Many if not all the CodeGeneration languages support default parameter value for function. In C# it would obviously be 

public static System.Int32 DefaultValueTest (System.Int32 parameterWithDefaultValue=1)

 

 

Another one is the type support. I was quite surprised that boolean type works fine in Maple but the codegeneration translation cannot handle it. For example:

Booltest := proc(boolVal::boolean)::integer;
	if ( boolVal = true ) then
		return 1;
	end if;
	
	return 0;
end proc;

Works fine in the maple.

Booltest(true);
                               1
Booltest(false);
                               0

But when ran trough the code generator:

CSharp(Booltest);
Warning, cannot translate type boolean, using default type
Error, (in CodeGeneration:-IssueError) cannot resolve types in {boolean, numeric}

Apparently, since the documentation says that if CodeGeneration doesn't recognize the type, it uses default type, which in this case is numeric, it cannot do the evaluation in the if clause ( numeric and boolean true ).

So if we change the if condition to a shorthand version:

if ( boolVal ) then

The csharp transpiled code looks like 

CSharp(Booltest);
Warning, cannot translate type boolean, using default type
public class CodeGenerationClass {
  public static System.Int32 Booltest (System.Double boolVal)
  {
    if (boolVal)
      return 1;
    return 0;
  }
}

 

Every languange in the codegeneration package has boolean type. So shouldn't there be a variable type bool in the translator/transpiler as well?

 

Is there a way around these problems? Are there plans on expanding the codegeneration/transpiler ruleset to cover these rather basic cases? 

 

 

 

 

 

Please Wait...