eval

executing anonymous functions created using JavaScript eval()

I have a function and its contents as a string. var funcStr = "function() { alert('hello'); }"; Now, I do an eval() to actually get that function in a variable. var func = eval(funcStr); If I remember correctly, in Chrome and Opera, simply calling func(); invoked that function and the alert was displayed. But, in other browsers...

Eval not working on unexpanded macro quote

In common lisp I can do this: src-> (defmacro macro-hello () `"hello") (eval '(macro-hello)) no problem. In clojure: (defmacro macro-hello [] `"hello") (eval '(macro-hello)) gives me an error. Have I done something wrong? Clojure Error: Exception in thread "main" java.lang.Exception: Unable to resolve symbol: macro-hello i...

Before Databinder.Eval

..there used to be another method of binding items to data containers in ASP.Net using 'ItemBinder' property maybe but nothing on google refreshes my memory. Typically, I would have a string array which when bound to say my DataGrid should show the array's values. This is an alternative method to DataBinder.Eval(). Thanks ...

When should I use eval (taking a string and executing it as code at runtime)?

I've often heard the argument (in javascript, but many languages have an eval-like feature) that using eval is "bad." The arguments being that most things you would think to use eval for can be done other ways, the fact that eval is very slow in most cases, and that it can allow users to input code to be executed (if proper precaution wa...

Is there a way in javascript to obtain the definition of a given function as a string, to be possibly modified and evaled?

I am trying to evaluate a function in a new context, ie, one that contains a certain word defined that does not exist in the scope. It is easy enough if I have the definition of the function as a string, but I would like to provide the ability to do this with a regular list of functions, like so: var funcs = { first: function() { ret...

Doing math in vb.net like Eval in javascript

Is there any way to parse a string in vb.net (like, built in methods), that can do math like Eval can? For example, 3+(7/3.5) as a string would return 2. I am not asking for you to code this for me, I just want to know if there is a built in way to do this, if there is not I will code it myself. I can wager that it would not be able to...

Python Eval: What's wrong with this code?

I'm trying to write a very simple Python utility for personal use that counts the number of lines in a text file for which a predicate specified at the command line is true. Here's the code: import sys pred = sys.argv[2] if sys.argv[1] == "stdin" : handle = sys.stdin else : handle = open(sys.argv[1]) result = 0 for line in han...

Is there a way of passing all the defined variables to a GroovyShell?

Right now, when I'm trying to eval a piece of code in Groovy, I have to do something like this : new GroovyShell(new Binding([var1:var1])).evaluate(line) This can be pretty nasty when you have a lot of variables defined. Is there a better way of doing this? Is there something like Python's locals, or something similar that lists all t...

A bit complicated eval in Ruby

I need a special behavior from eval, to evaluate strings like: '5a + 6b + 3a + 11b' into '8a + 17b' Is it possible? If it is, can you give a proper example? I found this example recently, where the talk was about evaluating strings with meters and inches. ...

Javascript: Debuging code created by eval() and new Function()

Hi all, im trying for put a private var into an already existent function, example: var AObject={ get:function(s){ return s.toLowerCase()+a; } } function temp(){ var a="A"; var o={}; eval("o.get="+AObject.get.toString()); reurn o; } var bObject=temp(); BObject.get("B"); // "bA" BObject.get(); /* error...

How to pass parameters in eval in an object form?

Hello, I have this json, and when i get this json i need to run the function which comes at callback object. { formId: 'snn_service_item_form', item_id: '1', item_title: 'some item', item_description: '', item_duration: '10', item_price: '120', item_level_1 : 1, item_level_2 : 0, item_level_3 : 1, ...

Bind List of object array to ListView in ASP.NET

Hi All, I am breaking my head to fix an issue. I have a method that returns a List<object[]>. Each object[] in the List contains the following: object[0]=Id; object[1]=Name; Now I am looking for a way to bind this List to a ListView in a custom ItemTemplate which would look as follows: <asp:Label runat="server" ID="lblId" Text=...

How to use Eval("x") value in ListView

Hey, I'm wondering how I can use the Eval values in a ListView? I mean displaying it as text is simple enough, even sending it to the codebehind via some parameters in a button click event for example. But how do I actually use that information as is on the aspx page without using any triggered events? Basically I get an Eval("Storage"...

Compilation of <%# %> expressions

Is there a way to force VS2008 to compile <%# %> databinding expressions to avoid runtime errors? ...

Do languages with meta-linguistic abstraction perform better than those that just use reflection API for that?

Say, if I have a Lisp program, which uses (eval 'sym) and looks it up in its symbol-table does it actually perform better than something like aClass.getField("sym", anInstance) in "static" languages? ...

Ajax: injecting code into Internet Explorer

I'm having trouble getting the follow code to work in Internet Explorer, it doesn't seem to want to execute the code sent back from the server via Ajax, it just does nothing: var ajax = new ActiveXObject('Microsoft.XMLHTTP'); ajax.open('GET','http://fromsitewebsite.com/javascript.js',true); ajax.setRequestHeader('Connection','close'); a...

Allow user-defined script in Ruby/Rails application

A predefined set of objects has to be aggregated into a new object. However I want the users to specify a custom function for that. Now the naive approach would be def foo; end objects = [1,2,3] # result = eval(user_script) result = eval("objects.inject {|sum, n| sum + n }") What I obviously do not want to do! I read about $SAFE = 4...

Acessing javascript multidimensional array with linear values

How could I set a variable that I can read by using eval('productOptionTree' + '[0][1][0]')? (the '[0][1][0]' part comes from another variable) UPDATE it's an ugly question, but I couldn't find another way to do it. the only answer I could find is: newVal = 4; dim = '[0][1][0]'; eval('productOptionTree'+dim+' = ' +newV...

eval json out of memory error

Hi, I'm using JSON.parse function to load info about a cellset. I'm testing how much data is possible to fetch in one call. The eval function starts throwing "out of memory" between 1.3-1.4 million characters (65,000-70,000 cells) in the JSON string. Does anybody know of a workaround for this - perhaps a pure JSON parser, rather than e...

User defined formulas in C#

I have an application where for each object the user can specify his own measurepoints. The values of theese measurements will then be used to classify the object as i e A - needs service, B - service should be scheduled within X days, C - no service needed ATM However theese objects can be almost anything and there is no way we can har...