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

RFC: Added do-expression syntax for regex matches. #3146

Closed
wants to merge 1 commit into from

Conversation

kmsquire
Copy link
Member

This trivial patch allows one to write regex matches like

julia> match(r"(.+)@(.+\.[A-Za-z]{2,4})", "julia@julia.org") do id, dom
         println("id: $id")
         println("domain: $dom")
       end
id: julia
domain: julia.org

julia> match(r"(.+)@(.+\.[A-Za-z]{2,4})", "julia_at_julia.org") do id, dom
         println("id: $id")
         println("domain: $dom")
       end

julia> 

Also adds a short description to the manual.

(Inspired by @StefanKarpinski's match macro comment in #1448.)

Comment: I wanted to write do (id, dom), but julia didn't seem to like that. That would be more readable to me...

@StefanKarpinski
Copy link
Member

I think I like this, but there's still the idea of using for-loop syntax with an optional else block. I don't really want to add two ways to do this if we're ultimately going to go with the other one. @JeffBezanson, thoughts on this matter? Can we just add optional else blocks? References: #1288, #1448. @kmsquire, I know you've wanted something like this forever and have made a previous attempt along these lines. Sorry we haven't worked it out yet :-\

@kmsquire
Copy link
Member Author

No worries, this was more to kick the bucket than anything, and it was a
one-liner (modulo the documentation updates).

Kevin

On Mon, May 20, 2013 at 4:07 PM, Stefan Karpinski
notifications@github.comwrote:

I think I like this, but there's still the idea of using for-loop syntax
with an optional else block. I don't really want to add two ways to do this
if we're ultimately going to go with the other one. @JeffBezansonhttps://github.com/JeffBezanson,
thoughts on this matter? Can we just add optional else blocks? References:
#1288 #1288, #1448#1448.
@kmsquire https://github.com/kmsquire, I know you've wanted something
like this forever and have made a previous attempt along these lines. Sorry
we haven't worked it out yet :-\


Reply to this email directly or view it on GitHubhttps://github.com//pull/3146#issuecomment-18179563
.

@kmsquire
Copy link
Member Author

Err, my metaphors aren't coming out right... I wanted to kick something,
but probably not the bucket...

On Mon, May 20, 2013 at 4:40 PM, Kevin Squire kevin.squire@gmail.comwrote:

No worries, this was more to kick the bucket than anything, and it was a
one-liner (modulo the documentation updates).

Kevin

On Mon, May 20, 2013 at 4:07 PM, Stefan Karpinski <
notifications@github.com> wrote:

I think I like this, but there's still the idea of using for-loop syntax
with an optional else block. I don't really want to add two ways to do this
if we're ultimately going to go with the other one. @JeffBezansonhttps://github.com/JeffBezanson,
thoughts on this matter? Can we just add optional else blocks? References:
#1288 #1288, #1448#1448.
@kmsquire https://github.com/kmsquire, I know you've wanted something
like this forever and have made a previous attempt along these lines. Sorry
we haven't worked it out yet :-\


Reply to this email directly or view it on GitHubhttps://github.com//pull/3146#issuecomment-18179563
.

@StefanKarpinski
Copy link
Member

yes, we definitely don't want any bucket kicking.

@kmsquire
Copy link
Member Author

Closing for now.

I'm not sure how I feel about this. On one hand, this is nice, clean syntax. On the other, it would really be nice to tell if the match succeeded. Match.jl does fill this role, but we can revisit if we ever get for-loop-else blocks.

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.

2 participants