-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
Support do-block syntax for redirect_std* #275
Conversation
c63e57a
to
2a3c3ef
Compare
I don't have a copy of julia 0.3 lying around; anyone have any idea about the error? I tried adding a |
v0.3 does not support defining a function without methods. |
|
||
Run the function `f` while redirecting `STDIN` to `stream`. Upon completion, `STDIN` is restored to its prior setting. | ||
""" | ||
redirect_stdin(f::Function, stream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like overkill to have docstrings in Compat.jl. We don't do that for any other functions that we copy from newer versions.
And if you delete the docstrings, you can just put the code directly into src/Compat.jl
. And it should fix things on 0.3.
Not sure I know what you mean. This is just adding a method to each of the existing Or do you mean it's the docstring that's likely the problem? |
Sorry, browser refresh delay left things out of sync. I'll delete the docstrings. |
596cab8
to
f481964
Compare
Hmm, still no dice. I worry it's because of the |
@@ -1452,4 +1452,20 @@ else | |||
end | |||
end | |||
|
|||
if VERSION < v"0.6.0-dev.374" | |||
for (F,S) in ((:redirect_stdin, :STDIN), (:redirect_stdout, :STDOUT), (:redirect_stderr, :STDERR)) | |||
@eval @compat function Base.$F(f::Function, stream) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function Base.$F() ...
doesn't parse on 0.3. You can use import
(note that @eval import Base: $F
won't work on 0.3 either so you need to either use Expr(:import)
or just list the functions manually outside the loop)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just import the functions outside the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a parsing thing, that explains why @compat
doesn't help.
9789cea
to
828d02e
Compare
local ret | ||
$F(stream) | ||
try | ||
ret = f() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could save a few lines with try f() finally $F(STDOLD) end
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should return the value of f()
not the value of $F
though, shouldn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A try
block's value is the tail statement in try
or catch
position, not the value in finally
position.
julia> try 1 finally 2 end
1
Something killed the OSX builds, but it passed on all 3 versions on Linux and Windows. |
Oh, and thanks for the help, folks! |
* Remove `take!(::Task)` definition for Julia versions prior to 0.6 Was added in #307. * Remove `redirect_std*(f, stream)` definitions for Julia prior to v0.6 Were added in #275. * Remove at-__DIR__ macro definition for Julia versions prior to 0.6 Was added in #281. * Remove `broadcast` definition for equal-length tuples Was added in #324 and #328 * Remove definitions of `unsafe_get` and `isnull` fallsback Were added in #287. * Remove defintions of `xor` and `⊻` Were added in #289. * Definitions of `numerator` and `denominator` Were added in #290. * Remove defintion of `iszero` Was added in #305. * Remove definition of `>:` Was added in #336 * Remove definition of `take!(::Base.AbstractIOBuffer)` Was added in #290. * Remove definiton of `.&` and `.|` Were added in #306. * Remove definition of `Compat.isapprox` Was added in #309.
Ref JuliaLang/julia#18165