eval

Equivalent of python eval in Haskell

前提是你 提交于 2019-12-03 03:03:39
There is function in python called eval that takes string input and evaluates it. >>> x = 1 >>> print eval('x+1') 2 >>> print eval('12 + 32') 44 >>> What is Haskell equivalent of eval function? It is true that in Haskell, as in Java or C++ or similar languages, you can call out to the compiler, then dynamically load the code and execute it. However, this is generally heavy weight and almost never why people use eval() in other languages. People tend to use eval() in a language because given that language's facilities, for certain classes of problem, it is easier to construct a string from the

Undefined reference to yyparse (flex & bison)

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm attempting to learn some flex/bison, and I'm reading Flex & Bison by John Levine (O'Reilly). There is an example that I need to get running, however I can't get it to run as I get the following error: /tmp/ccKZcRYB.o: In function `yylex': fb3-1.lex.c:(.text+0x2bd): undefined reference to `yylval' /tmp/cclBqnOk.o: In function `main': fb3-1funcs.c:(.text+0x420): undefined reference to `yyparse' collect2: ld returned 1 exit status I've got four source files: fb3-1.h : /* * Declarations for calculator fb3-1 */ /* Interface to the lexer */

Failed to catch syntax error python [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: SyntaxError inconsistency in Python? 2 answers try: x===x except SyntaxError: print "You cannot do that" outputs x===x ^ SyntaxError: invalid syntax this does not catch it either try: x===x except: print "You cannot do that" Other errors like NameError, ValueError, are catchable. Thoughts? System specs: import sys print(sys.version) -> 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] 回答1: You can only catch SyntaxError if it's thrown out of an eval or exec

What's the main benefit of using eval() in JavaScript?

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I know this may be a newbie question, but I'm curious as to the main benefit of eval() - where would it be used best? I appreciate any info. 回答1: The eval function is best used: Never. It's purpose is to evaluate a string as a Javascript expression. Example: eval('x = 42'); It has been used a lot before, because a lot of people didn't know how to write the proper code for what they wanted to do. For example when using a dynamic name for a field: eval('document.frm.'+frmName).value = text; The proper way to do that would be: document.frm

eval SyntaxError: invalid syntax in python

匿名 (未验证) 提交于 2019-12-03 02:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to assign : x0='123' x1='123' x2='123' x3='123' x4='123' x5='123' x6='123' x7='123' x8='123' x9='123' I write the code to express that i can get the output of a string 123 when input x1 or x8 . for i in range(0,10): eval("x"+str(i)+"='123'") Traceback (most recent call last): File " ", line 2, in File " ", line 1 x0='123' ^ SyntaxError: invalid syntax How i can do that way? 回答1: For dynamic execution of statements use exec statement. >>> exec('y=3') >>> y 3 Eval Usgae: eval(expression) The expression argument is parsed and evaluated

Evaluate dice rolling notation strings

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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

Convert strings of list to list of integers inside a list

匿名 (未验证) 提交于 2019-12-03 02:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a list of strings and those strings are lists. Like this: ['[1,2,3]','[10,12,5]'] , for example. I want to get a list of lists or even every list there: [[1,2,3],[10,12,5]] 回答1: You should use literal_eval to get actual list object from string . >>> from ast import literal_eval >>> data = ['[1,2,3]','[10,12,5]'] >>> data = [literal_eval(each) for each in data] >>> data [[1, 2, 3], [10, 12, 5]] literal_eval safely evaluates each object. >>> help(literal_eval) Help on function literal_eval in module ast: literal_eval(node_or_string)

Excel VBA evaluate formula from another sheet

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Solved: The problem is in my formula where I'm referencing a cell using INDIRECT() which doesn't work when sheet is different. See answer. I have a formula in one sheet and what I want to do is to use the formula from another sheet, using eval to evaluate the formula. However, the result is not as intended. It seems like the formula is using values at Sheet A instead of the caller Sheet B. Formula in sheet A (See: Screenshot Sheet A ) =IF(ISERROR(INDEX('1516Activity'!$B:$B,MATCH(INDIRECT(ADDRESS(ROW(),COLUMN(D:D) )),'1516Activity'!$C:$C,0)))

Simply typed lambda calculus with failure, in Haskell

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm a newcomer to Haskell, so apologies if this question doesn't make too much sense. I want to be able to implement simply typed lambda expressions in Haskell in such a way that when I try to apply an expression to another of the wrong type, the result is not a type error, but rather some set value, e.g. Nothing. At first I thought using the Maybe monad would be the right approach, but I've not been able to get anything working. I wondered what, if any, would be the correct way to do this. The context of the problem, if it helps, is a

Eval alternative

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This code works as a calculator, but the scratch pad at codeacademy tells me that eval is evil. Is there another way to do the same thing without using eval? var calculate = prompt("Enter problem"); alert(eval(calculate)); 回答1: eval evaluates the string input as JavaScript and coincidentally JavaScript supports calculations and understands 1+1 , which makes it suitable as a calculator. If you don't want to use eval , which is good, you have to parse that string yourself and, finally, do the computation yourself (not exactly yourself though).