Home » U++ Library support » U++ Library : Other (not classified elsewhere) » IdeCalc -- ERROR: void.sin(): (0,15): 'sin' is not a lambda
IdeCalc -- ERROR: void.sin(): (0,15): 'sin' is not a lambda [message #47341] |
Thu, 05 January 2017 14:16  |
 |
deep
Messages: 266 Registered: July 2011 Location: Bangalore
|
Experienced Member |
|
|
Hi,
Trying to use IDE Calculator function.
When I use IDE Calculator in IDE. (Ctrl+e) I get following result.
$A=100
100 0x64 "d"
$B=32.5
32.5
$A+B*(32-56/2)
230 0xe6 "æ"
$C=A+B*sin(3.0)
104.5864
But when I use same code from uppsrc/ide/Calc.cpp in my program I get following result.
It gives ERROR: void.sin(): (0,15): 'sin' is not a lambda for sin() function.
A=100 -- Result -- 100
B=32.5 -- Result -- 32.5
A+B*(32-56/2) -- Result -- 230
C=A+B*sin(3.0) -- Result -- ERROR: void.sin(): (0,15): 'sin' is not a lambda
Code used, ESC Package to be added to Package
What changes in code required to process trigonometric functions correctly. Is working code
This is code taken from uppsrc/ide/Calc.cpp
#include <Core/Core.h>
#include <Esc/Esc.h>
using namespace Upp;
ArrayMap<String, EscValue> vars;
ArrayMap<String, EscValue>& UscGlobal()
{
static ArrayMap<String, EscValue> global;
return global;
}
void Calc(String exp)
{
String txt;
try {
ArrayMap<String, EscValue>& g = UscGlobal();
for(int i = 0; i < g.GetCount(); i++)
vars.GetAdd(g.GetKey(i)) = g[i];
if(IsNull(exp))
return;
EscValue v = Evaluatex(exp, vars);
txt = v.ToString();
vars.GetAdd("_") = v;
}
catch(CParser::Error e) {
const char *x = strchr(e, ':');
txt << "ERROR: " << (x ? x + 1 : ~e);
}
LOG(exp << " -- Result -- " << txt);
}
CONSOLE_APP_MAIN
{
StdLib(UscGlobal());
String s = "A=100";
Calc(s);
s = "B=32.5";
Calc(s);
s = "A+B*(32-56/2)";
Calc(s);
s = "C=A+B*sin(3.0)",
Calc( s );
}
WIN10 - visual studio 14.0 - 64 bit.
IDE is compiled from source. Ver 10553
Warm Regards
Deepak
[Updated on: Thu, 05 January 2017 15:17] Report message to a moderator
|
|
|
Re: IdeCalc -- ERROR: void.sin(): (0,15): 'sin' is not a lambda [message #47344 is a reply to message #47341] |
Thu, 05 January 2017 15:15  |
 |
deep
Messages: 266 Registered: July 2011 Location: Bangalore
|
Experienced Member |
|
|
Hi,
Answer to my question.
To use standard functions UscGlobal needs init.
It is done like this at the beginning of the code.
StdLib(UscGlobal());
It will init ArrayMap with all StdLib Functions
is_number
is_array
is_map
is_void
int
to_string
to_number
count
keys
values
rand
reverse
sort
order
replace
ToUpper
ToLower
len
mid
exists
OpenFileOut
OpenFileAppend
OpenFileIn
GetSysTime
IsDate
IsTime
sin
cos
tan
asin
acos
atan
sinh
cosh
tanh
asinh
acosh
atanh
exp
log
log10
exp2
log2
sqrt
cbrt
pow
atan2
Warm Regards
Deepak
|
|
|
Goto Forum:
Current Time: Fri Apr 25 12:21:43 CEST 2025
Total time taken to generate the page: 0.00996 seconds
|