 Julia 中文文档convert(Array{Float64}, a) 2×3 Array{Float64,2}: 1.0 2.0 3.0 4.0 5.0 6.0 类型转换并不总是可行的,有时 convert 函数并不知道该如何执行所请求的类型转换就会抛出 MethodError 错误。例如下例: julia> convert(AbstractFloat, "foo") ERROR: MethodError: Cannot `convert` x。相反地,如果 T 是一个可变的集合类型,那 么 T(x) 应该总是创建一个新的集合(从 x 复制元素)。 封装器类型 对于某些「封装」其它值的类型,构造函数可能会将其参数封装在一个新对象中,即使它已经是 所请求的类型。例如,用 Some(x) 表示封装了一个 x 值(在上下文中,其结果可能是一个 Some 或 nothing)。但是,x 本身可能是对象 Some(y),在这种情况下,结果为 Some(Some(y)),封装了两层。 convert(::Type{T}, x::Number) where {T<:Number} = T(x) 这意味着新的 Number 类型只需要定义构造函数,因为此定义将为它们处理 convert。在参数已经是 所请求的类型的情况下,用恒同变换来处理 convert。 158 CHAPTER 15. 类型转换和类型提升 convert(::Type{T}, x::T) where {T<:Number} = x0 码力 | 1238 页 | 4.59 MB | 1 年前3 Julia 中文文档convert(Array{Float64}, a) 2×3 Array{Float64,2}: 1.0 2.0 3.0 4.0 5.0 6.0 类型转换并不总是可行的,有时 convert 函数并不知道该如何执行所请求的类型转换就会抛出 MethodError 错误。例如下例: julia> convert(AbstractFloat, "foo") ERROR: MethodError: Cannot `convert` x。相反地,如果 T 是一个可变的集合类型,那 么 T(x) 应该总是创建一个新的集合(从 x 复制元素)。 封装器类型 对于某些「封装」其它值的类型,构造函数可能会将其参数封装在一个新对象中,即使它已经是 所请求的类型。例如,用 Some(x) 表示封装了一个 x 值(在上下文中,其结果可能是一个 Some 或 nothing)。但是,x 本身可能是对象 Some(y),在这种情况下,结果为 Some(Some(y)),封装了两层。 convert(::Type{T}, x::Number) where {T<:Number} = T(x) 这意味着新的 Number 类型只需要定义构造函数,因为此定义将为它们处理 convert。在参数已经是 所请求的类型的情况下,用恒同变换来处理 convert。 158 CHAPTER 15. 类型转换和类型提升 convert(::Type{T}, x::T) where {T<:Number} = x0 码力 | 1238 页 | 4.59 MB | 1 年前3
 Julia 1.12.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 2009 页 | 6.72 MB | 1 年前3 Julia 1.12.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 2009 页 | 6.72 MB | 1 年前3
 julia 1.10.10com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3 julia 1.10.10com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.10.9com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3 Julia 1.10.9com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download to complete in seconds, with0 码力 | 1692 页 | 6.34 MB | 3 月前3
 Julia 1.8.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1463 页 | 5.01 MB | 1 年前3 Julia 1.8.0 DEV Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1463 页 | 5.01 MB | 1 年前3
 Julia 1.11.4com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.4com", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3
 Julia 1.11.5 Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3 Julia 1.11.5 Documentationcom", "github.com", "julialang.org") @async begin conn = connect(hostname, 80) write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") Main binary filename not available. Serving web UI on http://localhost:62261 "alloc-profile.pb.gz" Then you can view the profile by navigating to http://localhost:62261, and the profile is saved to disk delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false)0 码力 | 2007 页 | 6.73 MB | 3 月前3
 Julia v1.9.4 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3 Julia v1.9.4 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3
 Julia 1.9.0 DEV Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1633 页 | 5.23 MB | 1 年前3 Julia 1.9.0 DEV Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1633 页 | 5.23 MB | 1 年前3
 Julia 1.9.3 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3 Julia 1.9.3 Documentation@async begin conn = connect(hostname, 80) CHAPTER 21. NETWORKING AND STREAMS 288 write(conn, "GET / HTTP/1.1\r\nHost:$(hostname)\r\n\r\n") readline(conn, keep=true) println("Finished connection to $(hostname)") delays=rand(5:10, 2)) retry(f, delays=Base.ExponentialBackOff(n=3, first_delay=5, max_delay=1000)) retry(http_get, check=(s,e)->e.status == "503")(url) retry(read, check=(s,e)->isa(e, IOError))(io, 128; all=false) These pairs are passed as headers when downloading URLs with protocols that supports them, such as HTTP/S. The timeout keyword argument specifies a timeout for the download in seconds, with a resolution0 码力 | 1644 页 | 5.27 MB | 1 年前3
共 87 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9













