expression-evaluation

Idris eager evaluation

瘦欲@ 提交于 2019-12-04 22:17:06
In Haskell , I might implement if like this: if' True x y = x if' False x y = y spin 0 = () spin n = spin (n - 1) This behaves how I expect : haskell> if' True (spin 1000000) () -- takes a moment haskell> if' False (spin 1000000) () -- immediate In Racket , I could implement a flawed if like this: (define (if2 cond x y) (if cond x y)) (define (spin n) (if (= n 0) (void) (spin (- n 1)))) This behaves how I expect : racket> (if2 #t (spin 100000000) (void)) -- takes a moment racket> (if2 #f (spin 100000000) (void)) -- takes a moment In Idris , I might implement if like this: if' : Bool -> a -> a

++i+i++ evaluation

╄→尐↘猪︶ㄣ 提交于 2019-12-04 16:02:00
问题 Confusion rose because of this post. The author updated his post, and the result became clear. Conclusion: Java evaluates expressions from left to right Closed! As evaluation of expression is done from right to left the following code should store 5 in j : int i=2; int j=++i+i++; System.out.println(j); But I get 6 as the output, which forces me to re-think the right to left evaluation idea. Kindly explain the theory here. 回答1: int i = 2; int j = ++i + i++; is the same as int i = 2; // This

How to add a new function to Ncalc

﹥>﹥吖頭↗ 提交于 2019-12-03 21:54:54
I'm using Ncalc in my new project and it already has almost everything I need . I said almost everything, because now I need to expand some functions and also add new ones such as : nth root,random, etc Do you know if anyone has already implemented those functions? Or could you give me any tips or guides to extend the function list of Ncalc??? Thanks in advance. If I understand correctly: As much as I was using it is by creating a static function private static void NCalcExtensionFunctions(string name, FunctionArgs functionArgs) { if (name == "yourfunctionname") { var param1 = functionArgs

++i+i++ evaluation

喜夏-厌秋 提交于 2019-12-03 09:13:39
Confusion rose because of this post . The author updated his post, and the result became clear. Conclusion: Java evaluates expressions from left to right Closed! As evaluation of expression is done from right to left the following code should store 5 in j : int i=2; int j=++i+i++; System.out.println(j); But I get 6 as the output, which forces me to re-think the right to left evaluation idea. Kindly explain the theory here. int i = 2; int j = ++i + i++; is the same as int i = 2; // This part is from ++i i = i + 1; int left = i; // 3 // This part is from i++ int right = i; // 3 i = i + 1; int j

Evaluate dice rolling notation strings

牧云@^-^@ 提交于 2019-12-03 02:02:14
问题 Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation, including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive integer], "d", positive integer entity ::= roll | positive number expression ::= entity { [, whitespace], "+"|"*"[, whitespace], entity } Example inputs: "3d6 + 12" "4*d12 + 3" "d100" Using eval functions, or similar, is not forbidden, but I

Need guidance towards evaluative boolean logic tree

拟墨画扇 提交于 2019-12-03 00:14:43
I can't seem to find a pointer in the right direction, I am not even sure what the terms are that I should be researching but countless hours of googling seem to be spinning me in circles, so hopefully the collective hive of intelligence of Stack Overflow can help. The problem is this, I need a way to filter data in what I can only call a compound logic tree. Currently the system implements a simple AND filtering system. For example, lets say we have a dataset of people. You add a bunch of filters such that show all the people where (Sex = Female) AND (Age > 23) AND (Age < 30) AND ( Status =

Evaluate dice rolling notation strings

坚强是说给别人听的谎言 提交于 2019-12-02 15:38:31
Rules Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation , including addition and multiplication. To clear the things up, here comes EBNF definition of legal expressions: roll ::= [positive integer], "d", positive integer entity ::= roll | positive number expression ::= entity { [, whitespace], "+"|"*"[, whitespace], entity } Example inputs: "3d6 + 12" "4*d12 + 3" "d100" Using eval functions, or similar, is not forbidden, but I encourage to solving without using these. Re-entrancy is welcome. I cannot provide test-cases, as output

Recursive expression evaluator using Java

旧城冷巷雨未停 提交于 2019-11-30 18:47:32
I am going to write an expression evaluator which only does addition and subtraction. I have a simple algorithm to do that; but, I have some implementation problems. I considered an expression as (it is a String) "(" <expression1> <operator> <expression2> ")" Here is my algorithm String evaluate( String expression ) if expression is digit return expression else if expression is "(" <expression1> <operator> <expression2> ")" cut the brackets out of it expression1 = evaluate( <expression1> ) operator = <operator> expression2 = evaluate( <expression2> ) if operator is + expression1 + expression2

Evaluate() in VBA

旧城冷巷雨未停 提交于 2019-11-30 13:03:04
问题 Hi and welcome to the Evaluate() mystery The MSDN Office Developer Reference (2013) Documentation says: Using square brackets (for example, "[A1:C5]") is identical to calling the Evaluate method with a string argument. So, I have ran a very simple code to see how accurate the Microsoft's Documentation of the Evaluate() method is. Not surprisingly, I am getting a strange albeit consistent result. note: execute each of the 4 commands in the Immediate Window CTRL + G . See the difference in each

C++ and PHP vs C# and Java - unequal results

泪湿孤枕 提交于 2019-11-30 10:49:47
I found something a little strange in C# and Java. Let's look at this C++ code: #include <iostream> using namespace std; class Simple { public: static int f() { X = X + 10; return 1; } static int X; }; int Simple::X = 0; int main() { Simple::X += Simple::f(); printf("X = %d", Simple::X); return 0; } In a console you will see X = 11 ( Look at the result here - IdeOne C++ ). Now let's look at the same code on C#: class Program { static int x = 0; static int f() { x = x + 10; return 1; } public static void Main() { x += f(); System.Console.WriteLine(x); } } In a console you will see 1 (not 11!)