Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returned object from function gets lost #2997

Closed
tshort opened this issue May 2, 2013 · 0 comments
Closed

Returned object from function gets lost #2997

tshort opened this issue May 2, 2013 · 0 comments
Assignees
Labels
kind:bug Indicates an unexpected problem or unintended behavior

Comments

@tshort
Copy link
Contributor

tshort commented May 2, 2013

Here is an example where the return object from a function gets lost after it is called. The result ends up being Nothing.

This was found by @bsxfan who also reported that this is similar to #2161 and #2562:

Here is the shortest example I could come up with. It occurs with v0.1.2 and a just updated Julia.

module DualNumbers
import Base.show, Base.cat, Base.vcat, Base.hcat
export DualNum,dualnum

typealias FloatNum Union(Float64, Vector{Float64})

# This is the main new type declared here. The two components can be scalar, vector or matrix, 
# but must agree in type and shape.
type DualNum{T<:FloatNum} 
  st::T # standard part
  di::T # differential part
end
function dualnum{T<:FloatNum}(s::T,d::T) 
  return DualNum(s,d)  # construction given float types that agree
end

dualnum{T<:FloatNum}(s::T) = dualnum(s,zero(s))

function cat(k::Integer,x::DualNum,y::DualNum)
    ST = cat(k,x.st,y.st)
    DI = cat(k,x.di,y.di)
    D = dualnum(ST,DI)
    @show D
    return D
end

vcat(x::DualNum,y::DualNum) = cat(1,x,y)
hcat(x::DualNum,y::DualNum) = cat(2,x,y)

end # module

# Example
a = DualNumbers.dualnum(1.0)
b = DualNumbers.dualnum(2.0)
d = [a,b]
@show d   # shouldn't be Nothing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants