eval

How to store a function in a variable in Lisp and use it

爷,独闯天下 提交于 2019-12-11 02:02:06
问题 I want to store a function like print in a variable so that I can just type something short like p , e.g: In Scheme : (define print display) (print "Hello world\n") ;; alternate way (define print 'display) ((eval print) "Hello world\n") The same approach does not seem to work in Common Lisp : (defvar p 'print) ;;(print (type-of p)) (p "Hello world") ;; Attempt 1 ((eval p) "Hello world") ;; >> Attempt 2 ((eval (environment) p) "Hello world") ;; Attempt 3 I'm getting this error with Attempt 1

Python eval()函数

纵饮孤独 提交于 2019-12-11 01:59:44
eval() 函数用来执行一个字符串表达式,并返回表达式的值。通常,将字符串的内容表示为表达式时,便需要使用eval() 函数,特别是批量表示变量名或者dataframe内容时。 eval(expression[, globals[, locals]]) 参数 expression -- 表达式。 globals -- 变量作用域,全局命名空间,如果被提供,则必须是一个字典对象。 locals -- 变量作用域,局部命名空间,如果被提供,可以是任何映射对象。 返回值 返回表达式计算结果 >>>str_name = 'data' >>>data=234 >>>print(eval(str_name)) 234 来源: CSDN 作者: Cherzhoucheer 链接: https://blog.csdn.net/CherDW/article/details/103482388

using eval() on string to access object attributes in R

放肆的年华 提交于 2019-12-11 01:59:17
问题 I am trying to refer to a column of a data attribute of a spatial object using a string value of its name in R. I have no problem referring to the object only using eval(), but I could not refer to the attributes within the object using the same process. So: summary(eval(as.symbol(paste0("layerName", "_p", "5")))) refers to the object layerName_p5 with no problems. However summary(eval(as.symbol(paste0("layerName", "_p", "5", "@data$colName")))) does not work, throwing the following error:

Evaluate string as condition PHP

做~自己de王妃 提交于 2019-12-11 01:49:57
问题 I have a custom validation rule module that essentially allows users to set up CSV validation. My problem is I get it to this array: Array( [field_name] => 'is_int(324230435)', [some_other_field] => 'strlen("some str") > 25' ) I did some research and came across the eval() function. refs: How to use string in IF condition in PHP However, I really don't want to use eval() due to the security issues (ref: When is eval evil in php?) Although it doesn't strictly say eval is evil, I still would

How can I use a custom function within an expression using the eval dataframe method?

天大地大妈咪最大 提交于 2019-12-11 01:40:04
问题 I am using Python 3.X. With the builtin function eval() you can use a dictionaty of objects in order to use a custom function like this: from math import * def one(): # some operations return 1 functions = { '__builtins__': None, 'sqrt': sqrt, 'one': one, } variables = { '__builtins__': None, 'pi': pi, } expression = 'sqrt(34 * pi) + one()' eval(expression, variables, functions) But the eval() dataframe method does not work like that. You can only use these built-in functions: The supported

How to use Eval in codebehind to set Page.Title

非 Y 不嫁゛ 提交于 2019-12-11 00:20:12
问题 I have a SQLDataSource that is bound to a ListView control but I want to place parts of the bound record into the HTML TITLE attribute. Here is my codebehind file that I want to change so it can use Eval to construct a dynamic TITLE based on the data content: Public Partial Class zShowAd Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.Page.Title = " Dynamically set in ASPX page" 'how to use Eval here instead of the

How can I interpret a JSON object received as a string correctly?

廉价感情. 提交于 2019-12-10 23:57:45
问题 I've got a broken web service that I can't access and alter. It sends down some mainly nice JSON, but one of the attributes is a nested JSON object that is being sent down as a string. http://www.ireland.com/api/getitemweb/185213 CustomJsonData in the response from the above url is the example. My question is how could I interpret the CustomJsonData string as an object? I thought the 'evil' eval() might do it, but no luck. Thanks, Denis 回答1: If you are using eval, you need to add a ( and ) to

How to use a function containing eval in a file by variable defined at another file from that another file?

流过昼夜 提交于 2019-12-10 23:01:22
问题 Assume, I have created an python file (FirstFile.py) name which contains many functions and other things. One of the function is this (of course, it is simplified): def func(string): assert eval(string) Besides, I have created an python file which imports func() from the file mentioned above. Then this second python file try to execute following process: from FirstFile import func amk = 1 func("amk == 1") When variable "amk" is in the first file, no problem reveals. However, when variable

MATLAB: Alternative to using 'eval' in order to evaluate string

痞子三分冷 提交于 2019-12-10 22:43:12
问题 I have a bunch of char arrays within a cell array that actually represents the declaration of MATLAB structs. Something like this: tmp{1} = 'testData.input = [1;2;3;4;5]' tmp{2} = 'testData.output = [2;4;6;8;10]' I need to execute these "commands" and eventually create the respective struct. I am using the eval function within a for-loop and it works. numEntries = numel(tmp); for i = 1 : numEntries eval(tmp{i}); end However, this is painfully slow. I should mention that the real char arrays

Eval a string to a callable JS function

给你一囗甜甜゛ 提交于 2019-12-10 22:18:21
问题 I need to eval a function kept as string and then use it in JS code, here's the scenario: Step 1 <textarea id="function_text">function test(e){ alert(e.id); }</textarea> Step 2 var thatFunction = eval($("#function_text").val()); // returns undefined Step 3 thatFunction.call({id: 100}); Is there a way to do that? P.S. I'm aware of all security considerations, I just need 100 to be alerted at step 3! 回答1: I'm going to give you a warning, don't do it, but here is how: var thatFunction = Function