Re: [julia-users] excessive memory allocation with @printf at compile time

2016-01-07 Thread Michael Friedlander
Thanks for the pointer — wrapping all `@printf` statements cut compile time 
down by a factor of 10!

On Thursday, January 7, 2016 at 3:27:53 PM UTC-8, Chris Stook wrote:
>
> You can see what I did here. 
>  
> https://github.com/cstook/FTD2XX.jl/blob/master/src/ft_ee_read__ft_ee_program.jl
>  
> 
>
> There are a bunch of @printf 's starting at line 450.
>
> I'm learning Julia.  There may be a better way to do this, but this worked 
> for me.
>


Re: [julia-users] How to define methods of rearranged arguments

2016-01-07 Thread Josh Day
True, but this is a special case where arguments have unique types.  The 
reason I asked is for a type in OnlineStats.jl 
, where more often than not, the 
user will probably change defaults.

StatLearn(x, y, L1Regression(), AdaGrad(), L2Penalty())

looks considerably cleaner than

StatLearn(x, y, model = L1Regression(), algorithm = AdaGrad, penalty = 
L2Penalty())

On Thursday, January 7, 2016 at 6:15:04 PM UTC-5, Tim Holy wrote:
>
> This is what keyword arguments are for. 
> http://docs.julialang.org/en/stable/manual/functions/#keyword-arguments 
>
> --Tim 
>
> On Thursday, January 07, 2016 11:02:03 AM Josh Day wrote: 
> > Suppose I have a function that takes several arguments of different 
> types 
> > and each has a default value.  What is the best way to specify all 
> possible 
> > methods where a user can specify an argument without entering the 
> defaults 
> > that come before it?  I don't want to force a user to remember the exact 
> > order of arguments.  The example below may explain this better. 
> > 
> > type A 
> > a::Int 
> > end 
> > type B 
> > b::Int 
> > end 
> > type C 
> > c::Int 
> > end 
> > f(a::A = A(1), b::B = B(1), c::C = C(1)) = ... 
> > 
> > I would like the user to be able to call  f(C(3), B(2))instead of 
> f(A(1), 
> > B(2), C(3)).  I could just implement the factorial(3)methods myself, but 
> if 
> > I want to do this for 5 types, it means I'm writing 120 methods. 
> > 
> > Is this just a terrible idea and I should use keyword arguments? 
>
>

Re: [julia-users] ArgParse @add_arg_table not recognized

2016-01-07 Thread Uthsav Chitra
(Not sure how to edit my message) Actually, I ran it how you did and it 
worked fine. But I'm still not sure why it won't run when I use 
include("arg.jl").

On Thursday, January 7, 2016 at 7:09:47 PM UTC-5, Uthsav Chitra wrote:
>
> I opened Julia in Terminal, made a file with that text called 'arg.jl', 
> and ran
>
> include("arg.jl").
>
> On Thursday, January 7, 2016 at 4:34:00 PM UTC-5, Kevin Squire wrote:
>>
>> Hello Uthsav, 
>>
>> Works for me:
>>
>> $ julia0.3 argparse_example3.jl --opt1 1 2 3
>> Parsed args:
>>   arg1  =>  {"2","3"}
>>   karma  =>  0
>>   arg2  =>  {"no_arg_given"}
>>   opt1  =>  1
>>
>> How are you trying to run that code?
>>
>> On Thu, Jan 7, 2016 at 12:36 PM, Uthsav Chitra  
>> wrote:
>>
>>> I'm using Julia v0.3.9 right now. I recently updated all my packages (I 
>>> haven't opened Julia in a couple months), including ArgParse. The macro 
>>> @add_arg_table isn't recognized though. In particular, I tried running 
>>> example code here 
>>> ,
>>>  
>>> but I get the following error:
>>>
>>> *ERROR: @add_arg_table not defined*
>>>
>>> * in include at 
>>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>>
>>> * in include_from_node1 at 
>>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>>
>>> *while loading /Users/Uthsav/Desktop/Walking The Interactome 
>>> Work/arg.jl, in expression starting on line 42*
>>>
>>>
>>> This is essentially the problem I'm having in my own code. I looked but 
>>> couldn't find any information about this besides what it says on the 
>>> Github, which is that the macro @add_arg_table should still work. Any help 
>>> would be greatly appreciated. Thanks a lot!
>>>
>>
>>

Re: [julia-users] ArgParse @add_arg_table not recognized

2016-01-07 Thread Uthsav Chitra
I opened Julia in Terminal, made a file with that text called 'arg.jl', and 
ran

include("arg.jl").

On Thursday, January 7, 2016 at 4:34:00 PM UTC-5, Kevin Squire wrote:
>
> Hello Uthsav, 
>
> Works for me:
>
> $ julia0.3 argparse_example3.jl --opt1 1 2 3
> Parsed args:
>   arg1  =>  {"2","3"}
>   karma  =>  0
>   arg2  =>  {"no_arg_given"}
>   opt1  =>  1
>
> How are you trying to run that code?
>
> On Thu, Jan 7, 2016 at 12:36 PM, Uthsav Chitra  > wrote:
>
>> I'm using Julia v0.3.9 right now. I recently updated all my packages (I 
>> haven't opened Julia in a couple months), including ArgParse. The macro 
>> @add_arg_table isn't recognized though. In particular, I tried running 
>> example code here 
>> ,
>>  
>> but I get the following error:
>>
>> *ERROR: @add_arg_table not defined*
>>
>> * in include at 
>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>
>> * in include_from_node1 at 
>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>
>> *while loading /Users/Uthsav/Desktop/Walking The Interactome Work/arg.jl, 
>> in expression starting on line 42*
>>
>>
>> This is essentially the problem I'm having in my own code. I looked but 
>> couldn't find any information about this besides what it says on the 
>> Github, which is that the macro @add_arg_table should still work. Any help 
>> would be greatly appreciated. Thanks a lot!
>>
>
>

Re: [julia-users] ArgParse @add_arg_table not recognized

2016-01-07 Thread Uthsav Chitra
Sorry! Won't happen again.

On Thursday, January 7, 2016 at 4:38:27 PM UTC-5, Stefan Karpinski wrote:
>
> Please don't cross-post questions on multiple forums: 
> http://stackoverflow.com/questions/34665140/argparse-add-arg-table-not-recognized-in-julia
> .
>
> On Thu, Jan 7, 2016 at 4:33 PM, Kevin Squire  > wrote:
>
>> Hello Uthsav, 
>>
>> Works for me:
>>
>> $ julia0.3 argparse_example3.jl --opt1 1 2 3
>> Parsed args:
>>   arg1  =>  {"2","3"}
>>   karma  =>  0
>>   arg2  =>  {"no_arg_given"}
>>   opt1  =>  1
>>
>> How are you trying to run that code?
>>
>> On Thu, Jan 7, 2016 at 12:36 PM, Uthsav Chitra > > wrote:
>>
>>> I'm using Julia v0.3.9 right now. I recently updated all my packages (I 
>>> haven't opened Julia in a couple months), including ArgParse. The macro 
>>> @add_arg_table isn't recognized though. In particular, I tried running 
>>> example code here 
>>> ,
>>>  
>>> but I get the following error:
>>>
>>> *ERROR: @add_arg_table not defined*
>>>
>>> * in include at 
>>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>>
>>> * in include_from_node1 at 
>>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>>
>>> *while loading /Users/Uthsav/Desktop/Walking The Interactome 
>>> Work/arg.jl, in expression starting on line 42*
>>>
>>>
>>> This is essentially the problem I'm having in my own code. I looked but 
>>> couldn't find any information about this besides what it says on the 
>>> Github, which is that the macro @add_arg_table should still work. Any help 
>>> would be greatly appreciated. Thanks a lot!
>>>
>>
>>
>

[julia-users] Re: Pre-ANN: StringInterpolation.jl

2016-01-07 Thread Eric Forgy
Haha! :D

Scott, that is awesome :)

I don't deserve any credit for StringInterpolation. It is simply Stefan's old 
interp_parse resurrected and even JuliaJS is largely an immitation of Blink. I 
should make this more clear in the READMEs but was rushing to get them out 
hoping to get feedback to make them better. I plan to use JuliaJS for building 
web dashboards (and maybe a Julia-based JuliaBox).

Combining your StringUtils with JuliaJS (or whatever its name will be - 
suggestions welcome - JSCall?), we can build the next Slack 🦄😃

Re: [julia-users] excessive memory allocation with @printf at compile time

2016-01-07 Thread Chris Stook
You can see what I did here. 
 
https://github.com/cstook/FTD2XX.jl/blob/master/src/ft_ee_read__ft_ee_program.jl
 


There are a bunch of @printf 's starting at line 450.

I'm learning Julia.  There may be a better way to do this, but this worked 
for me.


Re: [julia-users] Iterating over leafs of a tree: use Cartesian?

2016-01-07 Thread Asbjørn Nilsen Riseth
Ah, that makes sense. I've mostly been working with Floats, so I didn't
realise there was an Int type.

On Thu, 7 Jan 2016 at 23:02 Kristoffer Carlsson 
wrote:

> Just an unsolicited tip here.
>
> Try not to "over type" your functions. Your function here would be
> cumbersome to use for someone on a 32-bit system for example. Unless you
> have a good reason, prefer Int instead of explicit Int32 / Int64.
>
>
> On Thursday, January 7, 2016 at 7:18:31 PM UTC+1, Asbjørn Nilsen Riseth
> wrote:
>>
>> For future reference, I used the following:
>>
>> function traverse(numpoints::Int64, β::Array{Int64}, level::Int64 = 1)
>> N = length(β)
>> @assert 0 < level < N
>>
>> for i = 0:numpoints-sum(β[1:level-1])
>> β[level] = i
>> if level < N-2
>> traverse(numpoints, β, level+1)
>> else
>> for j = 0:numpoints-sum(β[1:N-2])
>> β[N-1] = j
>> β[N] = numpoints - sum(β[1:N-1])
>> @show β/numpoints
>> end
>> end
>> end
>> end
>> traverse(5, Array{Int64}(4))
>>
>> Asbjørn
>>
>>
>> On Thursday, 7 January 2016 17:14:03 UTC, Asbjørn Nilsen Riseth wrote:
>>>
>>> Thank you both. I'll have a look at a recursion approach.
>>>
>>>
>>> On Thursday, 7 January 2016 13:47:02 UTC, Tim Holy wrote:

 This is a problem for recursion. See, for example, the LightGraphs or
 Graphs
 packages.

 Best,
 --Tim

 On Thursday, January 07, 2016 02:10:18 AM Asbjørn Nilsen Riseth wrote:
 > I would like to loop over all the \beta_i values of the following
 tree.
 >
 > <
 https://lh3.googleusercontent.com/-EBjanFs-BC4/Vo409IFAiTI/MEw/U7iq
 > Ev9nPmU/s1600/tree.png>
 >
 > What is the best Julia way of doing this? I'm also interested in
 > generalising this to N levels.
 >
 >
 > For the given tree, the following works. *Is there a way to use
 @nloops to
 > shorten this?*
 > n = Int(1/0.2)
 > for i_3 = 0:n
 > for i_2 = 0:n-i_3
 > for i_1 = 0:n-i_2-i_3
 > i_0 = n-sum(@ntuple 3 i)
 > β = [i_3, i_2, i_1, i_0]/n
 > @show β
 > end
 > end
 > end




Re: [julia-users] How to define methods of rearranged arguments

2016-01-07 Thread Tim Holy
This is what keyword arguments are for.
http://docs.julialang.org/en/stable/manual/functions/#keyword-arguments

--Tim

On Thursday, January 07, 2016 11:02:03 AM Josh Day wrote:
> Suppose I have a function that takes several arguments of different types
> and each has a default value.  What is the best way to specify all possible
> methods where a user can specify an argument without entering the defaults
> that come before it?  I don't want to force a user to remember the exact
> order of arguments.  The example below may explain this better.
> 
> type A
> a::Int
> end
> type B
> b::Int
> end
> type C
> c::Int
> end
> f(a::A = A(1), b::B = B(1), c::C = C(1)) = ...
> 
> I would like the user to be able to call  f(C(3), B(2))instead of f(A(1),
> B(2), C(3)).  I could just implement the factorial(3)methods myself, but if
> I want to do this for 5 types, it means I'm writing 120 methods.
> 
> Is this just a terrible idea and I should use keyword arguments?



Re: [julia-users] Iterating over leafs of a tree: use Cartesian?

2016-01-07 Thread Kristoffer Carlsson
Just an unsolicited tip here.

Try not to "over type" your functions. Your function here would be 
cumbersome to use for someone on a 32-bit system for example. Unless you 
have a good reason, prefer Int instead of explicit Int32 / Int64.

On Thursday, January 7, 2016 at 7:18:31 PM UTC+1, Asbjørn Nilsen Riseth 
wrote:
>
> For future reference, I used the following:
>
> function traverse(numpoints::Int64, β::Array{Int64}, level::Int64 = 1)
> N = length(β)
> @assert 0 < level < N
>
> for i = 0:numpoints-sum(β[1:level-1])
> β[level] = i
> if level < N-2
> traverse(numpoints, β, level+1)
> else
> for j = 0:numpoints-sum(β[1:N-2])
> β[N-1] = j
> β[N] = numpoints - sum(β[1:N-1])
> @show β/numpoints
> end
> end
> end
> end
> traverse(5, Array{Int64}(4))
>
> Asbjørn
>
>
> On Thursday, 7 January 2016 17:14:03 UTC, Asbjørn Nilsen Riseth wrote:
>>
>> Thank you both. I'll have a look at a recursion approach.
>>
>>
>> On Thursday, 7 January 2016 13:47:02 UTC, Tim Holy wrote:
>>>
>>> This is a problem for recursion. See, for example, the LightGraphs or 
>>> Graphs 
>>> packages. 
>>>
>>> Best, 
>>> --Tim 
>>>
>>> On Thursday, January 07, 2016 02:10:18 AM Asbjørn Nilsen Riseth wrote: 
>>> > I would like to loop over all the \beta_i values of the following 
>>> tree. 
>>> > 
>>> > <
>>> https://lh3.googleusercontent.com/-EBjanFs-BC4/Vo409IFAiTI/MEw/U7iq 
>>> > Ev9nPmU/s1600/tree.png> 
>>> > 
>>> > What is the best Julia way of doing this? I'm also interested in 
>>> > generalising this to N levels. 
>>> > 
>>> > 
>>> > For the given tree, the following works. *Is there a way to use 
>>> @nloops to 
>>> > shorten this?* 
>>> > n = Int(1/0.2) 
>>> > for i_3 = 0:n 
>>> > for i_2 = 0:n-i_3 
>>> > for i_1 = 0:n-i_2-i_3 
>>> > i_0 = n-sum(@ntuple 3 i) 
>>> > β = [i_3, i_2, i_1, i_0]/n 
>>> > @show β 
>>> > end 
>>> > end 
>>> > end 
>>>
>>>

Re: [julia-users] excessive memory allocation with @printf at compile time

2016-01-07 Thread Michael Friedlander
I'm also having similar trouble: compiling a module with a couple of dozen 
`@printf` statements can take 20-30 seconds, but only a few seconds when 
these statements are commented out.

Can you please say a bit more about how the `@printf` call should be 
wrapped in a function?


On Sunday, October 4, 2015 at 1:08:06 PM UTC-7, Stefan Karpinski wrote:
>
> You can try wrapping each printf call in a function. Sorry for that 
> annoyance, it should be fixed but for now that's the workaround.
>
> On Sunday, October 4, 2015, Chris Stook > 
> wrote:
>
>> I am having difficulty troubleshooting a memory allocation problem in a 
>> show method for a user defined type.
>>
>> Compiling the show method with 126 @printf macros takes 197 seconds and 
>> allocates 5.57GB of memory.  The next call takes 0.014 seconds and 
>> allocates 27.141KB.  I moved the type and it's show method to a notebook 
>> here:
>>
>> https://github.com/cstook/julia-printf-memory-allocation
>>
>> Memory allocation for compilation seems to be exponentially related to 
>> the number of @printf macros, but I do not see any particular offending 
>> line.  This was determined by commenting out blocks of code. 
>>
>> What is the best way to troubleshoot a compile time problem?
>>
>> Chris
>>
>

Re: [julia-users] ArgParse @add_arg_table not recognized

2016-01-07 Thread Stefan Karpinski
Please don't cross-post questions on multiple forums:
http://stackoverflow.com/questions/34665140/argparse-add-arg-table-not-recognized-in-julia
.

On Thu, Jan 7, 2016 at 4:33 PM, Kevin Squire  wrote:

> Hello Uthsav,
>
> Works for me:
>
> $ julia0.3 argparse_example3.jl --opt1 1 2 3
> Parsed args:
>   arg1  =>  {"2","3"}
>   karma  =>  0
>   arg2  =>  {"no_arg_given"}
>   opt1  =>  1
>
> How are you trying to run that code?
>
> On Thu, Jan 7, 2016 at 12:36 PM, Uthsav Chitra 
> wrote:
>
>> I'm using Julia v0.3.9 right now. I recently updated all my packages (I
>> haven't opened Julia in a couple months), including ArgParse. The macro
>> @add_arg_table isn't recognized though. In particular, I tried running
>> example code here
>> ,
>> but I get the following error:
>>
>> *ERROR: @add_arg_table not defined*
>>
>> * in include at
>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>
>> * in include_from_node1 at
>> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>>
>> *while loading /Users/Uthsav/Desktop/Walking The Interactome Work/arg.jl,
>> in expression starting on line 42*
>>
>>
>> This is essentially the problem I'm having in my own code. I looked but
>> couldn't find any information about this besides what it says on the
>> Github, which is that the macro @add_arg_table should still work. Any help
>> would be greatly appreciated. Thanks a lot!
>>
>
>


Re: [julia-users] ArgParse @add_arg_table not recognized

2016-01-07 Thread Kevin Squire
Hello Uthsav,

Works for me:

$ julia0.3 argparse_example3.jl --opt1 1 2 3
Parsed args:
  arg1  =>  {"2","3"}
  karma  =>  0
  arg2  =>  {"no_arg_given"}
  opt1  =>  1

How are you trying to run that code?

On Thu, Jan 7, 2016 at 12:36 PM, Uthsav Chitra 
wrote:

> I'm using Julia v0.3.9 right now. I recently updated all my packages (I
> haven't opened Julia in a couple months), including ArgParse. The macro
> @add_arg_table isn't recognized though. In particular, I tried running
> example code here
> ,
> but I get the following error:
>
> *ERROR: @add_arg_table not defined*
>
> * in include at
> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>
> * in include_from_node1 at
> /Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*
>
> *while loading /Users/Uthsav/Desktop/Walking The Interactome Work/arg.jl,
> in expression starting on line 42*
>
>
> This is essentially the problem I'm having in my own code. I looked but
> couldn't find any information about this besides what it says on the
> Github, which is that the macro @add_arg_table should still work. Any help
> would be greatly appreciated. Thanks a lot!
>


[julia-users] ArgParse @add_arg_table not recognized

2016-01-07 Thread Uthsav Chitra
I'm using Julia v0.3.9 right now. I recently updated all my packages (I 
haven't opened Julia in a couple months), including ArgParse. The macro 
@add_arg_table isn't recognized though. In particular, I tried running 
example code here 
,
 
but I get the following error:

*ERROR: @add_arg_table not defined*

* in include at 
/Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*

* in include_from_node1 at 
/Applications/Julia-0.3.9.app/Contents/Resources/julia/lib/julia/sys.dylib*

*while loading /Users/Uthsav/Desktop/Walking The Interactome Work/arg.jl, 
in expression starting on line 42*


This is essentially the problem I'm having in my own code. I looked but 
couldn't find any information about this besides what it says on the 
Github, which is that the macro @add_arg_table should still work. Any help 
would be greatly appreciated. Thanks a lot!


Re: [julia-users] How to define methods of rearranged arguments

2016-01-07 Thread Josh Day
Thanks, Tom.  That's exactly what I'm looking for.

On Thursday, January 7, 2016 at 2:21:13 PM UTC-5, Tom Breloff wrote:
>
> Depending on how much performance you need, you could do something like:
>
> _f(a::A, b::B, c::C) = ...
>
> function f(args...)
>   a,b,c = A(1),B(1),C(1)
>   for arg in args
> T = typeof(arg)
> if T <: A
>   a = arg
> elseif T <: B
>   b = arg
> elseif T <: C
>   c = arg
> end
>   end
>   _f(a,b,c)
> end
>
> And if you need to do this in multiple places, I'm sure you could turn 
> this into a macro fairly easily.
>
>
> On Thu, Jan 7, 2016 at 2:02 PM, Josh Day  > wrote:
>
>> Suppose I have a function that takes several arguments of different types 
>> and each has a default value.  What is the best way to specify all possible 
>> methods where a user can specify an argument without entering the defaults 
>> that come before it?  I don't want to force a user to remember the exact 
>> order of arguments.  The example below may explain this better.
>>
>> type A
>> a::Int
>> end
>> type B
>> b::Int
>> end
>> type C
>> c::Int
>> end
>> f(a::A = A(1), b::B = B(1), c::C = C(1)) = ...
>>
>> I would like the user to be able to call  f(C(3), B(2))instead of f(A(1), 
>> B(2), C(3)).  I could just implement the factorial(3)methods myself, but 
>> if I want to do this for 5 types, it means I'm writing 120 methods.  
>>
>> Is this just a terrible idea and I should use keyword arguments?  
>>
>
>

Re: [julia-users] How to define methods of rearranged arguments

2016-01-07 Thread Tom Breloff
Depending on how much performance you need, you could do something like:

_f(a::A, b::B, c::C) = ...

function f(args...)
  a,b,c = A(1),B(1),C(1)
  for arg in args
T = typeof(arg)
if T <: A
  a = arg
elseif T <: B
  b = arg
elseif T <: C
  c = arg
end
  end
  _f(a,b,c)
end

And if you need to do this in multiple places, I'm sure you could turn this
into a macro fairly easily.


On Thu, Jan 7, 2016 at 2:02 PM, Josh Day  wrote:

> Suppose I have a function that takes several arguments of different types
> and each has a default value.  What is the best way to specify all possible
> methods where a user can specify an argument without entering the defaults
> that come before it?  I don't want to force a user to remember the exact
> order of arguments.  The example below may explain this better.
>
> type A
> a::Int
> end
> type B
> b::Int
> end
> type C
> c::Int
> end
> f(a::A = A(1), b::B = B(1), c::C = C(1)) = ...
>
> I would like the user to be able to call  f(C(3), B(2))instead of f(A(1),
> B(2), C(3)).  I could just implement the factorial(3)methods myself, but
> if I want to do this for 5 types, it means I'm writing 120 methods.
>
> Is this just a terrible idea and I should use keyword arguments?
>


[julia-users] How to define methods of rearranged arguments

2016-01-07 Thread Josh Day
Suppose I have a function that takes several arguments of different types 
and each has a default value.  What is the best way to specify all possible 
methods where a user can specify an argument without entering the defaults 
that come before it?  I don't want to force a user to remember the exact 
order of arguments.  The example below may explain this better.

type A
a::Int
end
type B
b::Int
end
type C
c::Int
end
f(a::A = A(1), b::B = B(1), c::C = C(1)) = ...

I would like the user to be able to call  f(C(3), B(2))instead of f(A(1), 
B(2), C(3)).  I could just implement the factorial(3)methods myself, but if 
I want to do this for 5 types, it means I'm writing 120 methods.  

Is this just a terrible idea and I should use keyword arguments?  


[julia-users] Re: Confused about unmatching method signature

2016-01-07 Thread Marco Caramma
Thanks a lot Kristoffer!

On Thursday, January 7, 2016 at 5:51:26 PM UTC, Kristoffer Carlsson wrote:
>
> First sentence should have been:
>
> A Dict{ASCIIString, Any}, is not a subtype off Dict{AbstractString, Any}.
>
> On Thursday, January 7, 2016 at 6:50:54 PM UTC+1, Kristoffer Carlsson 
> wrote:
>>
>> A Dict{AbstractString, Any}, is not a subtype off Dict{AbstractString, 
>> Any}. You can read more about why and how here: 
>> https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)
>> and 
>> http://docs.julialang.org/en/release-0.4/manual/types/#man-parametric-types
>>
>> You need something like:
>>
>> function ma{S <: AbstractString}(s1::AbstractString, ad::Array{Dict{S,Any
>> }})
>>  return (s1, ad)
>>end
>>
>>
>> On Thursday, January 7, 2016 at 6:40:34 PM UTC+1, Marco Caramma wrote:
>>>
>>> Hi, I'm having trubles understanding why the following code generate 
>>> 'method matching' errors.
>>>
>>> In my understanding this 2 signatures should be compatibles:
>>>
>>> function signature =>(::AbstractString, ::Array{Dict{AbstractString,
>>> Any},N})
>>> call signature =>(::ASCIIString, ::Array{Dict{ASCIIString,Any},1})
>>>
>>> This repl session show the problem:
>>>
>>> julia> function ma(s1::AbstractString, ad::Array{Dict{AbstractString,Any
>>> }})
>>>  return (s1, ad)
>>>end
>>> ma (generic function with 1 method)
>>>
>>>
>>> julia> function a(s1::AbstractString, s2::AbstractString, s3::
>>> AbstractString, b1::Bool)
>>>  return ma(s1, [Dict("s2"=>s2, "s3"=>s3, "b1"=>b1)])
>>>end
>>> a (generic function with 1 method)
>>>
>>>
>>> julia> ma("s1",[Dict("s2"=>"s2","s3"=>"s3","b1"=>true)])
>>> ERROR: MethodError: `ma` has no method matching ma(::ASCIIString, ::
>>> Array{Dict{ASCIIString,Any},1})
>>> Closest candidates are:
>>>   ma(::AbstractString, ::Array{Dict{AbstractString,Any},N})
>>>
>>>
>>> julia> a("s1","s2","s3", true)
>>> ERROR: MethodError: `ma` has no method matching ma(::ASCIIString, ::
>>> Array{Dict{ASCIIString,Any},1})
>>> Closest candidates are:
>>>   ma(::AbstractString, ::Array{Dict{AbstractString,Any},N})
>>>  in a at ./none:2
>>>
>>>
>>> NOTE: I'm new to Julia and I usually try to figure things out by miself 
>>> but this time I can't really see the light.
>>>
>>

[julia-users] Re: Confused about unmatching method signature

2016-01-07 Thread Kristoffer Carlsson
First sentence should have been:

A Dict{ASCIIString, Any}, is not a subtype off Dict{AbstractString, Any}.

On Thursday, January 7, 2016 at 6:50:54 PM UTC+1, Kristoffer Carlsson wrote:
>
> A Dict{AbstractString, Any}, is not a subtype off Dict{AbstractString, 
> Any}. You can read more about why and how here: 
> https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)
> and 
> http://docs.julialang.org/en/release-0.4/manual/types/#man-parametric-types
>
> You need something like:
>
> function ma{S <: AbstractString}(s1::AbstractString, ad::Array{Dict{S,Any
> }})
>  return (s1, ad)
>end
>
>
> On Thursday, January 7, 2016 at 6:40:34 PM UTC+1, Marco Caramma wrote:
>>
>> Hi, I'm having trubles understanding why the following code generate 
>> 'method matching' errors.
>>
>> In my understanding this 2 signatures should be compatibles:
>>
>> function signature =>(::AbstractString, ::Array{Dict{AbstractString,
>> Any},N})
>> call signature =>(::ASCIIString, ::Array{Dict{ASCIIString,Any},1})
>>
>> This repl session show the problem:
>>
>> julia> function ma(s1::AbstractString, ad::Array{Dict{AbstractString,Any
>> }})
>>  return (s1, ad)
>>end
>> ma (generic function with 1 method)
>>
>>
>> julia> function a(s1::AbstractString, s2::AbstractString, s3::
>> AbstractString, b1::Bool)
>>  return ma(s1, [Dict("s2"=>s2, "s3"=>s3, "b1"=>b1)])
>>end
>> a (generic function with 1 method)
>>
>>
>> julia> ma("s1",[Dict("s2"=>"s2","s3"=>"s3","b1"=>true)])
>> ERROR: MethodError: `ma` has no method matching ma(::ASCIIString, ::Array
>> {Dict{ASCIIString,Any},1})
>> Closest candidates are:
>>   ma(::AbstractString, ::Array{Dict{AbstractString,Any},N})
>>
>>
>> julia> a("s1","s2","s3", true)
>> ERROR: MethodError: `ma` has no method matching ma(::ASCIIString, ::Array
>> {Dict{ASCIIString,Any},1})
>> Closest candidates are:
>>   ma(::AbstractString, ::Array{Dict{AbstractString,Any},N})
>>  in a at ./none:2
>>
>>
>> NOTE: I'm new to Julia and I usually try to figure things out by miself 
>> but this time I can't really see the light.
>>
>

[julia-users] Confused about unmatching method signature

2016-01-07 Thread Marco Caramma
Hi, I'm having trubles understanding why the following code generate 
'method matching' errors.

In my understanding this 2 signatures should be compatibles:

function signature =>(::AbstractString, ::Array{Dict{AbstractString,Any
},N})
call signature =>(::ASCIIString, ::Array{Dict{ASCIIString,Any},1})

This repl session show the problem:

julia> function ma(s1::AbstractString, ad::Array{Dict{AbstractString,Any}})
 return (s1, ad)
   end
ma (generic function with 1 method)


julia> function a(s1::AbstractString, s2::AbstractString, s3::AbstractString
, b1::Bool)
 return ma(s1, [Dict("s2"=>s2, "s3"=>s3, "b1"=>b1)])
   end
a (generic function with 1 method)


julia> ma("s1",[Dict("s2"=>"s2","s3"=>"s3","b1"=>true)])
ERROR: MethodError: `ma` has no method matching ma(::ASCIIString, ::Array{
Dict{ASCIIString,Any},1})
Closest candidates are:
  ma(::AbstractString, ::Array{Dict{AbstractString,Any},N})


julia> a("s1","s2","s3", true)
ERROR: MethodError: `ma` has no method matching ma(::ASCIIString, ::Array{
Dict{ASCIIString,Any},1})
Closest candidates are:
  ma(::AbstractString, ::Array{Dict{AbstractString,Any},N})
 in a at ./none:2


NOTE: I'm new to Julia and I usually try to figure things out by miself but 
this time I can't really see the light.


Re: [julia-users] Iterating over leafs of a tree: use Cartesian?

2016-01-07 Thread Asbjørn Nilsen Riseth
Thank you both. I'll have a look at a recursion approach.


On Thursday, 7 January 2016 13:47:02 UTC, Tim Holy wrote:
>
> This is a problem for recursion. See, for example, the LightGraphs or 
> Graphs 
> packages. 
>
> Best, 
> --Tim 
>
> On Thursday, January 07, 2016 02:10:18 AM Asbjørn Nilsen Riseth wrote: 
> > I would like to loop over all the \beta_i values of the following tree. 
> > 
> > <
> https://lh3.googleusercontent.com/-EBjanFs-BC4/Vo409IFAiTI/MEw/U7iq 
> > Ev9nPmU/s1600/tree.png> 
> > 
> > What is the best Julia way of doing this? I'm also interested in 
> > generalising this to N levels. 
> > 
> > 
> > For the given tree, the following works. *Is there a way to use @nloops 
> to 
> > shorten this?* 
> > n = Int(1/0.2) 
> > for i_3 = 0:n 
> > for i_2 = 0:n-i_3 
> > for i_1 = 0:n-i_2-i_3 
> > i_0 = n-sum(@ntuple 3 i) 
> > β = [i_3, i_2, i_1, i_0]/n 
> > @show β 
> > end 
> > end 
> > end 
>
>

[julia-users] Re: depsy.org

2016-01-07 Thread Jeffrey Sarnoff
Andreas,

I find this on-topic.  Depsy is built and run by Impactstory and funded by the 
National Science Foundation.  They give as a contact 
email t...@impactstory.org.
I sent a brief note as an interested third party (my tax dollars at work).

Thanks,

Jeffrey Sarnoff

On Thursday, January 7, 2016 at 9:19:33 AM UTC-5, Andreas Lobinger wrote:
>
> Hello colleagues,
>
> maybe offtopic, maybe not. This crossed my desk two times the last days: 
> depsy.org, a project to show researchers impact on scientific software. 
> Currently they do R and python only, and it's my strong believe they need 
> to be informed to pick up julia along that.
>
> Wishing a happy day,
> Andreas
>
>
>

[julia-users] Re: Operating with a Float64 on an Array of Real's gives an Array of Any's

2016-01-07 Thread Kristoffer Carlsson
An Int will be automatically converted to for example Float64 if you try to 
assign an int to a Float64 array.

julia> a = Float64[1.0, 2.0]
2-element Array{Float64,1}:
 1.0
 2.0

julia> a[2] = 3
3

julia> a
2-element Array{Float64,1}:
 1.0
 3.0



On Thursday, January 7, 2016 at 4:20:55 PM UTC+1, ami...@gmail.com wrote:
>
>
>
> Le jeudi 7 janvier 2016 16:15:56 UTC+1, Kristoffer Carlsson a écrit :
>>
>> Not sure why it promotes to Any but anyway, you most likely want to use x 
>> = Float64[1.0, 2.0] or another concrete Real type unless you plan to mix 
>> the type of the items in the array.
>>
>
>> The type Real is an abstract type and anyone is free to define a new type 
>> that is a subtype of Real. The compiler can therefore to no assumptions at 
>> all about what items will be in the array so if you care about performance 
>> you should use a concrete type.
>>
>  
> Yes that was the idea, more precisely the user is likely to give either 
> Int or Float64 in this Array. So I guess I need to use only Array{Float64} 
> and convert any possible Int given by the user to a Float64.
>


[julia-users] Re: How to detect an word starts with "\" in a text

2016-01-07 Thread Steven G. Johnson


On Thursday, January 7, 2016 at 2:51:54 AM UTC-7, Tomas Lycken wrote:
>
> Does this solve your problem?
>
> julia> startswith(haystack, needle) = haystack[1:length(needle)] == needle;
>
> This is wrong for Unicode needle strings (where length(needle) is not 
necessarily equal to the number of code units in haystack), and also 
unnecessary, e.g. it will fail for startswith("αβγ", "αβ").   There is a 
built-in startswith function in Base that already does this (correctly), 
however, so defining your own startswith function is unnecessary.

> ​
>


[julia-users] Re: Operating with a Float64 on an Array of Real's gives an Array of Any's

2016-01-07 Thread amiksvi
A meaningful small test:

julia> xr = Real[rand() for i = 1:1];

julia> xf = [rand() for i = 1:1];

julia> tic(); for n = 1:1000; xr += Real[rand() for i = 1:1]; end; toc()
elapsed time: 5.51013855 seconds
5.51013855

julia> tic(); for n = 1:1000; xf += [rand() for i = 1:1]; end; toc()
elapsed time: 0.090389651 seconds
0.090389651



[julia-users] Re: Operating with a Float64 on an Array of Real's gives an Array of Any's

2016-01-07 Thread amiksvi


Le jeudi 7 janvier 2016 16:15:56 UTC+1, Kristoffer Carlsson a écrit :
>
> Not sure why it promotes to Any but anyway, you most likely want to use x 
> = Float64[1.0, 2.0] or another concrete Real type unless you plan to mix 
> the type of the items in the array.
>

> The type Real is an abstract type and anyone is free to define a new type 
> that is a subtype of Real. The compiler can therefore to no assumptions at 
> all about what items will be in the array so if you care about performance 
> you should use a concrete type.
>
 
Yes that was the idea, more precisely the user is likely to give either Int 
or Float64 in this Array. So I guess I need to use only Array{Float64} and 
convert any possible Int given by the user to a Float64.


[julia-users] Re: Pre-ANN: JuliaJS.jl

2016-01-07 Thread Eric Forgy
Mike,

Cool! Glad it worked :) (Phew!)

Tony,

Yeah, this is just javascript in the browser. No node.js. Thanks :)

On Thursday, January 7, 2016 at 10:34:38 PM UTC+8, Tony Kelman wrote:
>
> This is explicitly designed for interoperating with javascript in the 
> browser, not local js execution engines like node.js, right? Given how 
> widely used node is, it might not be unambiguous to claim JSCall.jl for a 
> browser specific interoperability package.
>
> Still, cool stuff.
>


Re: [julia-users] jl_call function in c++ code

2016-01-07 Thread Isaiah Norton
>
> Can the output, jl_value_t* ret, point to more than one output argument?


Only as a tuple or array,

On Thu, Jan 7, 2016 at 12:26 AM, Shamika  wrote:

> Can the output, jl_value_t* ret, point to more than one output argument?
>
> On Wednesday, January 6, 2016 at 7:45:33 PM UTC+5:30, Stefan Karpinski
> wrote:
>>
>> On Wed, Jan 6, 2016 at 12:15 AM, Shamika  wrote:
>>
>>>
>>> I'm using Julia in c++ code. I have a few doubts regarding the jl_call
>>> function.The code is
>>>
>>> jl_array_t *ret = (jl_array_t*)jl_call(func,args,nargs);
>>>
>>> 1. Can args contain both scalar/array values?
>>>
>>
>> Yes, both scalar and array values are represented on the C side as
>> jl_value_t*. Args will be a pointer to an array of jl_value_t* values –
>> i.e. an array of pointers (of length nargs). Some of those pointers can
>> point to scalar values on the heap, some can point to array values. These
>> can be distinguished by their type tags, which there are various macros to
>> access.
>>
>>
>>> Does it use zero based or one based indexing?
>>>
>>
>> Zero-based: everything on the C side is zero-based.
>>
>>
>>> 2. Is there any data type that can hold both scalar/array output that is
>>> returned by jl_call? Right now, I have to define the output as jl_value_t
>>> or jl_array_t. Is there something more generic?
>>>
>>
>> As I explained above, jl_value_t* is strictly more generic than
>> jl_array_t*. You can think of these as corresponding to Any and Array in
>> Julia – Array is a subtype of Any.
>>
>


[julia-users] Re: Pre-ANN: JuliaJS.jl

2016-01-07 Thread Tony Kelman
This is explicitly designed for interoperating with javascript in the browser, 
not local js execution engines like node.js, right? Given how widely used node 
is, it might not be unambiguous to claim JSCall.jl for a browser specific 
interoperability package.

Still, cool stuff.

Re: [julia-users] Question about "null/empty" values

2016-01-07 Thread Milan Bouchet-Valat
Le jeudi 07 janvier 2016 à 01:49 -0800, Tomas Lycken a écrit :
> Two common options in many 0-indexed languages (Java and C#, to name
> a couple of static ones; JavaScript and Python, to name a couple of
> dynamic) is to return either -1 or length(iterator), i.e. either the
> index before the first item, or the index after the last (-1 is by
> far the more common of the two) if no matching items are found. Since
> Julia is 1-indexed, I would say 0 or lenght(iterator) + 1 makes just
> as much sense. I could even imagine returning -1, despite having no
> obvious relation to the indices of the elements in the container,
> just because it’s familiar to many developers coming from other
> languages.
I would choose 0 for consistency with e.g. findfirst(), and because
Bool(0) == false.


> If you choose to return a Nullable{Int} (which is a fine choice), you
> should return a Nullable{Int} also when a match is found; in other
> words, if the third element matches, return Nullable(3), while if no
> element matches return Nullable{Int}(). This will preserve type
> stability and thereby not hurt performance (at least not for that
> reason :) ).
> 
> // T
> 
> On Wednesday, January 6, 2016 at 11:06:11 PM UTC+1, Erik Schnetter
> wrote:
> 
> > I would return 0 (the integer zero) or a negative number for
> > entries 
> > that are not found. This way, the return type of the function is
> > still 
> > Int. This is relevant for type stability, i.e. performance. 
> > 
> > -erik 
> > 
> > On Wed, Jan 6, 2016 at 5:01 PM, Alex  wrote: 
> > > Hello, 
> > > 
> > > Let's say I write a function which checks if a given array/vector
> > > contains a certain value and returns it's index. 
> > > 
> > > What should the function return if array doesn't contain the
> > value? 
> > > 
> > > I read carefully the section "Nothingness and missing values": 
> > > http://docs.julialang.org/en/latest/manual/faq/#nothingness-and-m
> > issing-values 
> > > 
> > > 
> > > but I don't get from it what would be a correct "julian"
> > solution. 
> > > 
> > > -- Alex 
> > 
> > 
> > 
> > 


[julia-users] Re: Iterating over leafs of a tree: use Cartesian?

2016-01-07 Thread Tomas Lycken


I don’t think so; your way of determining the loop ranges is a little bit 
too specific.

The only two ways of generating loop bounds is either from a variable 
referencing an array (or array-like object), in which case the bounds will 
be determined by the size of the array, or with an anonymous function. The 
anonymous function allows for a limited set of rewrite-rules based on the 
dimension (which is its input), but it doesn’t allow referencing another 
dimension AFAICS. The closest I could get was this, which references the 
wrong dimension:

julia> macroexpand(quote
@nloops 3 i d->0:n-i_d begin
sum(@ntuple 3 i)
end
end)

quote  # In[15], line 2:
begin  # cartesian.jl, line 31:
for i_3 = 0:n - i_3 # cartesian.jl, line 32:
nothing # cartesian.jl, line 33:
begin  # cartesian.jl, line 31:
for i_2 = 0:n - i_2 # cartesian.jl, line 32:
nothing # cartesian.jl, line 33:
begin  # cartesian.jl, line 31:
for i_1 = 0:n - i_1 # cartesian.jl, line 32:
nothing # cartesian.jl, line 33:
begin  # In[15], line 3:
sum((i_1,i_2,i_3))
end # cartesian.jl, line 34:
nothing
end
end # cartesian.jl, line 34:
nothing
end
end # cartesian.jl, line 34:
nothing
end
end
end

I guess you’ve already found it, but the full docs of Base.Cartesian are 
enlightening, especially the reference at the bottom: 
http://docs.julialang.org/en/release-0.4/devdocs/cartesian/#devdoc-cartesian-reference

// T

On Thursday, January 7, 2016 at 11:10:18 AM UTC+1, Asbjørn Nilsen Riseth 
wrote:

I would like to loop over all the \beta_i values of the following tree. 
>
>
> 
>
> What is the best Julia way of doing this? I'm also interested in 
> generalising this to N levels.
>
>
> For the given tree, the following works. *Is there a way to use @nloops 
> to shorten this?*
> n = Int(1/0.2)
> for i_3 = 0:n
> for i_2 = 0:n-i_3
> for i_1 = 0:n-i_2-i_3
> i_0 = n-sum(@ntuple 3 i)
> β = [i_3, i_2, i_1, i_0]/n
> @show β
> end
> end
> end
>
>
> ​


Re: [julia-users] Equivalent for Python .join() function

2016-01-07 Thread David Salamon
Hi Alex,

I think you're looking for join.

julia> join(1:10, " - ")
"1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10"

If you haven't tried it, :methodswith and :methods are both amazing command
line functions.

julia> methodswith(Array)
312-element Array{Method,1}:
 *{T,S}(s::Base.LinAlg.SVDOperator{T,S}, v::Array{T,1}) at
linalg/arnoldi.jl:241
[lots of output -- can be used effectively if your terminal supports "find"]

julia> methods(join)
# 1 method for generic function "join":
join(args...) at strings/io.jl:104

Hope that helps,
David

On Thu, Jan 7, 2016 at 2:47 AM, Alex  wrote:

> Hello,
>
> I have a collection of items which I need to write into the file line by
> line:
>
> A=[(item1_1, item1_2, ...), (item2_1, item2_2, ...), ...]
>
> Line 1: item1_1, item1_2, ... \n
> Line 2: item2_1, item2_2, ...  \n
> ...
>
> In order to do that I need to concatenate all elements in A[i] into the
> string. In Python I would do it very quickly using .join function like
> that:
>
> # List of tuples:
> > a=[(1,2,"a"), (4,5,"g")]
>
> # Join elements into the string
> > " ".join(str(x) for x in a[0])
> Out: '1 2 a'
>
> > " ".join(str(x) for x in a[1])
> Out: '4 5 g'
>
> Is it some equivalent for this function in Julia?
>
> --
> Alex
>


Re: [julia-users] One click execution of Julia program

2016-01-07 Thread Fred
In Thunar :

 Create a custom action within Thunar which will execute your shell script 
in a terminal window. Open Thunar > Edit > Configure custom actions... > 
Add a new custom action, then:

- On the Basic Tab:
- Name = ExecuteJulia
- Description = ExecuteJulia
- Command = "xfce4-terminal -e /usr/bin/julia %f --hold". "--hold" is 
used to keep the terminal open, and can be removed if you want
- Select an icon if you want
- On the Appearance Conditions tab:
- Select "Other files"
- File Pattern (Optional) = Change to "*.jl" instead of "*"

Le jeudi 7 janvier 2016 10:51:29 UTC+1, Fred a écrit :
>
> I solved the problem :)
>
> In XFE (http://roland65.free.fr/xfe/) associate .jl files 
> with /usr/bin/julia allows one click execution of Julia programs :)
> In Thunar, it seems to be much more difficult : 
> https://bbs.archlinux.org/viewtopic.php?id=194464
>
> Le jeudi 7 janvier 2016 10:29:57 UTC+1, Fred a écrit :
>>
>> That's true, it seems to be related to the system. 
>> On my system, lightweight (XFCE), a double click open any executable 
>> Julia program in a text editor and I don't have the choice to execute in a 
>> terminal.
>> But, if I run the program in a terminal using ./program.jl it works, 
>> indicating that the program could be run in one click.
>>
>

[julia-users] Re: Pre-ANN: JuliaJS.jl

2016-01-07 Thread Michael Hatherly
Hi Eric,

Are you planning for this to be a full-on JS interface? If so, would it 
make sense to follow the naming convention of some of the other interface 
packages like PyCall, RCall, and JavaCall? Perhaps JSCall?

I wasn't able to get the plotly example,


include(Pkg.dir("JuliaJS","examples","plotly.jl"))

working. Should it just appear in the http://localhost:8000/julia tab? The 
js"..." macro calls did work though, which is cool!

-- Mike

On Thursday, 7 January 2016 11:25:45 UTC+2, Eric Forgy wrote:
>
> Hi,
>
> Yesterday, I posted a link to a new package StringInterpolation 
> . 
> That was a warmup for this one :)
>
> JuliaJS started life as PlotlyJS 
>  
> providing 
> an interface from Julia to the recently open-sourced plotly.js 
> . By the time I finished PlotlyJS, there 
> wasn't really much "Plotly"-specific about it and I changed the name to 
> make way for Spencer's cool PlotlyJS package 
>  (which I think these two 
> packages can work happily together btw).
>
> JuliaJS is HEAVILY inspired by the awesome Blink 
>  package, but there is no dependence 
> on Atom/Electron.
>
> One thing I like about JuliaJS, other than being able to use string 
> interpolation with JS commands, is the ease at which the two-way 
> communication works. For example, you can define a callback in Julia like 
> so:
>
> callback["Run My Code Please"] =  begin
> println("Ok! I will run your code.")
> # Your code here.
> end
>
> Then, on the JavaScript side:
>
> JuliaJS.message("Run My Code Please")
>
> and guess what it does? :)
>
> I'm still learning Julia so I'm sure there are plenty of bugs and a ton of 
> ways to do things better, so feedback, issues, PRs are most welcome. 
>
> From the README:
>
> https://github.com/EricForgy/JuliaJS.jl
>
> Warning: This package is still very early in development. Feedback, issues 
> and PRs are most welcome.
>
> *JuliaJS.jl*
>
> This is simple package that allows Julia to interact with JavaScript in a 
> browser.
>
> *Installation*
>
> JuliaJS is not registered and it requires another unregistered package: 
> StringInterpolation. To install, you'll need to run the following commands:
>
> julia> Pkg.clone("https://github.com/EricForgy/StringInterpolation.jl.git";
> )
> julia> Pkg.clone("https://github.com/EricForgy/JuliaJS.jl.git";)
>
> *Usage Example:*
>
> After installation, running the following from the Julia REPL
>
> julia> using JuliaJS
> Listening on 0.0.0.0:8000...
>
> will start an HttpServer. Open your browser to http://localhost:8000/julia 
> and you should see a blank page with "JuliaJS" in the browser tab.
>
> With the browser open, run the following:
>
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
>
> If the stars are aligned, you should see several sample charts appear in 
> the browser window.
>
> *Notes:*
>
> *Interpolation*
>
> The non-standard string literal `js` supports interpolation, but at the 
> moment, the Julia expression needs to be enclosed in parentheses, e.g. 
> instead of
>
> julia> msg = "Hello World"
> julia> js"""
> console.log("$msg")
> """
>
> you will need to enclose `msg` in parentheses as illustrated below:
>
> julia> msg = "Hello World"
> julia> js"""
> console.log("$(msg)")
> """
>
> *WebSockets*
>
> JuliaJS creates an active link between Julia and your browser via 
> WebSockets so you can update your charts from Julia without reloading the 
> page. To see this, try rerunning the above example several times:
>
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
>
> Each time you run from the REPL, the charts are updated without having to 
> reload.
>
> A fun artifact of using WebSockets is that you can "broadcast" your charts 
> to several browsers and they will all get updated interactively. Here is a 
> silly 
> video  demonstrating three 
> browsers (including an iPhone) with charts being interactively controlled 
> from the Julia REPL.
>


Re: [julia-users] One click execution of Julia program

2016-01-07 Thread Fred
I solved the problem :)

In XFE (http://roland65.free.fr/xfe/) associate .jl files 
with /usr/bin/julia allows one click execution of Julia programs :)
In Thunar, it seems to be much more difficult 
: https://bbs.archlinux.org/viewtopic.php?id=194464

Le jeudi 7 janvier 2016 10:29:57 UTC+1, Fred a écrit :
>
> That's true, it seems to be related to the system. 
> On my system, lightweight (XFCE), a double click open any executable Julia 
> program in a text editor and I don't have the choice to execute in a 
> terminal.
> But, if I run the program in a terminal using ./program.jl it works, 
> indicating that the program could be run in one click.
>


[julia-users] Re: Pre-ANN: JuliaJS.jl

2016-01-07 Thread Eric Forgy
Sorry. Small correction:

callback["Run My Code Please"] =  begin
println("Ok! I will run your code.")
# Your code here.
end

should be (of course):

callback["Run My Code Please"] =  () -> begin
println("Ok! I will run your code.")
# Your code here.
end

On Thursday, January 7, 2016 at 5:25:45 PM UTC+8, Eric Forgy wrote:
>
> Hi,
>
> Yesterday, I posted a link to a new package StringInterpolation 
> . 
> That was a warmup for this one :)
>
> JuliaJS started life as PlotlyJS 
>  
> providing 
> an interface from Julia to the recently open-sourced plotly.js 
> . By the time I finished PlotlyJS, there 
> wasn't really much "Plotly"-specific about it and I changed the name to 
> make way for Spencer's cool PlotlyJS package 
>  (which I think these two 
> packages can work happily together btw).
>
> JuliaJS is HEAVILY inspired by the awesome Blink 
>  package, but there is no dependence 
> on Atom/Electron.
>
> One thing I like about JuliaJS, other than being able to use string 
> interpolation with JS commands, is the ease at which the two-way 
> communication works. For example, you can define a callback in Julia like 
> so:
>
> callback["Run My Code Please"] =  begin
> println("Ok! I will run your code.")
> # Your code here.
> end
>
> Then, on the JavaScript side:
>
> JuliaJS.message("Run My Code Please")
>
> and guess what it does? :)
>
> I'm still learning Julia so I'm sure there are plenty of bugs and a ton of 
> ways to do things better, so feedback, issues, PRs are most welcome. 
>
> From the README:
>
> https://github.com/EricForgy/JuliaJS.jl
>
> Warning: This package is still very early in development. Feedback, issues 
> and PRs are most welcome.
>
> *JuliaJS.jl*
>
> This is simple package that allows Julia to interact with JavaScript in a 
> browser.
>
> *Installation*
>
> JuliaJS is not registered and it requires another unregistered package: 
> StringInterpolation. To install, you'll need to run the following commands:
>
> julia> Pkg.clone("https://github.com/EricForgy/StringInterpolation.jl.git";
> )
> julia> Pkg.clone("https://github.com/EricForgy/JuliaJS.jl.git";)
>
> *Usage Example:*
>
> After installation, running the following from the Julia REPL
>
> julia> using JuliaJS
> Listening on 0.0.0.0:8000...
>
> will start an HttpServer. Open your browser to http://localhost:8000/julia 
> and you should see a blank page with "JuliaJS" in the browser tab.
>
> With the browser open, run the following:
>
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
>
> If the stars are aligned, you should see several sample charts appear in 
> the browser window.
>
> *Notes:*
>
> *Interpolation*
>
> The non-standard string literal `js` supports interpolation, but at the 
> moment, the Julia expression needs to be enclosed in parentheses, e.g. 
> instead of
>
> julia> msg = "Hello World"
> julia> js"""
> console.log("$msg")
> """
>
> you will need to enclose `msg` in parentheses as illustrated below:
>
> julia> msg = "Hello World"
> julia> js"""
> console.log("$(msg)")
> """
>
> *WebSockets*
>
> JuliaJS creates an active link between Julia and your browser via 
> WebSockets so you can update your charts from Julia without reloading the 
> page. To see this, try rerunning the above example several times:
>
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
> julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
>
> Each time you run from the REPL, the charts are updated without having to 
> reload.
>
> A fun artifact of using WebSockets is that you can "broadcast" your charts 
> to several browsers and they will all get updated interactively. Here is a 
> silly 
> video  demonstrating three 
> browsers (including an iPhone) with charts being interactively controlled 
> from the Julia REPL.
>


Re: [julia-users] One click execution of Julia program

2016-01-07 Thread Fred
That's true, it seems to be related to the system. 
On my system, lightweight (XFCE), a double click open any executable Julia 
program in a text editor and I don't have the choice to execute in a 
terminal.
But, if I run the program in a terminal using ./program.jl it works, 
indicating that the program could be run in one click.

Le jeudi 7 janvier 2016 02:07:09 UTC+1, ele...@gmail.com a écrit :
>
> Works for me.
>
> Note that when you run by clicking there is nowhere for the output of the 
> `println` to show, and standard input will be closed so the `readline` 
> returns EOF immediately, so it might look like it didn't run.
>
> My system offers an option to "run in terminal" when I double click which 
> gives it somewhere to show the output and to read the input from.
>
> Cheers
> Lex
>


[julia-users] Pre-ANN: JuliaJS.jl

2016-01-07 Thread Eric Forgy
Hi,

Yesterday, I posted a link to a new package StringInterpolation 
. 
That was a warmup for this one :)

JuliaJS started life as PlotlyJS 
 
providing 
an interface from Julia to the recently open-sourced plotly.js 
. By the time I finished PlotlyJS, there 
wasn't really much "Plotly"-specific about it and I changed the name to 
make way for Spencer's cool PlotlyJS package 
 (which I think these two 
packages can work happily together btw).

JuliaJS is HEAVILY inspired by the awesome Blink 
 package, but there is no dependence 
on Atom/Electron.

One thing I like about JuliaJS, other than being able to use string 
interpolation with JS commands, is the ease at which the two-way 
communication works. For example, you can define a callback in Julia like 
so:

callback["Run My Code Please"] =  begin
println("Ok! I will run your code.")
# Your code here.
end

Then, on the JavaScript side:

JuliaJS.message("Run My Code Please")

and guess what it does? :)

I'm still learning Julia so I'm sure there are plenty of bugs and a ton of 
ways to do things better, so feedback, issues, PRs are most welcome. 

>From the README:

https://github.com/EricForgy/JuliaJS.jl

Warning: This package is still very early in development. Feedback, issues 
and PRs are most welcome.

*JuliaJS.jl*

This is simple package that allows Julia to interact with JavaScript in a 
browser.

*Installation*

JuliaJS is not registered and it requires another unregistered package: 
StringInterpolation. To install, you'll need to run the following commands:

julia> Pkg.clone("https://github.com/EricForgy/StringInterpolation.jl.git";)
julia> Pkg.clone("https://github.com/EricForgy/JuliaJS.jl.git";)

*Usage Example:*

After installation, running the following from the Julia REPL

julia> using JuliaJS
Listening on 0.0.0.0:8000...

will start an HttpServer. Open your browser to http://localhost:8000/julia 
and you should see a blank page with "JuliaJS" in the browser tab.

With the browser open, run the following:

julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))

If the stars are aligned, you should see several sample charts appear in 
the browser window.

*Notes:*

*Interpolation*

The non-standard string literal `js` supports interpolation, but at the 
moment, the Julia expression needs to be enclosed in parentheses, e.g. 
instead of

julia> msg = "Hello World"
julia> js"""
console.log("$msg")
"""

you will need to enclose `msg` in parentheses as illustrated below:

julia> msg = "Hello World"
julia> js"""
console.log("$(msg)")
"""

*WebSockets*

JuliaJS creates an active link between Julia and your browser via 
WebSockets so you can update your charts from Julia without reloading the 
page. To see this, try rerunning the above example several times:

julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))
julia> include(Pkg.dir("JuliaJS","examples","plotly.jl"))

Each time you run from the REPL, the charts are updated without having to 
reload.

A fun artifact of using WebSockets is that you can "broadcast" your charts 
to several browsers and they will all get updated interactively. Here is a 
silly 
video  demonstrating three 
browsers (including an iPhone) with charts being interactively controlled 
from the Julia REPL.