Why am I getting the error message below? (I'm fairly new to metaprogramming in Julia.) Thanks.
julia> d = :e
:e
julia> macroexpand(:(b.$d))
:(b.e)
julia> macroexpand(:($d.c))
:(e.c)
julia> macroexpand(:(b.$d.c))
ERROR: unsupported or misplaced expression $
julia> macroexpand(:(b.$(d).c))
ERROR: unsupported or misplaced expression $
This was a bug, issue filed here:
https://github.com/JuliaLang/julia/issues/10997
It has been fixed since. As indicated in the comments on the question, there are some hacky workarounds if you're stuck on an unfixed Julia version, but hopefully you can upgrade.
Related
I am updating my code from Julia v0.6 to v0.7. I get the following error at runtime:
Warning: Deprecated syntax `parametric method syntax Base.show{S (io::IO, m::Base.MIME("text/plain"), scvec::Vector{StatesContainer{S}}) around /Users/logankilpatrick/.julia/packages/SHERPA/A8APz/src/utils/states_containers.jl:74.
Use Base.show(io::IO, m::Base.MIME("text/plain"), scvec::Vector{StatesContainer{S}}) where S instead.
So I do the following:
Original code: Base.show{S}(io::IO, m::Base.MIME("text/plain"), scvec::Vector{StatesContainer{S}})
Updated Code: function Base.show(io::IO, m::Base.MIME("text/plain"), scvec::Vector{StatesContainer{S}}) where S
I still get the following error: ERROR: LoadError: LoadError: ArgumentError: invalid type for argument m in method definition for show at /Users/logankilpatrick/.julia/packages/SHERPA/A8APz/src/utils/states_containers.jl:74
All line 74 shows is: println(io, typeof(scvec))
Any suggestions as to how to resolve this issue?
Thanks!
Note: I tried commenting out what was on line 74, and re-running it. It then said there was an issue with line 76!
I also tried getting rid of the "where S" part at the end of the function but that doesn't resolve the issue.
A correct signature is:
Base.show(io::IO, m::MIME{Symbol("text/plain")}, scvec::Vector{StatesContainer{S}}) where S
I'm just experimenting with Julia and found that it gives incorrect value when run:
Input:
println(1000^6)
println(1000^7)
println(1000^8)
println(1000^9)
Output:
1000000000000000000
3875820019684212736
2003764205206896640
-6930898827444486144
Is this an issue or am I doing it wrong?
As explained the problem is due to integer overflow. Maximum value you can store in an Int64 can be obtained thanks to
julia> typemax(Int64)
9223372036854775807
However, 1000^9 is bigger, as you can see with:
julia> BigInt(1000)^9
1000000000000000000000000000
isdefined(:x) will tell you if a variable x is defined in your current workspace.
If I want to check a variable is defined in a module (not one that's exported), how can I do that? I tried all of the following:
julia> module Test
x = 1
end
Test
julia> x
ERROR: UndefVarError: x not defined
julia> isdefined(:x)
false
julia> Test.x
1
julia> isdefined(:Test.x)
ERROR: type Symbol has no field x
julia> isdefined(:Test.:x)
ERROR: TypeError: getfield: expected Symbol, got QuoteNode
julia> isdefined(Test.:x)
ERROR: TypeError: getfield: expected Symbol, got QuoteNode
In the module Test above, I want to check if x is defined or not.
isdefined has an optional parameter for doing this. Try:
isdefined(Test, :x)
More information available through the usual channels: ?isdefined on the REPL and in the book: http://docs.julialang.org/en/release-0.4/stdlib/base/#Base.isdefined (link may be for older version, so the currently dominant search engine will help).
I think you need
:x in names(Test)
In Julia 1.1.0, isdefined's first parameter is not optional, instead there is a macro #isdefined(x) or #isdefined x that tests if x is defined. Calling it inside Test, checks if x is defined when in Test (inherited or not).
See documentation.
I recently tried to compute the Type-I DCT of an array in Julia using the r2r standard-library function, and got errors. I tried to execute the following minimal example:
dat = [5; 4; 3; 1];
r2r(dat, "FFTW.REDFT00")
I encountered this error message:
ERROR: r2r not defined
I can't figure out what this means. The r2r function is supposedly built-in to Julia 0.3.0, so how is it possible that it is giving a syntax error here? For comparison, the dct (Type-II discrete cosine transform) works properly on dat.
Or am I just doing a silly syntax error?
EDIT
I just tried it in Julia 0.2.1 and I got the same error. This significantly elevates the probability that I am simply being an idiot, and that the function is not broken. However, confirmation would be great! :)
r2r is built-in, but that doesn't mean it's available under that name in the standard scope. As the docs you linked say:
The following functions are defined within the Base.FFTW module.
And so:
julia> dat = [5; 4; 3; 1];
julia> FFTW.r2r(dat, FFTW.REDFT00)
4-element Array{Float64,1}:
20.0
5.0
-1.0
2.0
I am using an implementation of common lisp called CCL and I have run into a strange issue that I do not quite understand.
When I call:
(read-from-string "(=)")
I get a list containing the equal operator:
(=)
But when I call:
(read-from-string "(<)")
I get a backslash in front of the <:
(\<)
I find this quite confusing and I am wondering if this may be specific to my implementation or is this an intended part of the spec? Why would this \ show for < and > but not =?
Is there anyway to avoid the backslash?
The backslash is just a presentation issue.
When you do (mapcar #'symbol-name (read-from-string "(<)")) you probably get ("<"), so you are getting the right symbol.
If you want, you can report this as a bug to the CCL maintainers, since this backslash is a (minor) deviation from the ANSI CL standard.