[julia-users] Re: Equivalent to the Python's None value for the function's default parameter value

2016-11-06 Thread Fengyang Wang
There is no need to do this in Julia; you can simply initialize in the default argument. function f(x; y=[x, x, x]) @show x y end then julia> f(1) x = 1 y = [1,1,1] because in Julia, unlike Python, the initialization is done at calltime instead of function definition time. On Friday,

[julia-users] Re: [ANN] QuickTypes.jl: Concise type definitions with default arguments

2016-10-29 Thread Fengyang Wang
It is also possible to use @type and @immutable, although the macros are slightly harder to define. macro lit_str(s); Symbol(s); end macro lit"type"(x) ... end macro lit"immutable"(x) ... end @type ... @immutable ... On Saturday, October 29, 2016 at 6:16:37 PM UTC-4, Jake Rosoman

[julia-users] Re: How to print ALL packages of Pkg.available()?

2016-10-11 Thread Fengyang Wang
The `showall` function does this. On Monday, October 10, 2016 at 3:16:20 PM UTC-4, John Paul Vasquez wrote: > > Is there a command/option to display all the elements of a very long > array? The output gets cut in the middle. For example when calling > Pkg.available(), I only see the head and

[julia-users] Re: Representation of a material conditional (implication)

2016-10-07 Thread Fengyang Wang
As Jussi Piitulainen noted, the ^ operator is backwards, so you need to wrap it around a function. On Friday, October 7, 2016 at 10:05:34 AM UTC-4, Kevin Liu wrote: > > *julia> **@code_native(b^a)* > >.section__TEXT,__text,regular,pure_instructions > > Filename: bool.jl > >

[julia-users] Re: Any examples of using Julia with online judge systems

2016-10-07 Thread Fengyang Wang
HackerRank supports Julia in its Algorithms domain and related contests. I sent a support request to extend this to the Mathematics domain. On Monday, June 27, 2016 at 10:39:52 PM UTC-4, Андрей Логунов wrote: > > Are there any projects/initiatives to apply Julia with online judge > systems

[julia-users] Re: Representation of a material conditional (implication)

2016-10-07 Thread Fengyang Wang
The ^ operator can be used for implication. Due to Curry-Howard, implication is isomorphic to function abstraction, which combinatorially can be counted using the exponentiation function. On Thursday, October 6, 2016 at 12:10:51 PM UTC-4, Kevin Liu wrote: > > How is an implication represented

[julia-users] Re: Unexpected results with typeof(DataFrame)

2016-10-07 Thread Fengyang Wang
I think you have misunderstood Kristoffer. It's possible the Int values themselves are of distinct types; note for instance julia> Array{Int, Int32(1)} Array{Int64,1} julia> Array{Int, 1} Array{Int64,1} julia> Array{Int, Int32(1)} == Array{Int, 1} false On Thursday, October 6, 2016 at

[julia-users] Re: ANN: A potential new Discourse-based Julia forum

2016-10-07 Thread Fengyang Wang
I would also personally prefer a Discourse-based forum to this Google Groups mailing list. On Saturday, September 19, 2015 at 8:16:36 PM UTC-4, Jonathan Malmaud wrote: > > Hi all, > There's been some chatter about maybe switching to a new, more modern > forum platform for Julia that could

Re: [julia-users] metaprogramming and encapsulation

2016-10-02 Thread Fengyang Wang
It is not in general possible to recover the function itself from a method, as methods are specific to types and not functions. Multiple functions can share methods if those functions have the same type. In the case of generic (or singleton) functions, you can recover the function from the

[julia-users] Re: View (a portion of a) vector as a matrix

2016-10-02 Thread Fengyang Wang
There should be no copy if you reshape a view. julia> reshape((@view x[1:6]), (3, 2)) 3×2 Base.ReshapedArray{Float64,2,SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true},Tuple{}}: 1.0 1.0 1.0 1.0 1.0 1.0 On Sunday, October 2, 2016 at 8:43:01 AM UTC-4, Alexey Cherkaev

[julia-users] Re: if-elseif-else programmatically

2016-09-24 Thread Fengyang Wang
Oh yeah, or x[direction] += rand(-1:2:1) to avoid the need for the allocation in the first place. On Sunday, September 25, 2016 at 1:01:47 AM UTC-4, Fengyang Wang wrote: > > You could even do x[direction] += rand([-1, 1]). The allocation can be > avoided by defining a global constant

[julia-users] Re: if-elseif-else programmatically

2016-09-24 Thread Fengyang Wang
You could even do x[direction] += rand([-1, 1]). The allocation can be avoided by defining a global constant with [-1, 1] as its contents. On Saturday, September 24, 2016 at 6:54:47 PM UTC-4, Steven G. Johnson wrote: > > > > On Saturday, September 24, 2016 at 6:09:14 PM UTC-4, David P. Sanders

Re: [julia-users] Understanding Nullable as immutable

2016-09-21 Thread Fengyang Wang
, 2016 at 4:50:26 PM UTC, Fengyang Wang wrote: >> >> but type piracy is bad practice. This method should really be in Base. >> > > As always, if something, should be in Base or Julia, then I think a PR is > welcome. > > [Maybe I do not fully understand this (yes, t

Re: [julia-users] Understanding Nullable as immutable

2016-09-21 Thread Fengyang Wang
There is no need to modify a copy; only the Nullable is immutable and not its underlying value. Just instead of modifying ec.title, modify get(ec.title). Like setfield!(get(ec.title), k, v). In short scripts, I often define getindex(x::Nullable) = get(x) so that I can write ec.title[] instead

[julia-users] Re: Return type of broadcast

2016-09-17 Thread Fengyang Wang
I wonder why this is desirable. A type instability in the array type is unlikely to be of much concern, because the cost of array operations will wildly overshadow the cost of a dynamic dispatch. Once the array passes a function barrier, its eltype becomes inferrable. A type instability in a

[julia-users] Re: 'which' functionality, similar to applicable

2016-09-16 Thread Fengyang Wang
In addition to Mauro's answer, programatically, you can do which(issymmetric, Tuple{typeof(fill(NaN, 1, 1))}), which is almost your preferred syntax.

[julia-users] Return type of broadcast

2016-09-16 Thread Fengyang Wang
julia> foo(x) = 0 foo (generic function with 1 method) julia> foo(x::Int) = 0.0 foo (generic function with 2 methods) julia> foo.(Any[1, 2, 3]) 3-element Array{Float64,1}: 0.0 0.0 0.0 julia> foo.(Number[1, 2, 3]) 3-element Array{Number,1}: 0.0 0.0 0.0 My understanding was that the actual

Re: [julia-users] hashing floating point zeroes

2016-09-13 Thread Fengyang Wang
This is an intuitive explanation, but the mathematics of IEEE floating points seem to be designed so that 0.0 represents a "really small positive number" and -0.0 represents "exact zero" or at least "an even smaller really small negative number"; hence -0.0 + 0.0 = 0.0. I never understood this

[julia-users] Re: Preferred MIME type for Julia

2016-09-10 Thread Fengyang Wang
Should application/julia perhaps be recognized as a text MIME, then? julia> istextmime("application/julia") false julia> istextmime("application/javascript") true A PR making this change: https://github.com/JuliaLang/julia/pull/18441

[julia-users] Preferred MIME type for Julia

2016-09-08 Thread Fengyang Wang
What is the standard MIME type for Julia code? My reading of the MIME standard leads to me think application/x-julia is the accurate choice. However, I could only find few results on Google, and Julia doesn't currently recognize this as a text MIME.

Re: [julia-users] How do I write `import Base.!` in julia 0.5?

2016-08-08 Thread Fengyang Wang
On Monday, August 8, 2016 at 10:26:46 AM UTC-4, Kevin Squire wrote: > > Try > > import Base.(!) > > Cheers, > Kevin > Why do import statements have different syntax? This syntax, I'm pretty sure, has either meant getfield or broadcast—in neither case does it actually refer to the !

Re: [julia-users] help with ccall- pointers-to-pointers

2016-08-04 Thread Fengyang Wang
Generally, pointers returned from ccalls should be freed with the free function from the same library. From the documentation of Libc.free: Call free from the C standard library. Only use this on memory obtained from > malloc, not on pointers retrieved from other C libraries. Ptr objects >

Re: [julia-users] vector of vectors to array

2016-07-02 Thread Fengyang Wang
Hi Ferran, Just a quick note that any solution (including Mauro's) *must* make a copy—as the original vectors are not contiguous in memory, they have to be copied to form an array.

[julia-users] Re: Which way is preferred to define a closure?

2016-07-02 Thread Fengyang Wang
let is lowered to what is basically a function that's executed immediately. It should have identical performance on 0.5. On Friday, July 1, 2016 at 10:31:20 AM UTC-4, David Gold wrote: > > Depends which version you're on. On 0.5, where anonymous functions are > performant, I think the way to go

[julia-users] Re: Fixing some parameters of parametrized type?

2016-07-02 Thread Fengyang Wang
I don't know about performance or correctness, but it *is* possible to do something like this: x :: SomeType{X, TypeVar(:T), Z} but I think the typealias is a better solution.

[julia-users] Re: Fixing some parameters of parametrized type?

2016-07-02 Thread Fengyang Wang
The typealias is the best solution I know of.

[julia-users] Re: Any examples of using Julia with online judge systems

2016-06-28 Thread Fengyang Wang
This would be one form of tech evangelism. I wonder if there are any communities set up for Julia evangelism?

[julia-users] Re: Function in module templated on types defined later

2016-06-20 Thread Fengyang Wang
This can't work because it would not, for instance, make sense to use module `M` independently. You could use the parent module from `M`, but as it stands that won't work either because loading the parent module will try to use `f` from `M`. What are you trying to do? On Monday, June 20, 2016

[julia-users] Re: printing specific RGB colors

2016-06-18 Thread Fengyang Wang
Are you using solarized, by any chance? That terminal theme is notorious for changing around the meaning of colours. I would avoid it if possible.

Re: [julia-users] Using `Rational` with `Poly`

2016-02-12 Thread Fengyang Wang
> > On Saturday, February 6, 2016, Fengyang Wang <fengya...@gmail.com > > wrote: > >> I was looking for a Julia package to handle rational functions, when I >> noticed that the `Polynomials` package implements `gcd`, `div`, and `rem`. >> So it would be possibl

[julia-users] Using `Rational` with `Poly`

2016-02-06 Thread Fengyang Wang
I was looking for a Julia package to handle rational functions, when I noticed that the `Polynomials` package implements `gcd`, `div`, and `rem`. So it would be possible to simply use `Rational{Poly}`... or so I thought. Unfortunately, the type `Rational` prevents this use, since it requires

[julia-users] Re: Convert ASCIIString to Uint8

2016-02-06 Thread Fengyang Wang
collect(UInt8, "hello world") should do the trick. On Saturday, February 6, 2016 at 8:31:19 PM UTC-5, icebl...@gmail.com wrote: > > Hello, > > I m trying to convert ASCIIString (or ASCII) to Uint8 . > > b"string" seems to be the option. However it doesnt seem to handle > b"$(variable)" > >

Re: [julia-users] Julia as scripting language for larger project

2015-08-26 Thread Fengyang Wang
On Wednesday, August 26, 2015 at 1:17:06 PM UTC-4, Stefan Karpinski wrote: Is JavaScript actually easy to integrate with Java? Java has always come bundled with a Javascript interpreter (first Rhino, now Nashorn). It can be used like this: *package sample1;* *import

Re: [julia-users] Julia as scripting language for larger project

2015-08-26 Thread Fengyang Wang
Thank you for your response! This has been very helpful.

[julia-users] Julia as scripting language for larger project

2015-08-26 Thread Fengyang Wang
Hi, I learned Julia recently, and I must say it has been incredible for scientific work. I am in love with the clean, modern syntax. Props to the developers for their tireless efforts to improve this language even further! Historically, Lua and Javascript have been the most common choices for