eval

How to eval strings in racket

旧时模样 提交于 2019-12-21 09:14:30
问题 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. 回答1: You want to use read together with open-input-string . Like so: -> (eval (read (open-input-string "(+ 1 2)"))) 3 You can also use

Ruby: Parse, replace, and evaluate a string formula

∥☆過路亽.° 提交于 2019-12-21 06:39:49
问题 I'm creating a simple Ruby on Rails survey application for a friend's psychological survey project. So we have surveys, each survey has a bunch of questions, and each question has one of the options participants can choose from. Nothing exciting. One of the interesting aspects is that each answer option has a score value associated with it. And so for each survey a total score needs to be calculated based on these values. Now my idea is instead of hard-coding calculations is to allow user add

“Eval” a string in OCaml

橙三吉。 提交于 2019-12-21 05:14:27
问题 I'm trying to "eval" a string representing an OCaml expression in OCaml. I'm looking to do something equivalent to Python's eval. So far I've not been able to find much. The Parsing module looks like it could be helpful, but I was not able to find a way to just eval a string. 回答1: Here is how to do it, but I didn't tell you. (Also the Parsing module is about Parsing, not executing code) #require "compiler-libs" (* Assuming you're using utop, if compiling then this is the package you need *)

How do you know to use Container.DataItem when data binding in ASP.NET? Is there a reference?

不想你离开。 提交于 2019-12-21 05:06:36
问题 Is there a reference for data binding? I've seen a bunch of different ways to data bind things, but I've never found a reference. Is there one? I know there are Bind and Eval, but when does Container.DataItem come into play? Are there other "hidden" objects and methods available? Or is Container.DataItem the object that is being used here? 回答1: when does Container.DataItem come into play? From the first link below (paraphrasing slightly): "Container.DataItem is a runtime alias for the

Using ast and whitelists to make python's eval() safe?

帅比萌擦擦* 提交于 2019-12-20 14:38:42
问题 OK. I know the experts have spoken and you should not ever use python's eval() on untrusted data, ever. I'm not smarter than the rest of the world, and shouldn't even try this. But! I'm going to, anyhow. My basic problem is that I'm looking to write a little calculator evaluator program that'll take untrusted input, using a subset of python's syntax. I know: use ply or pyparsing and write a parser and there we go. Screwing around with passing globals and locals to eval() will not do the trick

Using ast and whitelists to make python's eval() safe?

孤街醉人 提交于 2019-12-20 14:37:48
问题 OK. I know the experts have spoken and you should not ever use python's eval() on untrusted data, ever. I'm not smarter than the rest of the world, and shouldn't even try this. But! I'm going to, anyhow. My basic problem is that I'm looking to write a little calculator evaluator program that'll take untrusted input, using a subset of python's syntax. I know: use ply or pyparsing and write a parser and there we go. Screwing around with passing globals and locals to eval() will not do the trick

Why I can call 'print' from 'eval'

眉间皱痕 提交于 2019-12-20 14:12:35
问题 For code: #!/usr/bin/python src = """ print '!!!' import os """ obj = compile(src, '', 'exec') eval(obj, {'__builtins__': False}) I get output: !!! Traceback (most recent call last): File "./test.py", line 9, in <module> eval(obj, {'__builtins__': False}) File "", line 3, in <module> ImportError: __import__ not found Both 'print' and 'import' are language construct. Why does 'eval' restrict using of 'import' but doesn't restrict 'print'? P.S. I'm using python 2.6 UPDATE: Question is not "Why

Equivalent of python eval in Haskell

佐手、 提交于 2019-12-20 12:44:50
问题 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? 回答1: 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

Equivalent of python eval in Haskell

懵懂的女人 提交于 2019-12-20 12:44:28
问题 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? 回答1: 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

What are the common pitfalls when using Perl's eval?

偶尔善良 提交于 2019-12-20 10:33:12
问题 What are the common pitfalls associated with Perl's eval, which might make you choose to use a module such as Try::Tiny? 回答1: Perl's eval comes in two flavors, string eval and block eval. String eval invokes the compiler to execute source code. Block eval surrounds already compiled code in a wrapper that will catch the die exception. (string eval catches the die exception also, as well as any compilation errors). Try::Tiny only applies to the block form of eval, but the following applies to