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

Support do-block syntax for redirect_std* #275

Merged
merged 1 commit into from
Aug 25, 2016
Merged

Support do-block syntax for redirect_std* #275

merged 1 commit into from
Aug 25, 2016

Conversation

timholy
Copy link
Member

@timholy timholy commented Aug 23, 2016

@timholy timholy force-pushed the teh/redirect branch 2 times, most recently from c63e57a to 2a3c3ef Compare August 23, 2016 17:41
@timholy
Copy link
Member Author

timholy commented Aug 23, 2016

I don't have a copy of julia 0.3 lying around; anyone have any idea about the error? I tried adding a @compat but that didn't seem to help.

@TotalVerb
Copy link
Contributor

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)
Copy link
Member

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.

@timholy
Copy link
Member Author

timholy commented Aug 23, 2016

Not sure I know what you mean. This is just adding a method to each of the existing redirect_std* functions.

Or do you mean it's the docstring that's likely the problem?

@timholy
Copy link
Member Author

timholy commented Aug 23, 2016

Sorry, browser refresh delay left things out of sync. I'll delete the docstrings.

@timholy timholy force-pushed the teh/redirect branch 2 times, most recently from 596cab8 to f481964 Compare August 23, 2016 22:23
@timholy
Copy link
Member Author

timholy commented Aug 23, 2016

Hmm, still no dice. I worry it's because of the Base.$F part, but I've tried with and without @compat and it doesn't seem to matter.

@@ -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)
Copy link
Contributor

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)

Copy link
Member

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.

Copy link
Member Author

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.

@timholy timholy force-pushed the teh/redirect branch 2 times, most recently from 9789cea to 828d02e Compare August 24, 2016 15:20
local ret
$F(stream)
try
ret = f()
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

@TotalVerb TotalVerb Aug 25, 2016

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

@timholy
Copy link
Member Author

timholy commented Aug 25, 2016

Something killed the OSX builds, but it passed on all 3 versions on Linux and Windows.

@timholy
Copy link
Member Author

timholy commented Aug 25, 2016

Oh, and thanks for the help, folks!

@timholy timholy merged commit 08d559f into master Aug 25, 2016
@timholy timholy deleted the teh/redirect branch August 25, 2016 18:45
martinholters added a commit that referenced this pull request Aug 31, 2018
martinholters added a commit that referenced this pull request Aug 31, 2018
stevengj pushed a commit that referenced this pull request Sep 5, 2018
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants