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

empty %w #1394

Closed
yrashk opened this issue Jul 8, 2013 · 11 comments · Fixed by #1395
Closed

empty %w #1394

yrashk opened this issue Jul 8, 2013 · 11 comments · Fixed by #1395

Comments

@yrashk
Copy link
Contributor

yrashk commented Jul 8, 2013

iex(2)> %w()a 
** (ErlangError) erlang error: {:bad_generator, ""}
    :erl_eval.expr/3

Shouldn't this return an empty list?

cc @devinus

@devinus
Copy link

devinus commented Jul 8, 2013

@yrashk Yeah it should, not sure why %w()b works but %w()a doesn't... I'll investigate.

@yrashk
Copy link
Contributor Author

yrashk commented Jul 8, 2013

I am also curious why %w()b returns an empty string, not an empty list:

ex(6)> %w()b  
""

Also, c has the same problem as a:

iex(7)> %w()c
** (ErlangError) erlang error: {:bad_generator, ""}
    :erl_eval.expr/3

@devinus
Copy link

devinus commented Jul 8, 2013

I know why. It's a bad but simple bug.

  def split(""), do: ""

Should be:

  def split(""), do: [""]

@devinus
Copy link

devinus commented Jul 8, 2013

Follow-up: Should String.split("") return [""] or [] ?

@yrashk
Copy link
Contributor Author

yrashk commented Jul 8, 2013

My logic suggests [""]

On Mon, Jul 8, 2013 at 3:03 PM, Devin Torres notifications@github.comwrote:

Follow-up: Should String.split("") return [""] or [] ?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1394#issuecomment-20639590
.

@devinus
Copy link

devinus commented Jul 8, 2013

@yrashk What do you expect when you do %w()a ?

[:""] ??

@yrashk
Copy link
Contributor Author

yrashk commented Jul 8, 2013

[]

On Mon, Jul 8, 2013 at 3:09 PM, Devin Torres notifications@github.comwrote:

@yrashk https://github.com/yrashk What do you expect when you do %w()a ?

[:""] ??


Reply to this email directly or view it on GitHubhttps://github.com//issues/1394#issuecomment-20640016
.

@devinus
Copy link

devinus commented Jul 8, 2013

@yrashk Then they have different functionality and split_words becomes more complicated :-/

@devinus
Copy link

devinus commented Jul 8, 2013

That means %w() should be [] too. I guess that makes sense.

@yrashk
Copy link
Contributor Author

yrashk commented Jul 8, 2013

well, %w means "words" but if the thing is empty, then it means there are
no words.

I think %w(), %w()a and %w()c should return the same thing — an empty list

On Mon, Jul 8, 2013 at 3:12 PM, Devin Torres notifications@github.comwrote:

@yrashk https://github.com/yrashk Then they have different
functionality and split_words becomes more complicated :-/


Reply to this email directly or view it on GitHubhttps://github.com//issues/1394#issuecomment-20640172
.

@devinus
Copy link

devinus commented Jul 8, 2013

Indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants