eval

Expression eval(“function(x) { return x*x}”) breaks node.js console

别说谁变了你拦得住时间么 提交于 2019-12-04 04:59:28
问题 When I type something like this in node.js console: var f = eval("function(x) { return x*x}"); It doesn't evaluate the expression and waits for me to type something else. Why is this happening? Why can't I type another expression after this one? 回答1: function(x) { return x*x} is an error (type it in the console to check that), so Node's REPL waits for more. If you want to build and assign the function, you must eval an expression, that is a statement returning a value. The usual solution is

Getting nested obj value

六眼飞鱼酱① 提交于 2019-12-04 04:54:05
问题 Given the following obj: var inputMapping = { nonNestedItem: "someItem here", sections: { general: "Some general section information" } }; I'm writing a function to get that data by passing in a string "nonNestedItem" or in the nested case "sections.general" . I'm having to use an eval and I was wondering if there was maybe a better way to do this. Here is what I have so far and it works okay. But improve! function getNode(name) { var n = name.split("."); if (n.length === 1) { n = name[0]; }

Why is `eval` worse than `str2func` to evaluate a function from a string? [closed]

☆樱花仙子☆ 提交于 2019-12-04 04:28:23
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . I already showed that the performance of str2func is better, but I got a lot of comments stating that there are more fundamental reasons to not use eval . Which fundamental reasons do apply to eval and do not apply to str2func in the following situation: f='a^x+exp(b)+sin(c*x

interpolating values from a dataframe based on a column value

时光怂恿深爱的人放手 提交于 2019-12-04 04:05:27
问题 Assuming I have a the following problem: import pandas as pd import numpy as np xp = [0.0, 0.5, 1.0] np.random.seed(100) df = pd.DataFrame(np.random.rand(10, 4), columns=['x0', 'y1', 'y2', 'y3']) df x0 y1 y2 y3 0 0.5434 0.2784 0.4245 0.8448 1 0.0047 0.1216 0.6707 0.8259 2 0.1367 0.5751 0.8913 0.2092 3 0.1853 0.1084 0.2197 0.9786 4 0.8117 0.1719 0.8162 0.2741 5 0.4317 0.9400 0.8176 0.3361 6 0.1754 0.3728 0.0057 0.2524 7 0.7957 0.0153 0.5988 0.6038 8 0.1051 0.3819 0.0365 0.8904 9 0.9809 0.0599

Javascript AJAX include file witth eval

a 夏天 提交于 2019-12-04 03:42:08
问题 Suppose I have 1) a HTML document. 2) This HTML document loads Javascript file "code.js" like this: <script src="code.js"> 3) User clicks button which runs "fetchdata" function in "code.js", 4) "fetchdata" function looks like this: var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState==4) { myjsdata = xmlhttp.responseText; } } xmlhttp.open("GET", 'http://www.example.com/data.js', false); xmlhttp.send(null); ... Now how do I do the following

javascript eval in context without using this keyword

故事扮演 提交于 2019-12-04 03:40:05
问题 I am trying to execute eval within a particular context. I have found the answer here useful. However I am getting the following behavior in Chrome Version 53.0.2785.143 m. Not tried other browsers. The code I am using is the following: function evalInContext(js, context) { return function() { return eval(js); }.call(context); } console.log(evalInContext('x==3', { x : 3})) // Throws console.log(evalInContext('this.x==3', { x : 3})) // OK However I expected the first call to evalInContext not

How to eval strings in racket

天涯浪子 提交于 2019-12-04 03:02:49
I'm trying to understand how to get the eval function to read a string and evaluate the content that's inside the string. Currently I know that > (eval '(+ 1 2)) 3 but I'm not that knowledgeable with the use of racket. So at the moment I'm trying to get it so that I can do this: > (eval "(+ 1 2)") 3 Any advice or links to useful resources would be appreciated. You want to use read together with open-input-string . Like so: -> (eval (read (open-input-string "(+ 1 2)"))) 3 You can also use with-input-from-string : -> (with-input-from-string "(+ 1 2)" (lambda () (eval (read)))) 3 来源: https:/

Boolean expression solver/simplifier

最后都变了- 提交于 2019-12-04 02:56:10
问题 I am looking for an Boolean expression solver for very big (but not complex) algebra like: Boolsche Ausdrücke vereinfachen (Axiome) I would like to have some code (c++ or java [or libraries]) to simplify huge boolean expression. I haven´t found something. I just want to do some "simply" convertion like: a && ~a -> 0 a || a && (b || c) -> a But much longer. And I want to use symbolics (a, b, c1, d1..) not TRUE, FALSE, 0 or 1 at the moment. Thank you in advance. Edit: If I write it my self, I

Does converting json to dict with eval a good choice?

跟風遠走 提交于 2019-12-04 02:53:33
I am getting a json object from a remote server, and converting it to a python string like this: a = eval(response) Is this stupid in any way, or do I have a better option? Ned Batchelder Using eval is not a good way to process JSON: JSON isn't even valid Python, because of true , false , and null . eval will execute arbitrary Python code, so you are at the mercy of malicious injection of code. Use the json module available in the standard library instead: import json data = json.loads("[1, 2, 3]") If you're using a version of Python older than 2.6, you'll need to download the module yourself.

How to dynamically set array keys in php

瘦欲@ 提交于 2019-12-04 02:35:58
I have some logic that is being used to sort data but depending on the user input the data is grouped differently. Right now I have five different functions that contain the same logic but different groupings. Is there a way to combine these functions and dynamically set a value that will group properly. Within the function these assignments are happening For example, sometimes I store the calculations simply by: $calcs[$meter['UnitType']['name']] = ... but other times need a more specific grouping: $calcs[$meter['Resource']['name']][$meter['UnitType']['name']][date('Y-m',$start)] =... As you