eval

Variable scope + eval in Clojure

杀马特。学长 韩版系。学妹 提交于 2019-11-26 11:25:25
问题 In Clojure, (def x 3) (eval \'(prn x)) prints 3, whereas (let [y 3] (eval \'(prn y))) and (binding [z 3] (eval \'(prn z))) generate an \'Unable to resolve var\' exception. According to http://clojure.org/evaluation, eval , load-string , etc generate temporary namespaces to evaluate their contents. Therefore, I\'d expect neither of the above code samples to work, since (def x 3) is done in my current namespace, not the one created by eval . Why does the first code sample work and not the last

How do I use variables to set properties in VBA (Excel)

删除回忆录丶 提交于 2019-11-26 11:25:19
问题 Take this code: With ActiveSheet.Shapes.AddShape(msoShapeRectangle, x, y, w, h).TextFrame .Parent.Line.Visible = False .Parent.Fill.ForeColor.RGB = RGB(r, g, b) End With Is there any VBA way to \"execute\" or \"evaluate\" like can be done in perl/python/... such that the text .Parent.Line.Visible can be drawn from a variable (or cell value), rather than hard coded? ParentLine = \".Parent.Line.Visible\" ParentLineValue = \"False\" With ActiveSheet.Shapes.AddShape(msoShapeRectangle, x, y, w, h)

Lookup shell variables by name, indirectly [duplicate]

别等时光非礼了梦想. 提交于 2019-11-26 11:23:31
This question already has an answer here: How to use a variable's value as another variable's name in bash [duplicate] 6 answers Let's say I have a variable's name stored in another variable: myvar=123 varname=myvar now, I'd like to get 123 by just using $varname variable. Is there a direct way for that? I found no such bash builtin for lookup by name, so came up with this: function var { v="\$$1"; eval "echo "$v; } so var $varname # gives 123 Which doesn't look too bad in the end, but I'm wondering if I missed something more obvious. Thanks in advance! tangens From the man page of bash : ${

Calculate string value in javascript, not using eval

南楼画角 提交于 2019-11-26 11:14:28
Is there a way to calculate a formula stored in a string in JavaScript without using eval ? Normally I would do something like var apa = "12/5*9+9.4*2"; alert(eval(apa)); So, does anyone know about alternatives to eval ? Troy SK This exactly the place where you should be using eval, or you will have to loop through the string and generate the numbers. You will have to use isNaN method to do it. Mhh, you could use the Function -constructor: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function function evil(fn) { return new Function('return ' + fn)(); }

利用AutoHotkey实现Vim和Excel的数据传递

瘦欲@ 提交于 2019-11-26 11:07:11
应用场景是Excel某N列数据想用Vim处理后再复制回Excel。 Vim提供了ole接口供其他语言调用,详见:h ole.txt。 一、先说从Vim缓冲区内容转到Excel 用如下命令就能获取Vim当前缓冲区的内容(字符串格式),需要用iconv来转换编码供ahk使用。 oVim := ComObjActive("Vim.application") rs := oVim.eval('line("$")') ;行数 str := oVim.eval('iconv(join(getline(1,"$"),"\r\n"),"utf-8","cp936")') 对str的第一行内容用tab分割就知道有几列数据了(如果后面列数比第1行多就会报错了,可以多设置列数) loop parse, str, "`n", "`r" { cs := StrSplit(A_LoopField, A_Tab).length() break }   然后就可以用ComObjArray把字符串转成数组,再写入Excel的selection即可 arrA := ComObjArray(12, rs, cs) loop parse, str, "`n", "`r" { r := A_Index-1 for k, v in StrSplit(A_LoopField, A_Tab) arrA[r,k-1] := v

Python: make eval safe [duplicate]

梦想与她 提交于 2019-11-26 10:31:29
This question already has an answer here: Python eval: is it still dangerous if I disable builtins and attribute access? 6 answers I want an easy way to do a "calculator API" in Python. Right now I don't care much about the exact set of features the calculator is going to support. I want it to receive a string, say "1+1" and return a string with the result, in our case "2" . Is there a way to make eval safe for such a thing? For a start I would do env = {} env["locals"] = None env["globals"] = None env["__name__"] = None env["__file__"] = None env["__builtins__"] = None eval(users_str, env) so

Why does JavaScript's eval need parentheses to eval JSON data?

梦想与她 提交于 2019-11-26 10:28:35
I've learned (the hard way) that I need to add parentheses around JSON data, like this: stuff = eval('(' + data_from_the_wire + ')'); // where data_from_the_wire was, for example {"text": "hello"} (In Firefox 3, at least). What's the reason behind this? I hate writing code without understanding what´s behind the hood. Kazar Putting the parentheses around data_from_the_wire is effectively equivalent to stuff = eval('return ' + data_from_the_wire + ';'); If you were to eval without the parentheses, then the code would be evaluated, and if you did have any named functions inside it those would be

Understanding ASP.NET Eval() and Bind()

淺唱寂寞╮ 提交于 2019-11-26 10:18:48
问题 Can anyone show me some absolutely minimal ASP.NET code to understand Eval() and Bind() ? It is best if you provide me with two separate code-snippets or may be web-links. 回答1: For read-only controls they are the same. For 2 way databinding, using a datasource in which you want to update, insert, etc with declarative databinding, you'll need to use Bind . Imagine for example a GridView with a ItemTemplate and EditItemTemplate . If you use Bind or Eval in the ItemTemplate , there will be no

How can I dynamically include Perl modules without using eval?

一个人想着一个人 提交于 2019-11-26 09:30:28
问题 I need to dynamically include a Perl module, but if possible would like to stay away from eval due to work coding standards. This works: $module = \"My::module\"; eval(\"use $module;\"); But I need a way to do it without eval if possible. All google searches lead to the eval method, but none in any other way. Is it possible to do it without eval ? 回答1: Use require to load modules at runtime. It often a good idea to wrap this in a block (not string) eval in case the module can't be loaded.

Is 'eval' supposed to be nasty?

拟墨画扇 提交于 2019-11-26 08:46:25
I have been using eval feature of ruby many a times. But I have heard people saying eval s are nasty. When asked, why and how, I could never get a convincing reason not to use it. Are they really nasty? If yes, in what way? What are possible "safer" options to eval? If you are eval ing a string submitted by, or modifiable by the user, this is tantamount to allowing arbitrary code execution. Imagine if the string contained an OS call to rm -rf / or similar. That said, in situations where you know the strings are appropriately constrained, or your Ruby interpreter is sandboxed appropriately, or