return 'sum' from a function like '(x) => sum=0; for(i=1;i<=x;i++) sum+=i; sum;'
See original GitHub issueHi!
Is it siomehow possible to return a specific value from a function defined in Mages, i.e. if i define a function
var myfunc = engine.Interpret("(x) => x*2");
var result = myfunc.Invoke(new Object[] { 7.0 });
then i get 14.0. fine!
but if i’ve got a ‘method’-like function(*1) like:
var myfunc = engine.Interpret("(x) => sum=0; for(i=1;i<=x;i++) sum+=i; sum;");
var result = myfunc.Invoke(new Object[] { 100 });
I’d expect that the call returns 5050. but it’s returning 100.
interpreting (i.e. engine.Interpret(…))
var result = engine.Interpret("sum=0; for(i=1;i<=100;i+=1) {sum+=i;} sum;");
returns 5050.
is it somehow possible to return ‘sum’ from the above defined function *1)?
more info: it returns 100 if there is no variable “sum” defined in Engine.Scope otherwise it returns the value of “sum” (if it is defined in Engine.Scope)
thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python function "sum" with syntax like: sum() -> 0 sum(1)(2) ...
The built-in sum just takes an iterable and returns a number, which feels much less surprising. However, assuming that you are certain you ......
Read more >Python's sum(): The Pythonic Way to Sum Values
In this step-by-step tutorial, you'll learn how to use Python's sum() function to add numeric values together. You also learn how to concatenate...
Read more >sum() function in Python
Sum () Function in Python Syntax sum(a) : a is the list , it adds up all the numbers in the list a...
Read more >Various ways to sum numbers in Python
The sum() function returns the sum of all items in an iterable. It is a Python built-in function. There are various methods to...
Read more >SUMIF function
To sum cells based on multiple criteria, see SUMIFS function. Important: The SUMIF function returns incorrect results when you use it to match...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks Florain, using “var” does the trick 😃 and BTW: Kudos to MAGES! It’s awesome!!!
Cool! Glad you like it!