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

Let fun names and method calls start with Uppercase #4934

Merged
merged 2 commits into from Sep 7, 2017
Merged

Let fun names and method calls start with Uppercase #4934

merged 2 commits into from Sep 7, 2017

Conversation

asterite
Copy link
Member

@asterite asterite commented Sep 7, 2017

So for SDL we can have:

lib LibSDL
  fun SDL_Init(flags : UInt32) : Int32
end 

LibSDL.SDL_Init(0)

Previously, the compiler would require fun names to start with lowercase, and also method calls.

This is a tiny change, but:

  1. it makes it easier to write bindings, without having to think alternative "valid" names
  2. it makes it easier to automatically generate bindings (for the same reason above)
  3. it makes it clearer for the reader what C function is being used

Of course LibSDL.init might be referring to SDL_Init, but LibSDL.SDL_Init is much more explicit. And in most cases these methods are wrapped and invoked once, so not much is saved by writing LibSDL.init.

For #4832 it means we can write LibC.DuplicateHandle and LibC.GetStdHandle (and others).

@bew
Copy link
Contributor

bew commented Sep 7, 2017

This makes it possible to write a top level fun starting with an uppercase letter, but there is no way to call this fun:

fun Top_Level_fun
  puts "foobar"
end

Top_Level_fun # => undefined constant Top_Level_fun

I think it's a good addition for fun in lib, but maybe not in top level. We could give a compile-time error when trying to define a top level fun like this, WDYT?

@asterite
Copy link
Member Author

asterite commented Sep 7, 2017

@bew Good catch. Fixed!

@ysbaddaden
Copy link
Contributor

I strongly support this change :-)

@yxhuvud
Copy link
Contributor

yxhuvud commented Sep 7, 2017

"| Disallow top-level funs that start with Uppercase"

So no toplevel methods like the Integer and String factories in Ruby will be possible? Ok.

How will uppercase methods compare against constants in name resolution? Say you have the following:

class Foo
  class X
  end 

  def X
    return Foo
  end

  def do_it
    X.new
  end
end


x = Foo.new.do_it

which X is X?

@asterite
Copy link
Member Author

asterite commented Sep 7, 2017

@yxhuvud This change only applies to lib funs. So your code won't compile because def X isn't valid.

@asterite
Copy link
Member Author

asterite commented Sep 7, 2017

@yxhuvud And if we ever allow that, X will always refer to a constant, and X() will be the method call, just like in Ruby. But for that we'd have to change generics to use another syntax, maybe Gen<T>.

@RX14
Copy link
Contributor

RX14 commented Sep 7, 2017

I thought that this wasn't just funs because the title is a bit confusing mentioning method calls.

@asterite
Copy link
Member Author

asterite commented Sep 7, 2017

Well, to be able to call funs with those names you have to allow uppercase in any call names, like in Foo.Bar and foo.Bar (because right now you can assign a lib to a variable)

@asterite
Copy link
Member Author

asterite commented Sep 7, 2017

Note that it's method calls, not method definitions ;-)

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

Successfully merging this pull request may close these issues.

None yet

5 participants