eval

Array: set value using dot notation?

落爺英雄遲暮 提交于 2019-12-17 23:32:44
问题 Looking into Kohana documentation, i found this really usefull function that they use to get values from a multidimensional array using a dot notation, for example: $foo = array('bar' => array('color' => 'green', 'size' => 'M')); $value = path($foo, 'bar.color', NULL , '.'); // $value now is 'green' Im wondering if there is a way to set the an array value in the same way: set_value($foo, 'bar.color', 'black'); The only way i found to do that is re-building the array notation ($array['bar'][

What are the caveats of using source versus parse & eval?

不想你离开。 提交于 2019-12-17 22:55:40
问题 Short version Can I replace source(filename, local = TRUE, encoding = 'UTF-8') with eval(parse(filename, encoding = 'UTF-8')) without any risk of breakage, to make UTF-8 source files work on Windows? Long version I am currently loading specific source files via source(filename, local = TRUE, encoding = 'UTF-8') However, it is well known that this does not work on Windows, full stop. As a workaround, Joe Cheng suggested using instead eval(parse(filename, encoding = 'UTF-8')) This seems to work

“eval” for Objective-C code

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 21:21:20
问题 Does a method like eval exist in Objective-C as in Javascript, Ruby, PHP, or Python? I use PhoneGap and I want to create a window which is specific for each of my projects, and I can't use an HTML file. So I want to call a method from JavaScript and, with one of the arguments being Objective-C code to be interpreted. 回答1: Sorry, there is no "eval" method in Objective-C, and the iPhone license specifically prohibits interpreted code. You can specify a xib/nib file by name, however. 回答2: Try

How could I call Java code dynamically?

你离开我真会死。 提交于 2019-12-17 19:55:40
问题 How could I write Java code that is executed like javascript code used together with the eval function? What I would like to achieve would be something like this: System.execute ("String str = \"test\"; System.out.println(str);"); which would print the word 'test'. (10x dehmann ) A code sample would help a lot. 回答1: Look into BeanShell or Groovy. Both will give you reasonable solutions--but those solutions rely on my interpretation of your problem, which may be flawed. 回答2: I've used the

eval in if statement?

雨燕双飞 提交于 2019-12-17 19:37:13
问题 <% if(Eval("SaveDate") != DBNull.Value){ %> do magic <%} %> gives me error: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. I could write : <%# Eval("SaveDate") != DBNull.Value ? do magic But I need to do lots of html magic in if statement. I know I should add # in order to use Eval, but not sure about correct syntax. 回答1: One solution is to wrap the content in a runat="server" tag with a Visible value, e.g., <div runat="server"

Python: Way to speed up a repeatedly executed eval statement?

自古美人都是妖i 提交于 2019-12-17 18:51:11
问题 In my code, I'm using eval to evaluate a string expression given by the user. Is there a way to compile or otherwise speed up this statement? import math import random result_count = 100000 expression = "math.sin(v['x']) * v['y']" variable = dict() variable['x'] = [random.random() for _ in xrange(result_count)] variable['y'] = [random.random() for _ in xrange(result_count)] # optimize anything below this line result = [0] * result_count print 'Evaluating %d instances of the given expression:'

Are Dynamic Prepared Statements Bad? (with php + mysqli)

流过昼夜 提交于 2019-12-17 18:24:51
问题 I like the flexibility of Dynamic SQL and I like the security + improved performance of Prepared Statements. So what I really want is Dynamic Prepared Statements, which is troublesome to make because bind_param and bind_result accept "fixed" number of arguments. So I made use of an eval() statement to get around this problem. But I get the feeling this is a bad idea. Here's example code of what I mean // array of WHERE conditions $param = array('customer_id'=>1, 'qty'=>'2'); $stmt = $mysqli-

In C# is there an eval function?

不问归期 提交于 2019-12-17 18:22:01
问题 I'm typing an equation into a textbox that will generate the graph of the given parabola. Is it possible to use an eval function? My C# 2010 doesn't have microsoft.jscript . 回答1: C# doesn't have a comparable Eval function but creating one is really easy: public static double Evaluate(string expression) { System.Data.DataTable table = new System.Data.DataTable(); table.Columns.Add("expression", string.Empty.GetType(), expression); System.Data.DataRow row = table.NewRow(); table.Rows.Add(row);

Indirect eval call in strict mode

北城余情 提交于 2019-12-17 17:47:28
问题 I understand about how eval() works in non-strict contexts, however the case of using eval() in strict mode has completely befuddled me. When eval() is called directly in the global scope, variables are kept inside the new eval() scope: 'use strict'; eval('var a = 1;'); console.log(a); // ReferenceError: a is not defined However, if I perform an indirect call to eval() in the global scope (should be the same thing, right?), it acts as though it is not in strict mode (if you don't believe me,

Alan Kay's Eval/Apply Einstein Moment

江枫思渺然 提交于 2019-12-17 15:44:47
问题 Alan Kay said that reading the code closely and finding the 1 and only bug in the code on page 13 of the Lisp 1.5 manual, helped him understand Computer Science by a factor of 100 better. The code in question is the 1st release of eval & apply that looks anything remotely like modern lisp (that I'm aware of). Since the correct answer is likely known but lost (my google-fu is decent and I've searched for 20 mins at least) I will award the 1st correct answer (I will be looking at edit times so