[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Ali Rezaee
That's a very beautiful solution. Thank you! On Tuesday, April 26, 2016 at 10:58:39 PM UTC+2, Josh Langsfeld wrote: > eval works in global scope but returns its result locally, so something > like this works easily enough: > > rulestrs = ["x[1] && x[2]", "x[3] || x[4]", "x[1] && (x[2] ||

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Josh Langsfeld
eval works in global scope but returns its result locally, so something like this works easily enough: rulestrs = ["x[1] && x[2]", "x[3] || x[4]", "x[1] && (x[2] || x[3])"] function evaluate(rules, boolList) rulefuncs = [eval(parse(string("x -> ", rule))) for rule in rules]

Re: [julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Yichao Yu
On Tue, Apr 26, 2016 at 2:24 PM, Ali Rezaee wrote: > Reading the rules from a file, how can I convert the strings to such > anonymous functions? You need to `eval` in global scope. If you are more serious about input validation and such, you might need to have your own

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Ali Rezaee
Reading the rules from a file, how can I convert the strings to such anonymous functions? On Tuesday, April 26, 2016 at 6:48:21 PM UTC+2, Josh Langsfeld wrote: > > Maybe a better design would be to store the rules as anonymous functions > rather than code strings? Something like: > > ``` >

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Ali Rezaee
I am writing code for regulated Flux Balance Analysis. I need to read some regulatory rules from a file and predict the future state of the genes in the network. In this example x is a vector of genes being on or off, and each rule belongs to a reaction, i.e. if the rule is true, then the

Re: [julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Milan Bouchet-Valat
Le mardi 26 avril 2016 à 13:22 -0400, Yichao Yu a écrit : > On Tue, Apr 26, 2016 at 12:58 PM, Milan Bouchet-Valat wrote: > > > > Le mardi 26 avril 2016 à 12:52 -0400, Yichao Yu a écrit : > > > > > > On Tue, Apr 26, 2016 at 12:09 PM, Ali Rezaee wrote: > > > > > > > > > >

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Steven G. Johnson
On Tuesday, April 26, 2016 at 12:09:33 PM UTC-4, Ali Rezaee wrote: > > My objective is exactly what the code shows. I have a list of Boolean > expressions similar to the examples in the code, and I need to evaluate > them one by one based on x values. > So writing a macro would be the only

Re: [julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Yichao Yu
On Tue, Apr 26, 2016 at 12:58 PM, Milan Bouchet-Valat wrote: > Le mardi 26 avril 2016 à 12:52 -0400, Yichao Yu a écrit : >> On Tue, Apr 26, 2016 at 12:09 PM, Ali Rezaee wrote: >> > >> > >> > Thanks for your replies. >> > My objective is exactly what the

Re: [julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Milan Bouchet-Valat
Le mardi 26 avril 2016 à 12:52 -0400, Yichao Yu a écrit : > On Tue, Apr 26, 2016 at 12:09 PM, Ali Rezaee wrote: > > > > > > Thanks for your replies. > > My objective is exactly what the code shows. I have a list of Boolean > > expressions similar to the examples in the

Re: [julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Yichao Yu
On Tue, Apr 26, 2016 at 12:09 PM, Ali Rezaee wrote: > > Thanks for your replies. > My objective is exactly what the code shows. I have a list of Boolean > expressions similar to the examples in the code, and I need to evaluate them > one by one based on x values. > So writing

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Josh Langsfeld
Maybe a better design would be to store the rules as anonymous functions rather than code strings? Something like: ``` rules = [(x -> x[1] && x[2]), (x -> x[3] || x[4])] #parentheses not required result = [rule(boolList) for rule in rules] ``` On Tuesday, April 26, 2016 at 12:09:33 PM UTC-4,

[julia-users] Re: Evaluation of boolean expression fails

2016-04-26 Thread Steven G. Johnson
On Tuesday, April 26, 2016 at 11:38:21 AM UTC-4, Ali Rezaee wrote: > > Hi everyone, > > I am trying to run the code below. When I try the code outside of a > function and in REPL, it runs successfully. However when I run it using a > function it throw an error. > Why do I get the error? and