[julia-users] DefaultDict unexpected behaviour?
Hi, I have the following code: using DataStrucures d= DefaultDict(ASCIIString,Array{Int64},Array{Int64}(0)) push!(d["A"],2) push!(d["B"],3) d DataStructures.DefaultDict{ASCIIString,Array{Int64,N},Array{Int64,1}} with 2 entries: "B" => [2,3] "A" => [2,3] Isn't it unexpected that when I push to any key, the value is pushed to all the other keys as well? Thanks :)
Re: [julia-users] DefaultDict unexpected behaviour?
Thank you. What would be the work around? How can I push values to defaultdict without changing any other value? On Friday, July 3, 2015 at 3:35:39 PM UTC+2, Yichao Yu wrote: > > On Fri, Jul 3, 2015 at 9:29 AM, Ali Rezaee > wrote: > > Hi, > > > > I have the following code: > > > > using DataStrucures > > d= DefaultDict(ASCIIString,Array{Int64},Array{Int64}(0)) > > > > push!(d["A"],2) > > push!(d["B"],3) > > > > d > > DataStructures.DefaultDict{ASCIIString,Array{Int64,N},Array{Int64,1}} > with 2 > > entries: > > "B" => [2,3] > > "A" => [2,3] > > > > > > Isn't it unexpected that when I push to any key, the value is pushed to > all > > the other keys as well? > > Yes, pretty much. Because the default value is stored by reference and > you are mutating it with `push!` > > See the last paragraph of the corresponding section in the > DataStructures.jl README[1] > > [1] > https://github.com/JuliaLang/DataStructures.jl#defaultdict-and-defaultordereddict > > > > > > Thanks :) >
Re: [julia-users] DefaultDict unexpected behaviour?
Thank you. It solved my problem On Friday, July 3, 2015 at 5:54:12 PM UTC+2, Kevin Squire wrote: > > I updated the README with another example based on this discussion. > > Cheers! >Kevin > > On Fri, Jul 3, 2015 at 7:51 AM, Yichao Yu > > wrote: > >> On Fri, Jul 3, 2015 at 10:40 AM, Yichao Yu > > wrote: >> > On Fri, Jul 3, 2015 at 9:42 AM, Ali Rezaee > > wrote: >> >> Thank you. What would be the work around? How can I push values to >> >> defaultdict without changing any other value? >> > >> > The README I linked is exactly about that. >> >> And quote it here for future reference: >> >> > Note that in the last example, we need to use a function to create each >> new `DefaultDict`. If we forget, we will end up using the same >> `DefaultDict` for all default values: >> >> In their case, the value of a parent DefaultDict is also a DefaultDict >> so it might be a little confusing. You can pretty much replace the >> DefaultDict above by `Array` and it will apply to your case directly. >> >> >> > >> >> >> >> On Friday, July 3, 2015 at 3:35:39 PM UTC+2, Yichao Yu wrote: >> >>> >> >>> On Fri, Jul 3, 2015 at 9:29 AM, Ali Rezaee wrote: >> >>> > Hi, >> >>> > >> >>> > I have the following code: >> >>> > >> >>> > using DataStrucures >> >>> > d= DefaultDict(ASCIIString,Array{Int64},Array{Int64}(0)) >> >>> > >> >>> > push!(d["A"],2) >> >>> > push!(d["B"],3) >> >>> > >> >>> > d >> >>> > >> DataStructures.DefaultDict{ASCIIString,Array{Int64,N},Array{Int64,1}} >> >>> > with 2 >> >>> > entries: >> >>> > "B" => [2,3] >> >>> > "A" => [2,3] >> >>> > >> >>> > >> >>> > Isn't it unexpected that when I push to any key, the value is >> pushed to >> >>> > all >> >>> > the other keys as well? >> >>> >> >>> Yes, pretty much. Because the default value is stored by reference and >> >>> you are mutating it with `push!` >> >>> >> >>> See the last paragraph of the corresponding section in the >> >>> DataStructures.jl README[1] >> >>> >> >>> [1] >> >>> >> https://github.com/JuliaLang/DataStructures.jl#defaultdict-and-defaultordereddict >> >>> >> >>> > >> >>> > Thanks :) >> > >
[julia-users] Converting a string to an array?
How can I convert the string representation of an array, such as the following string, into an Array? s = "[1,2,3]" I am reading these strings from a file and I am looking for an easy way to have them as a list. In Python I would use eval function. Is there an alternative in Julia? Many thanks, Ali
Re: [julia-users] Converting a string to an array?
Great. Thank you. On Monday, August 31, 2015 at 11:52:09 AM UTC+2, René Donner wrote: > > Hi, > > yes, it works almost the same: > > julia> eval(parse("[1,2,3]")) > 3-element Array{Int64,1}: > 1 > 2 > 3 > > > parse parses the string into an expression (abstract syntax tree, AST), > and eval, well, evaluates ;-) > > But take care, any valid code inside the string will get executed. > > Rene > > > > > Am 31.08.2015 um 11:48 schrieb Ali Rezaee >: > > > > How can I convert the string representation of an array, such as the > following string, into an Array? > > > > > > s = "[1,2,3]" > > > > I am reading these strings from a file and I am looking for an easy way > to have them as a list. > > In Python I would use eval function. Is there an alternative in Julia? > > > > Many thanks, > > > > Ali > > > >
[julia-users] How can I convert a set into an array?
In Python I would normally to something like this: a = set([1,2,1,3]) a = list(a) What is the equivalent way to do this in Julia? Thanks a lot in advance for your help
[julia-users] How can I convert a set to an array?
In Python I would do a = set([1,2]) a = list(a) How can I do that in Julia? Thanks a lot in advance for your help
[julia-users] Re: How can I convert a set into an array?
Thanks Rene and Kevin. The unique function is what I needed. On Wednesday, March 11, 2015 at 5:05:08 PM UTC+1, Ali Rezaee wrote: > > In Python I would normally to something like this: > > a = set([1,2,1,3]) > a = list(a) > > What is the equivalent way to do this in Julia? > > > Thanks a lot in advance for your help >
Re: [julia-users] How can I convert a set to an array?
Thanks a lot for your help :) On Wednesday, March 11, 2015 at 5:07:45 PM UTC+1, Jacob Quinn wrote: > > a = IntSet([1,2,3]) > a = [a...] > > On Wed, Mar 11, 2015 at 9:35 AM, Ali Rezaee > wrote: > >> In Python I would do >> >> a = set([1,2]) >> a = list(a) >> >> How can I do that in Julia? >> >> Thanks a lot in advance for your help >> > >
[julia-users] Something equivalent to Python's xrange()?
Hi, I am trying to iterate over a range of numbers. I know I can do this: for i in 1:10 println(i) end but, if I am not wrong, it creates a list from 1 to 10 and iterates over it. Is there a more memory efficient method so that it does not create and store the list? something that returns an iterator object similar to Python's xrange(). Many thanks
[julia-users] Re: Something equivalent to Python's xrange()?
That's cool. Thank you On Thursday, March 12, 2015 at 2:19:31 PM UTC+1, Ali Rezaee wrote: > > Hi, > > I am trying to iterate over a range of numbers. I know I can do this: > > for i in 1:10 > println(i) > end > > but, if I am not wrong, it creates a list from 1 to 10 and iterates over > it. > Is there a more memory efficient method so that it does not create and > store the list? something that returns an iterator object similar to > Python's xrange(). > > Many thanks >
[julia-users] Garbage collection when calling a function
Dear all, I have faced a situation that was unexpected to me. Would you let me know if this was expected or this is a bug? I have a very long code, so I could not put an example here. But the situation is that I have a function in a separate file that I have included in my code. Some where in my code, I call the function for thousands of times, and each time it returns an integer, 0 or 1. The problem is that with each call of the function, memory usage of my pc increases by one percent and is not deallocated after the function is finished. I could circumvent the problem by explicitly using the garbage collector gc(). Should Julia not have collected garbage automatically after a function from an external library has finished running? Many thanks
Re: [julia-users] Garbage collection when calling a function
Thanks, Stefan. My code is all in Julia. That is why I was surprised that memory didn't get freed until I explicitly called gc(). On Thursday, April 2, 2015 at 5:02:27 PM UTC+2, Stefan Karpinski wrote: > > I'm afraid this is a little too vague to help debugging. If you are > calling C code that allocates memory and doesn't free it, then there's > nothing that Julia's GC can do about it. If normal Julia code allocates > memory, it will get freed once there's no way to reach it anymore. > > On Thu, Apr 2, 2015 at 7:51 AM, Ali Rezaee > wrote: > >> Dear all, >> >> I have faced a situation that was unexpected to me. Would you let me know >> if this was expected or this is a bug? >> >> I have a very long code, so I could not put an example here. But the >> situation is that I have a function in a separate file that I have included >> in my code. >> Some where in my code, I call the function for thousands of times, and >> each time it returns an integer, 0 or 1. The problem is that with each call >> of the function, memory usage of my pc increases by one percent and is not >> deallocated after the function is finished. >> I could circumvent the problem by explicitly using the garbage collector >> gc(). >> Should Julia not have collected garbage automatically after a function >> from an external library has finished running? >> >> Many thanks >> > >
RE: [julia-users] Re: Garbage collection when calling a function
Ok that makes sense. Thank you. -Original Message- From: "ele...@gmail.com" Sent: 4/3/2015 3:35 AM To: "julia-users@googlegroups.com" Subject: [julia-users] Re: Garbage collection when calling a function On Thursday, April 2, 2015 at 10:51:52 PM UTC+11, Ali Rezaee wrote: Dear all, I have faced a situation that was unexpected to me. Would you let me know if this was expected or this is a bug? I have a very long code, so I could not put an example here. But the situation is that I have a function in a separate file that I have included in my code. Some where in my code, I call the function for thousands of times, and each time it returns an integer, 0 or 1. The problem is that with each call of the function, memory usage of my pc increases by one percent and is not deallocated after the function is finished. I could circumvent the problem by explicitly using the garbage collector gc(). Should Julia not have collected garbage automatically after a function from an external library has finished running? The GC does not run every time a function returns, it runs when the memory usage reaches a specified amount (IIUC) so until your usage reaches the limit GC won't run. Cheers Lex Many thanks
[julia-users] Re: Performance variability - can we expect Julia to be the fastest (best) language?
They were interesting questions. I would also like to know why poorly written Julia code sometimes performs worse than similar python code, especially when tuples are involved. Did you say it was fixed? On Thursday, April 30, 2015 at 9:58:35 PM UTC+2, Páll Haraldsson wrote: > > Hi, > > [As a best language is subjective, I'll put that aside for a moment.] > > Part I. > > The goal, as I understand, for Julia is at least within a factor of two of > C and already matching it mostly and long term beating that (and C++). > [What other goals are there? How about 0.4 now or even 1.0..?] > > While that is the goal as a language, you can write slow code in any > language and Julia makes that easier. :) [If I recall, Bezanson mentioned > it (the global "problem") as a feature, any change there?] > > > I've been following this forum for months and newbies hit the same issues. > But almost always without fail, Julia can be speed up (easily as Tim Holy > says). I'm thinking about the exceptions to that - are there any left? And > about the "first code slowness" (see Part II). > > Just recently the last two flaws of Julia that I could see where fixed: > Decimal floating point is in (I'll look into the 100x slowness, that is > probably to be expected of any language, still I think may be a > misunderstanding and/or I can do much better). And I understand the tuple > slowness has been fixed (that was really the only "core language" defect). > The former wasn't a performance problem (mostly a non existence problem and > correctness one (where needed)..). > > > Still we see threads like this one recent one: > > https://groups.google.com/forum/#!topic/julia-users/-bx9xIfsHHw > "It seems changing the order of nested loops also helps" > > Obviously Julia can't beat assembly but really C/Fortran is already close > enough (within a small factor). The above row vs. column major (caching > effects in general) can kill performance in all languages. Putting that > newbie mistake aside, is there any reason Julia can be within a small > factor of assembly (or C) in all cases already? > > > Part II. > > Except for caching issues, I still want the most newbie code or > intentionally brain-damaged code to run faster than at least > Python/scripting/interpreted languages. > > Potential problems (that I think are solved or at least not problems in > theory): > > 1. I know Any kills performance. Still, isn't that the default in Python > (and Ruby, Perl?)? Is there a good reason Julia can't be faster than at > least all the so-called scripting languages in all cases (excluding small > startup overhead, see below)? > > 2. The global issue, not sure if that slows other languages down, say > Python. Even if it doesn't, should Julia be slower than Python because of > global? > > 3. Garbage collection. I do not see that as a problem, incorrect? Mostly > performance variability ("[3D] games" - subject for another post, as I'm > not sure that is even a problem in theory..). Should reference counting > (Python) be faster? On the contrary, I think RC and even manual memory > management could be slower. > > 4. Concurrency, see nr. 3. GC may or may not have an issue with it. It can > be a problem, what about in Julia? There are concurrent GC algorithms > and/or real-time (just not in Julia). Other than GC is there any big > (potential) problem for concurrent/parallel? I know about the threads work > and new GC in 0.4. > > 5. Subarrays ("array slicing"?). Not really what I consider a problem, > compared to say C (and Python?). I know 0.4 did optimize it, but what > languages do similar stuff? Functional ones? > > 6. In theory, pure functional languages "should" be faster. Are they in > practice in many or any case? Julia has non-mutable state if needed but > maybe not as powerful? This seems a double-edged sword. I think Julia > designers intentionally chose mutable state to conserve memory. Pros and > cons? Mostly Pros for Julia? > > 7. Startup time. Python is faster and for say web use, or compared to PHP > could be an issue, but would be solved by not doing CGI-style web. How > good/fast is Julia/the libraries right now for say web use? At least for > long running programs (intended target of Julia) startup time is not an > issue. > > 8. MPI, do not know enough about it and parallel in general, seems you are > doing a good job. I at least think there is no inherent limitation. At > least Python is not in any way better for parallel/concurrent? > > 9. Autoparallel. Julia doesn't try to be, but could (be an addon?). Is > anyone doing really good and could outperform manual Julia? > > 10. Any other I'm missing? > > > Wouldn't any of the above or any you can think of be considered > performance bugs? I know for libraries you are very aggressive. I'm > thinking about Julia as a core language mostly, but maybe you are already > fastest already for most math stuff (if implemented at all)? > > > I know to g
[julia-users] How to optimize the collect function?
Dear all, I have a ported all my project from python to Julia. However, there is one part of my code that I have not been able to optimize much. It is between 3 to 9 times slower than similar python code. Do you have any suggestions / explanations? Julia code: function collect_zip(a::Array=["a","b","c","d"],b::Array=[0.2,0.1,0.1,0.6]) c = collect(zip(a,b)) end collect_zip() @time for i in 1:1; j= collect_zip();end # elapsed time: 0.089672328 seconds (9 MB allocated) Python code: def listzip(a = ["a","b","c","d"], b = [0.2,0.1,0.1,0.6]): c = list(zip(a,b)) a = timeit.timeit("listzip()","from __main__ import listzip",number=1) print(a) # 0.0105497862674 P.S: I need to convert the zip to an array because after that I need to sort them. Thanks a lot,
[julia-users] Re: How to optimize the collect function?
I tried on a Linux desktop, and I still get similar timings. Does anyone else get different timings? On Friday, May 1, 2015 at 12:43:24 AM UTC+2, Ali Rezaee wrote: > > Dear all, > > I have a ported all my project from python to Julia. However, there is one > part of my code that I have not been able to optimize much. It is between 3 > to 9 times slower than similar python code. > Do you have any suggestions / explanations? > > Julia code: > function collect_zip(a::Array=["a","b","c","d"],b::Array=[0.2,0.1,0.1,0.6 > ]) > c = collect(zip(a,b)) > end > > collect_zip() > @time for i in 1:1; j= collect_zip();end # elapsed time: 0.089672328 > seconds (9 MB allocated) > > Python code: > def listzip(a = ["a","b","c","d"], b = [0.2,0.1,0.1,0.6]): > c = list(zip(a,b)) > a = timeit.timeit("listzip()","from __main__ import listzip",number=1) > print(a) # 0.0105497862674 > > P.S: I need to convert the zip to an array because after that I need to > sort them. > > Thanks a lot, >
[julia-users] Re: How to optimize the collect function?
That is amazing. I just updated to the latest Julia and my timing is 1.6 ms now. Thank you for your help. On Friday, May 1, 2015 at 12:43:24 AM UTC+2, Ali Rezaee wrote: > Dear all, > > I have a ported all my project from python to Julia. However, there is one > part of my code that I have not been able to optimize much. It is between 3 > to 9 times slower than similar python code. > Do you have any suggestions / explanations? > > Julia code: > function collect_zip(a::Array=["a","b","c","d"],b::Array=[0.2,0.1,0.1,0.6 > ]) > c = collect(zip(a,b)) > end > > collect_zip() > @time for i in 1:1; j= collect_zip();end # elapsed time: 0.089672328 > seconds (9 MB allocated) > > Python code: > def listzip(a = ["a","b","c","d"], b = [0.2,0.1,0.1,0.6]): > c = list(zip(a,b)) > a = timeit.timeit("listzip()","from __main__ import listzip",number=1) > print(a) # 0.0105497862674 > > P.S: I need to convert the zip to an array because after that I need to > sort them. > > Thanks a lot, >
[julia-users] How to flush output of print?
Hi, I would like to show the progress of my Julia code while its running. But I do not want each different percent being printed in a different line in the command line. Is there a way to print something and then remove it before a new item is printed? Many thanks,
[julia-users] Evaluation of boolean expression fails
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 how can I solve this problem? Thanks in advance for your help. rules = ["(x[1] && x[2])", "(x[3] || x[4])"]; # a list of boolean expressions boolList = [false, true, false, true]; # a boolean vector for every x in rules function evaluate(rules, boolList) x = boolList result = Array{Bool}(length(rules)) for (i, rule) in enumerate(rules) result[i] = eval(parse(rule)) end return result end evaluate(rules, boolList) # ERROR: UndefVarError: x not defined # but This will work: x = boolList result = Array{Bool}(length(rules)) for (i, rule) in enumerate(rules) result[i] = eval(parse(rule)) end result # 2-element Array{Bool,1}: false true
[julia-users] Re: Evaluation of boolean expression fails
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 a macro would be the only solution. Best regards On Tuesday, April 26, 2016 at 5:38:21 PM UTC+2, 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 how can I solve this problem? > > Thanks in advance for your help. > > rules = ["(x[1] && x[2])", "(x[3] || x[4])"]; # a list of boolean > expressions > boolList = [false, true, false, true]; # a boolean vector for every x in > rules > > function evaluate(rules, boolList) > x = boolList > result = Array{Bool}(length(rules)) > for (i, rule) in enumerate(rules) > result[i] = eval(parse(rule)) > end > return result > end > > evaluate(rules, boolList) > # ERROR: UndefVarError: x not defined > > # but This will work: > x = boolList > result = Array{Bool}(length(rules)) > for (i, rule) in enumerate(rules) > result[i] = eval(parse(rule)) > end > > result > # 2-element Array{Bool,1}: false true > > >
[julia-users] Re: Evaluation of boolean expression fails
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 reaction is active. On Tuesday, April 26, 2016 at 7:28:59 PM UTC+2, Steven G. Johnson wrote: > > > > 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 solution. >> > > That's not an objective, that's an implementation. What are you > actually trying to do in which evaluating lists of boolean expressions > arises? >
[julia-users] Re: Evaluation of boolean expression fails
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: > > ``` > 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, 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 a macro would be the only solution. >> >> Best regards >> On Tuesday, April 26, 2016 at 5:38:21 PM UTC+2, 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 how can I solve this problem? >>> >>> Thanks in advance for your help. >>> >>> rules = ["(x[1] && x[2])", "(x[3] || x[4])"]; # a list of boolean >>> expressions >>> boolList = [false, true, false, true]; # a boolean vector for every x >>> in rules >>> >>> function evaluate(rules, boolList) >>> x = boolList >>> result = Array{Bool}(length(rules)) >>> for (i, rule) in enumerate(rules) >>> result[i] = eval(parse(rule)) >>> end >>> return result >>> end >>> >>> evaluate(rules, boolList) >>> # ERROR: UndefVarError: x not defined >>> >>> # but This will work: >>> x = boolList >>> result = Array{Bool}(length(rules)) >>> for (i, rule) in enumerate(rules) >>> result[i] = eval(parse(rule)) >>> end >>> >>> result >>> # 2-element Array{Bool,1}: false true >>> >>> >>>
[julia-users] Re: Evaluation of boolean expression fails
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] || x[3])"] > > function evaluate(rules, boolList) > rulefuncs = [eval(parse(string("x -> ", rule))) for rule in rules] > Bool[rf(boolList) for rf in rulefuncs] > end > > evaluate(rulestrs, [true, false, true, false]) #output: Array{Bool,1} - > [false, > true, true] > > Note the the Bool is required for the comprehension to get the correct > output type because the compiler has no idea that all the anonymous > functions return Bools. > > On Tuesday, April 26, 2016 at 2:24:18 PM UTC-4, Ali Rezaee wrote: >> >> 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: >>> >>> ``` >>> 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, 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 a macro would be the only solution. >>>> >>>> Best regards >>>> On Tuesday, April 26, 2016 at 5:38:21 PM UTC+2, 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 how can I solve this problem? >>>>> >>>>> Thanks in advance for your help. >>>>> >>>>> rules = ["(x[1] && x[2])", "(x[3] || x[4])"]; # a list of boolean >>>>> expressions >>>>> boolList = [false, true, false, true]; # a boolean vector for every x >>>>> in rules >>>>> >>>>> function evaluate(rules, boolList) >>>>> x = boolList >>>>> result = Array{Bool}(length(rules)) >>>>> for (i, rule) in enumerate(rules) >>>>> result[i] = eval(parse(rule)) >>>>> end >>>>> return result >>>>> end >>>>> >>>>> evaluate(rules, boolList) >>>>> # ERROR: UndefVarError: x not defined >>>>> >>>>> # but This will work: >>>>> x = boolList >>>>> result = Array{Bool}(length(rules)) >>>>> for (i, rule) in enumerate(rules) >>>>> result[i] = eval(parse(rule)) >>>>> end >>>>> >>>>> result >>>>> # 2-element Array{Bool,1}: false true >>>>> >>>>> >>>>>
[julia-users] function to paste into REPL?
Hi, Is there a function or macro that pastes the copied code into REPL? something similar to %paste in iPython. Thanks :)
Re: [julia-users] function to paste into REPL?
Thanks, Stefan. I get the following error, though. julia> eval(parse(clipboard())) ERROR: MethodError: `data` has no method matching data(::Symbol) in arg_gen at process.jl:624 in cmd_gen at process.jl:646 in clipboardcmd at interactiveutil.jl:95 in clipboard at interactiveutil.jl:109 On Monday, May 2, 2016 at 5:29:49 PM UTC+2, Stefan Karpinski wrote: > eval(parse(clipboard())) will do it. > > On Mon, May 2, 2016 at 7:28 AM, Ali Rezaee > wrote: > >> >> >> Hi, >> >> Is there a function or macro that pastes the copied code into REPL? >> something similar to %paste in iPython. >> >> Thanks :) >> > >
[julia-users] Re: function to paste into REPL?
Thanks, Ethan. I get the same error. Could it be an issue with my Julia installation? I am on Version 0.4.6-pre+24 (2016-04-17 03:57 UTC) On Monday, May 2, 2016 at 5:52:13 PM UTC+2, Ethan Anderes wrote: > > I use: > > function paste() > include_string(clipboard()) > return nothing > end > > and put it in my .juliarc.jl > > On Monday, May 2, 2016 at 4:28:56 AM UTC-7, Ali Rezaee wrote: > > >> >> Hi, >> >> Is there a function or macro that pastes the copied code into REPL? >> something similar to %paste in iPython. >> >> Thanks :) >> > >
Re: [julia-users] Re: function to paste into REPL?
It's working now. I didn't have xclip installed. Thanks for your help. On Monday, May 2, 2016 at 6:00:12 PM UTC+2, Stefan Karpinski wrote: > What is the code that you're pasting in? > > On Mon, May 2, 2016 at 11:56 AM, Ali Rezaee > wrote: > >> >> Thanks, Ethan. I get the same error. Could it be an issue with my Julia >> installation? >> I am on Version 0.4.6-pre+24 (2016-04-17 03:57 UTC) >> >> On Monday, May 2, 2016 at 5:52:13 PM UTC+2, Ethan Anderes wrote: >>> >>> I use: >>> >>> function paste() >>> include_string(clipboard()) >>> return nothing >>> end >>> >>> and put it in my .juliarc.jl >>> >>> On Monday, May 2, 2016 at 4:28:56 AM UTC-7, Ali Rezaee wrote: >>> >>> >>>> >>>> Hi, >>>> >>>> Is there a function or macro that pastes the copied code into REPL? >>>> something similar to %paste in iPython. >>>> >>>> Thanks :) >>>> >>> >>> >> >