Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks!
John Lam (IRONRUBY)
2008-Nov-26 04:11 UTC
[Ironruby-core] IronRuby and XNA. Super and Generics
We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Curt Hagenlocher
2008-Nov-26 15:45 UTC
[Ironruby-core] IronRuby and XNA. Super and Generics
For the first problem, does it work if you just use "super" without any arguments? -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Hi Curt! Unfortunatelly it does not work. The error returned is the same. :( 2008/11/26 Curt Hagenlocher <curth at microsoft.com>:> For the first problem, does it work if you just use "super" without any arguments? > > -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o > Sent: Tuesday, November 25, 2008 6:26 PM > To: ironruby-core at rubyforge.org > Subject: [Ironruby-core] IronRuby and XNA. Super and Generics > > Hi guys! > > Im playing with XNA trying to run the simplest xna example: To show a > SpriteBatch on screen. > > After some tests I found some problems: > > 1- The "Microsoft::Xna::Framework::Game" expects that we implement > some methods like "Update", "Drawn" etc, and inside the method we have > to call the base class (super) actual method passing some parameters. > > If I try to do this: > > def update(game_time) > super(game_time) > end > > I get this error: > > my_game.rb:23:in `update'': wrong number or type of arguments for > `update'' (ArgumentError) > from Snippets.scripting:0:in `Update'' > from Microsoft.Xna.Framework.Game:0:in `Run'' > from program.rb:23:in `main'' > from :0 > > 2- XNA uses generic functions to load the game contents. How can I > convert the code above to IronRuby? > > // This is a texture we can render. > Texture2D myTexture; > > protected override void LoadContent() > { > myTexture = Content.Load<Texture2D>("mytexture"); > } > > Can IronRuby consume generics? > > Thanks! > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >
Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com>:> We can''t consume generic methods today. It''s on the list of things to do though. > > You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. > > Thanks, > -John > > -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o > Sent: Tuesday, November 25, 2008 6:26 PM > To: ironruby-core at rubyforge.org > Subject: [Ironruby-core] IronRuby and XNA. Super and Generics > > Hi guys! > > Im playing with XNA trying to run the simplest xna example: To show a > SpriteBatch on screen. > > After some tests I found some problems: > > 1- The "Microsoft::Xna::Framework::Game" expects that we implement > some methods like "Update", "Drawn" etc, and inside the method we have > to call the base class (super) actual method passing some parameters. > > If I try to do this: > > def update(game_time) > super(game_time) > end > > I get this error: > > my_game.rb:23:in `update'': wrong number or type of arguments for > `update'' (ArgumentError) > from Snippets.scripting:0:in `Update'' > from Microsoft.Xna.Framework.Game:0:in `Run'' > from program.rb:23:in `main'' > from :0 > > 2- XNA uses generic functions to load the game contents. How can I > convert the code above to IronRuby? > > // This is a texture we can render. > Texture2D myTexture; > > protected override void LoadContent() > { > myTexture = Content.Load<Texture2D>("mytexture"); > } > > Can IronRuby consume generics? > > Thanks! > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >
I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com>:> We can''t consume generic methods today. It''s on the list of things to do though. > > You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. > > Thanks, > -John > > -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o > Sent: Tuesday, November 25, 2008 6:26 PM > To: ironruby-core at rubyforge.org > Subject: [Ironruby-core] IronRuby and XNA. Super and Generics > > Hi guys! > > Im playing with XNA trying to run the simplest xna example: To show a > SpriteBatch on screen. > > After some tests I found some problems: > > 1- The "Microsoft::Xna::Framework::Game" expects that we implement > some methods like "Update", "Drawn" etc, and inside the method we have > to call the base class (super) actual method passing some parameters. > > If I try to do this: > > def update(game_time) > super(game_time) > end > > I get this error: > > my_game.rb:23:in `update'': wrong number or type of arguments for > `update'' (ArgumentError) > from Snippets.scripting:0:in `Update'' > from Microsoft.Xna.Framework.Game:0:in `Run'' > from program.rb:23:in `main'' > from :0 > > 2- XNA uses generic functions to load the game contents. How can I > convert the code above to IronRuby? > > // This is a texture we can render. > Texture2D myTexture; > > protected override void LoadContent() > { > myTexture = Content.Load<Texture2D>("mytexture"); > } > > Can IronRuby consume generics? > > Thanks! > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >_______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
On Wed, Nov 26, 2008 at 12:04 PM, Tomas Matousek < Tomas.Matousek at microsoft.com> wrote:> I''m thinking of something like: > > myTexture = content.load of(Texture2D), "mytexture" > > I.e. we would add Kernel#of method that takes a list of classes/modules and > returns a special object representing generic parameters that binder would > use for selecting the right method. > > We are open for more ideas. >Couldn''t you just send in the constant? What would the Kernel#of method do for you? myTexture = content.load Texture2D, "mytexture" Or, could you use method_missing? myTexture = content.load_Texture2D "mytexture" Tomas> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/e0b84e21/attachment.html>
What if the method has signature m<T>(object x, ... T...). How do we know you don''t want to pass the value of constant Texture2D as x? "of" would wrap it into an internal class that would be known as carrying generic parameter types and always unwrapped. load_Texture2D clashes with name mangling and is not composable. What if you want to call method with parameter Dictionary<string, List<object>>? With "of" you would do: load of(Dictionary.of(System::String, List.of(Object)) Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Mike Moore Sent: Wednesday, November 26, 2008 12:02 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics On Wed, Nov 26, 2008 at 12:04 PM, Tomas Matousek <Tomas.Matousek at microsoft.com<mailto:Tomas.Matousek at microsoft.com>> wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Couldn''t you just send in the constant? What would the Kernel#of method do for you? myTexture = content.load Texture2D, "mytexture" Or, could you use method_missing? myTexture = content.load_Texture2D "mytexture" Tomas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/73e2a4a6/attachment-0001.html>
An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/b862210e/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.jpg Type: image/jpeg Size: 8147 bytes Desc: not available URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/b862210e/attachment.jpg>
VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C94FC4.9226CB10] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/55f3e500/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/55f3e500/attachment-0001.jpg>
An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/70e78a76/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 8147 bytes Desc: not available URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/70e78a76/attachment-0001.jpe> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.jpg Type: image/jpeg Size: 8147 bytes Desc: not available URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/70e78a76/attachment-0001.jpg>
It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C94FDC.CDF31870] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C94FDC.CDF31870] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/6dc1fdf9/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/6dc1fdf9/attachment-0001.jpg>
An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/61f98454/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 8147 bytes Desc: not available URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/61f98454/attachment-0001.jpe> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.jpg Type: image/jpeg Size: 8147 bytes Desc: not available URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081127/61f98454/attachment-0001.jpg>
For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C94FE1.C5C6B620] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C94FE1.C5C6B620] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C94FE1.C5C6B620] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/93da89cf/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081126/93da89cf/attachment-0001.jpg>
Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C971E2.93B1F230] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C971E2.93B1F230] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C971E2.93B1F230] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090108/e76156ff/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090108/e76156ff/attachment-0001.jpg>
That might also work. There might be ambiguities however (as with any name prefixes/suffixes). What if there are methods, for example, GetClass<T>() and GetClassOf(object)? What would get_class_of(String) mean? Maybe we could define a priority. But that is IMO too magical. Also, the mangling works in two steps: 1) the method name is tried as written (thus you can use Array.ConvertAll(...)) 2) mangled name is tried if 1) fails. Hence we might need to handle -Of suffix as well to be consistent, if the PascalCase style is preferred by the user. And that would lead to more ambiguities. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, January 08, 2009 10:58 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Generic method synxtax Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C971EC.010A69D0] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C971EC.010A69D0] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C971EC.010A69D0] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/73d3abf5/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/73d3abf5/attachment-0001.jpg>
Yup, it can theoretically cause an ambiguity, but in reality, I doubt we will ever run into a case of a class having both Foo<T> and FooOf. We can scan all of .NET 3.5 to see if there is any clash of this form. And as you say, if we really cared, we could define some priortization scheme to deal with it and/or have some other scheme like using Kernel#send to be able to get to the lower priority case. We have to deal with this in other cases too where Ruby keyword names clash with .NET api names, right? I think we should optimize for the 99.9% case (there will be no clashes) rather than chosing a suboptimal syntax that can handle the 0.1% case. Yes, we should probably do the "Of" suffix as well if we do "_of". Thanks, Shri From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 12:16 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax That might also work. There might be ambiguities however (as with any name prefixes/suffixes). What if there are methods, for example, GetClass<T>() and GetClassOf(object)? What would get_class_of(String) mean? Maybe we could define a priority. But that is IMO too magical. Also, the mangling works in two steps: 1) the method name is tried as written (thus you can use Array.ConvertAll(...)) 2) mangled name is tried if 1) fails. Hence we might need to handle -Of suffix as well to be consistent, if the PascalCase style is preferred by the user. And that would lead to more ambiguities. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, January 08, 2009 10:58 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Generic method synxtax Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97240.CC8E21B0] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97240.CC8E21B0] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97240.CC8E21B0] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/63280183/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/63280183/attachment-0001.jpg>
Here are the ideas that stand out to me: I like Tomas''s idea, since it reads like C#/VB, but adding an argument to the front urks me: content.load of(Texture2D), "mytexture" Shri, having the "_of" appended to a generic method name and requiring a ".do" after it is how you would work with lambdas (except you do ".call"), but since we''re talking about .NET methods, not .NET delegates. So, I''d like the syntax to look more like a method call. Also, as Tomas says, mangling gets more complicated ... content.load_of(Texture2D).call "mytexture" How about adding an "of" method to the class/object, to put the class in a generic "mode"? The method probably shouldn''t be called "of", but you get the idea. It reads different than C#, but seems the most Rubyesk without changing the arguments. content.of(Texture2D).load "mytexture" Thoughts? If no one likes my idea, I think Tomas''s is a fine compromise. ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Friday, January 09, 2009 9:58 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Yup, it can theoretically cause an ambiguity, but in reality, I doubt we will ever run into a case of a class having both Foo<T> and FooOf. We can scan all of .NET 3.5 to see if there is any clash of this form. And as you say, if we really cared, we could define some priortization scheme to deal with it and/or have some other scheme like using Kernel#send to be able to get to the lower priority case. We have to deal with this in other cases too where Ruby keyword names clash with .NET api names, right? I think we should optimize for the 99.9% case (there will be no clashes) rather than chosing a suboptimal syntax that can handle the 0.1% case. Yes, we should probably do the "Of" suffix as well if we do "_of". Thanks, Shri From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 12:16 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax That might also work. There might be ambiguities however (as with any name prefixes/suffixes). What if there are methods, for example, GetClass<T>() and GetClassOf(object)? What would get_class_of(String) mean? Maybe we could define a priority. But that is IMO too magical. Also, the mangling works in two steps: 1) the method name is tried as written (thus you can use Array.ConvertAll(...)) 2) mangled name is tried if 1) fails. Hence we might need to handle -Of suffix as well to be consistent, if the PascalCase style is preferred by the user. And that would lead to more ambiguities. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, January 08, 2009 10:58 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Generic method synxtax Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725A.DCFA15D0] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725A.DCFA15D0] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725A.DCFA15D0] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/03d0b904/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/03d0b904/attachment-0001.jpg>
Orion mentioned below the idea of adding "of" to the class. Here is how it would read. These calls actually read reasonably well since they are all static methods. I would be curious to see examples of instance methods, and how this scheme would read in that case. Anyone know of real world examples of generic instance methods? Array.of(Fixnum, String).convert_all data, lambda {|x|x.to_s } Content.of(Texture2d).load "mytexture" System::Activator.of(String).create_instance System::Linq::Enumerable.of(String).count string_array Thanks, Shri From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Friday, January 09, 2009 1:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Here are the ideas that stand out to me: I like Tomas''s idea, since it reads like C#/VB, but adding an argument to the front urks me: content.load of(Texture2D), "mytexture" Shri, having the "_of" appended to a generic method name and requiring a ".do" after it is how you would work with lambdas (except you do ".call"), but since we''re talking about .NET methods, not .NET delegates. So, I''d like the syntax to look more like a method call. Also, as Tomas says, mangling gets more complicated ... content.load_of(Texture2D).call "mytexture" How about adding an "of" method to the class/object, to put the class in a generic "mode"? The method probably shouldn''t be called "of", but you get the idea. It reads different than C#, but seems the most Rubyesk without changing the arguments. content.of(Texture2D).load "mytexture" Thoughts? If no one likes my idea, I think Tomas''s is a fine compromise. ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Friday, January 09, 2009 9:58 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Yup, it can theoretically cause an ambiguity, but in reality, I doubt we will ever run into a case of a class having both Foo<T> and FooOf. We can scan all of .NET 3.5 to see if there is any clash of this form. And as you say, if we really cared, we could define some priortization scheme to deal with it and/or have some other scheme like using Kernel#send to be able to get to the lower priority case. We have to deal with this in other cases too where Ruby keyword names clash with .NET api names, right? I think we should optimize for the 99.9% case (there will be no clashes) rather than chosing a suboptimal syntax that can handle the 0.1% case. Yes, we should probably do the "Of" suffix as well if we do "_of". Thanks, Shri From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 12:16 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax That might also work. There might be ambiguities however (as with any name prefixes/suffixes). What if there are methods, for example, GetClass<T>() and GetClassOf(object)? What would get_class_of(String) mean? Maybe we could define a priority. But that is IMO too magical. Also, the mangling works in two steps: 1) the method name is tried as written (thus you can use Array.ConvertAll(...)) 2) mangled name is tried if 1) fails. Hence we might need to handle -Of suffix as well to be consistent, if the PascalCase style is preferred by the user. And that would lead to more ambiguities. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, January 08, 2009 10:58 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Generic method synxtax Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725E.1CD23400] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725E.1CD23400] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725E.1CD23400] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/3aff4afa/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/3aff4afa/attachment-0001.jpg>
Mine has also an issue that just occurred to me. If you do: class C content.load of(Texture2D), "foo" end "of" resolves to Module#of which would return a C<Texture2D> if C was a generic type or throws an exception. So that''s not good either. We would need a different method name for generic method constructor than for generic type. Maybe "method_of"? As for your idea: content.of(T).load is looks backwards. The content is not of T... the load is. I think this would be confusing. Until we figure out some nice clean solution that works in 100% cases, I would implement the following as the first step for generic method support: content.method(:load).of(Texture2D).call("mytexture") (Note, you can do the same in Ruby for regular methods: "foo".method(:center).call(100)) anything else is just a convenience and anyone could define it via standard Ruby means. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Friday, January 09, 2009 1:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Here are the ideas that stand out to me: I like Tomas''s idea, since it reads like C#/VB, but adding an argument to the front urks me: content.load of(Texture2D), "mytexture" Shri, having the "_of" appended to a generic method name and requiring a ".do" after it is how you would work with lambdas (except you do ".call"), but since we''re talking about .NET methods, not .NET delegates. So, I''d like the syntax to look more like a method call. Also, as Tomas says, mangling gets more complicated ... content.load_of(Texture2D).call "mytexture" How about adding an "of" method to the class/object, to put the class in a generic "mode"? The method probably shouldn''t be called "of", but you get the idea. It reads different than C#, but seems the most Rubyesk without changing the arguments. content.of(Texture2D).load "mytexture" Thoughts? If no one likes my idea, I think Tomas''s is a fine compromise. ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Friday, January 09, 2009 9:58 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Yup, it can theoretically cause an ambiguity, but in reality, I doubt we will ever run into a case of a class having both Foo<T> and FooOf. We can scan all of .NET 3.5 to see if there is any clash of this form. And as you say, if we really cared, we could define some priortization scheme to deal with it and/or have some other scheme like using Kernel#send to be able to get to the lower priority case. We have to deal with this in other cases too where Ruby keyword names clash with .NET api names, right? I think we should optimize for the 99.9% case (there will be no clashes) rather than chosing a suboptimal syntax that can handle the 0.1% case. Yes, we should probably do the "Of" suffix as well if we do "_of". Thanks, Shri From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 12:16 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax That might also work. There might be ambiguities however (as with any name prefixes/suffixes). What if there are methods, for example, GetClass<T>() and GetClassOf(object)? What would get_class_of(String) mean? Maybe we could define a priority. But that is IMO too magical. Also, the mangling works in two steps: 1) the method name is tried as written (thus you can use Array.ConvertAll(...)) 2) mangled name is tried if 1) fails. Hence we might need to handle -Of suffix as well to be consistent, if the PascalCase style is preferred by the user. And that would lead to more ambiguities. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, January 08, 2009 10:58 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Generic method synxtax Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725F.575F6920] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725F.575F6920] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C9725F.575F6920] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/18327db8/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/18327db8/attachment-0001.jpg>
I like Tomas''s idea the best. Generics are not native to Ruby, so most people using them will likely have a C#/VB background, which means Tomas''s syntax would be more familiar. The "_of" syntax isn''t bad, but forcing a ".do" or ".call" at the end isn''t ideal, even if it does have a bit of a Ruby flavor. Adding a ".of()" to the class is okay, but many classes may have generic methods even when the class itself is not a generic. (I''m thinking primarily of static and extension method classes here.) Passing the generic types as the first parameters seems the most explicit and understandable translation to me. ~ Ryan On Fri, Jan 9, 2009 at 3:12 PM, Jimmy Schementi < Jimmy.Schementi at microsoft.com> wrote:> Here are the ideas that stand out to me: > > > > I like Tomas''s idea, since it reads like C#/VB, but adding an argument to > the front urks me: > > > > content.load of(Texture2D), "mytexture" > > > > Shri, having the "_of" appended to a generic method name and requiring a > ".do" after it is how you would work with lambdas (except you do ".call"), > but since we''re talking about .NET methods, not .NET delegates. So, I''d like > the syntax to look more like a method call. Also, as Tomas says, mangling > gets more complicated ... > > > > content.load_of(Texture2D).call "mytexture" > > > > How about adding an "of" method to the class/object, to put the class in a > generic "mode"? The method probably shouldn''t be called "of", but you get > the idea. It reads different than C#, but seems the most Rubyesk without > changing the arguments. > > > > content.of(Texture2D).load "mytexture" > > > > Thoughts? If no one likes my idea, I think Tomas''s is a fine compromise. > > ~js >-- Ryan Riley ryan.riley at panesofglass.org http://panesofglass.org/ http://wizardsofsmart.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/0d05b8b8/attachment.html>
Cool, implement the basic support and we can play around with the syntax. Thanks Tomas! From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 1:46 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Mine has also an issue that just occurred to me. If you do: class C content.load of(Texture2D), "foo" end "of" resolves to Module#of which would return a C<Texture2D> if C was a generic type or throws an exception. So that''s not good either. We would need a different method name for generic method constructor than for generic type. Maybe "method_of"? As for your idea: content.of(T).load is looks backwards. The content is not of T... the load is. I think this would be confusing. Until we figure out some nice clean solution that works in 100% cases, I would implement the following as the first step for generic method support: content.method(:load).of(Texture2D).call("mytexture") (Note, you can do the same in Ruby for regular methods: "foo".method(:center).call(100)) anything else is just a convenience and anyone could define it via standard Ruby means. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Friday, January 09, 2009 1:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Here are the ideas that stand out to me: I like Tomas''s idea, since it reads like C#/VB, but adding an argument to the front urks me: content.load of(Texture2D), "mytexture" Shri, having the "_of" appended to a generic method name and requiring a ".do" after it is how you would work with lambdas (except you do ".call"), but since we''re talking about .NET methods, not .NET delegates. So, I''d like the syntax to look more like a method call. Also, as Tomas says, mangling gets more complicated ... content.load_of(Texture2D).call "mytexture" How about adding an "of" method to the class/object, to put the class in a generic "mode"? The method probably shouldn''t be called "of", but you get the idea. It reads different than C#, but seems the most Rubyesk without changing the arguments. content.of(Texture2D).load "mytexture" Thoughts? If no one likes my idea, I think Tomas''s is a fine compromise. ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Friday, January 09, 2009 9:58 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Yup, it can theoretically cause an ambiguity, but in reality, I doubt we will ever run into a case of a class having both Foo<T> and FooOf. We can scan all of .NET 3.5 to see if there is any clash of this form. And as you say, if we really cared, we could define some priortization scheme to deal with it and/or have some other scheme like using Kernel#send to be able to get to the lower priority case. We have to deal with this in other cases too where Ruby keyword names clash with .NET api names, right? I think we should optimize for the 99.9% case (there will be no clashes) rather than chosing a suboptimal syntax that can handle the 0.1% case. Yes, we should probably do the "Of" suffix as well if we do "_of". Thanks, Shri From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 12:16 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax That might also work. There might be ambiguities however (as with any name prefixes/suffixes). What if there are methods, for example, GetClass<T>() and GetClassOf(object)? What would get_class_of(String) mean? Maybe we could define a priority. But that is IMO too magical. Also, the mangling works in two steps: 1) the method name is tried as written (thus you can use Array.ConvertAll(...)) 2) mangled name is tried if 1) fails. Hence we might need to handle -Of suffix as well to be consistent, if the PascalCase style is preferred by the user. And that would lead to more ambiguities. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, January 08, 2009 10:58 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Generic method synxtax Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97263.04385820] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97263.04385820] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97263.04385820] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/c88f368f/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/c88f368f/attachment-0001.jpg>
How would this look for instantiating a generic object? my_object = Foo.method(:new).of(Bar).call That seems strange. Perhaps we need to possibilities: the above for generic methods and the following for generic classes: my_object = Foo.of(Bar).new # where Foo would be defined as Foo<T> in C# my_clone = my_object.clone # where clone would have a C# signature of T Clone<T>() or should that be: my_clone = my_object.method(:clone).of(Bar).call? # and allow my_object.clone to have an overloaded # C# signature of object Clone()? ~Ryan On Fri, Jan 9, 2009 at 3:45 PM, Tomas Matousek <Tomas.Matousek at microsoft.com> wrote:> Mine has also an issue that just occurred to me. If you do: > > > > class C > > content.load of(Texture2D), "foo" > > end > > > > "of" resolves to Module#of which would return a C<Texture2D> if C was a > generic type or throws an exception. > > So that''s not good either. We would need a different method name for > generic method constructor than for generic type. Maybe "method_of"? > > > > As for your idea: > > content.of(T).load > > > > is looks backwards. The content is not of T? the load is. I think this > would be confusing. > > > > Until we figure out some nice clean solution that works in 100% cases, I > would implement the following as the first step for generic method support: > > > > content.method(:load).of(Texture2D).call("mytexture") > > > > (Note, you can do the same in Ruby for regular methods: > "foo".method(:center).call(100)) > > > > anything else is just a convenience and anyone could define it via standard > Ruby means. > > > > Tomas > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/b11e7cdf/attachment.html>
Agreed. Once we find what works, we can consider pulling it into the interpreter, but we may not even need to. JD From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Friday, January 09, 2009 2:03 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Cool, implement the basic support and we can play around with the syntax. Thanks Tomas! From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 1:46 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Mine has also an issue that just occurred to me. If you do: class C content.load of(Texture2D), "foo" end "of" resolves to Module#of which would return a C<Texture2D> if C was a generic type or throws an exception. So that''s not good either. We would need a different method name for generic method constructor than for generic type. Maybe "method_of"? As for your idea: content.of(T).load is looks backwards. The content is not of T... the load is. I think this would be confusing. Until we figure out some nice clean solution that works in 100% cases, I would implement the following as the first step for generic method support: content.method(:load).of(Texture2D).call("mytexture") (Note, you can do the same in Ruby for regular methods: "foo".method(:center).call(100)) anything else is just a convenience and anyone could define it via standard Ruby means. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Friday, January 09, 2009 1:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Here are the ideas that stand out to me: I like Tomas''s idea, since it reads like C#/VB, but adding an argument to the front urks me: content.load of(Texture2D), "mytexture" Shri, having the "_of" appended to a generic method name and requiring a ".do" after it is how you would work with lambdas (except you do ".call"), but since we''re talking about .NET methods, not .NET delegates. So, I''d like the syntax to look more like a method call. Also, as Tomas says, mangling gets more complicated ... content.load_of(Texture2D).call "mytexture" How about adding an "of" method to the class/object, to put the class in a generic "mode"? The method probably shouldn''t be called "of", but you get the idea. It reads different than C#, but seems the most Rubyesk without changing the arguments. content.of(Texture2D).load "mytexture" Thoughts? If no one likes my idea, I think Tomas''s is a fine compromise. ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Friday, January 09, 2009 9:58 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax Yup, it can theoretically cause an ambiguity, but in reality, I doubt we will ever run into a case of a class having both Foo<T> and FooOf. We can scan all of .NET 3.5 to see if there is any clash of this form. And as you say, if we really cared, we could define some priortization scheme to deal with it and/or have some other scheme like using Kernel#send to be able to get to the lower priority case. We have to deal with this in other cases too where Ruby keyword names clash with .NET api names, right? I think we should optimize for the 99.9% case (there will be no clashes) rather than chosing a suboptimal syntax that can handle the 0.1% case. Yes, we should probably do the "Of" suffix as well if we do "_of". Thanks, Shri From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Friday, January 09, 2009 12:16 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax That might also work. There might be ambiguities however (as with any name prefixes/suffixes). What if there are methods, for example, GetClass<T>() and GetClassOf(object)? What would get_class_of(String) mean? Maybe we could define a priority. But that is IMO too magical. Also, the mangling works in two steps: 1) the method name is tried as written (thus you can use Array.ConvertAll(...)) 2) mangled name is tried if 1) fails. Hence we might need to handle -Of suffix as well to be consistent, if the PascalCase style is preferred by the user. And that would lead to more ambiguities. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shri Borde Sent: Thursday, January 08, 2009 10:58 PM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] Generic method synxtax Another suggestion is to use name mangling to append "_of" to the method name. This could return an object with a method called "do", "call", or something like that. Since we already do name mangling from PascalCase to under_scores, this could work out. It avoids having to pass the type parameter along with the other arguments. Array.convert_all_of(Fixnum, String).do data, lambda {|x|x.to_s } Content.load_of(Texture2d).do "mytexture" System.Activator.create_instance_of(String).do System.Linq.Enumerable.count_of(String).do string_array From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, November 26, 2008 4:12 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics For the record: I really like the chaining idea. I don''t know if it would work, but I like it. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 4:10 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Ah I see. Completely agree with the reasoning behind ''stuff appears when you require mscorlib'' too. Possible idea - make ''of'' a proc rather than a method, so it uses square brackets instead of round ones. d = Dictionary.of[String, String] t = Load of[Texture2d], "sometexture" # awesome, but only because ''Load'' is a conveniently nice name IMHO the [] "looks more like templates" than if it used () - but I''m biased on account of having never written a line of VB.net in my life. The VB coders will probably have the exact opposite reaction to me :-) Even so, I''m not entirely sure that copying VB is neccessarily the right thing... Examples for thought: data = [1,2,3,4] Array.convert_all of[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all of(Fixnum, String), data, lambda{ |x| x.to_s } Array.convert_all T[Fixnum, String], data, lambda{ |x| x.to_s } Array.convert_all T(Fixnum, String), data, lambda{ |x| x.to_s } I guess that any of these will be fine once one becomes used to them... Here''s one from left-field which probably won''t work, but how about using a proxy like andand does Array.with(Fixnum, String).convert_all data, lambda{ |x| x.to_s } Array.T(Fixnum, String).convert_all data, lambda{ |x| x.to_s } T(Texture2d).load "sometexture" Tomas Matousek wrote: It''s like: Sub Foo(Of T)(ByVal a As T) End Sub Sub Main() Foo(Of Integer)(1) End Sub Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 3:27 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics That makes sense. Dictionary.of(T1, T2) looks good, but how do they handle invoking generic methods? I don''t have VB.net installed, and all the samples I can find all rely on type inference rather than explicitly specifying the type Do they do Load( of(Texture2d), "blah" ) ?? Thanks. Tomas Matousek wrote: VB.NET has (Of T) syntax for generic parameters, so it would be familiar to VB programmers :) I don''t see a strong connection between "of" and "typeof". "T" is interesting, though we already use "of" for generic types (e.g. Dictionary.of(String, String)) so it might be better to stick with one concept for all generic parameters. We don''t want to extend Ruby syntax. Adding new methods is safe since it could always be implemented as monkey patching and could be done conditionally, for example after you require ''mscorlib'' the new methods appear. If you don''t use CLR no IronRuby/CLR specific methods should be available (it currently doesn''t work that way, but that''s the plan). Tomas From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Orion Edwards Sent: Wednesday, November 26, 2008 12:38 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics While I can certainly see the elegance of the ''of'' suggestion, it can''t help but to trip my "code smell" warning, because ''of'' implies ''typeof'', and it treats the types as method arguments. I can''t help but think that every new programmer, seeing this: myTexture = content.load( of(Texture2D), "mytexture" ) is going to wrongly infer that it''s calling this CLR method content.Load( typeof(Texture2D), "mytexture" ) The relative lack of such counter-intuitive assumptions is IMHO one of the best things about ruby. I''d really like to see IronRuby keep this up Perhaps it would be more clear if ''of'' was ''T'' ?? - eg: myTexture = content.load( T(Texture2D), "mytexture" ) But that doesn''t really solve the ''types aren''t method arguments'' problem How about this: myTexture = content.load[Texture2D]( "mytexture" ) myTexture = content.load[Texture2D] "mytexture" Both of these produce a syntax error in MRI, which IMHO is a good thing as it means IronRuby is not breaking any existing functionality. MRI is never going to have to call generics, and as far as I can tell there won''t be any overlaps with existing ruby syntax (eg Proc#[], etc), so it seems safe. It also is consistent with the existing syntax for instantiating generic classes. The deal-breaker I guess would be how hard (or possible) this syntax is to implement with the IronRuby parser, etc. Tomas Matousek wrote: I''m thinking of something like: myTexture = content.load of(Texture2D), "mytexture" I.e. we would add Kernel#of method that takes a list of classes/modules and returns a special object representing generic parameters that binder would use for selecting the right method. We are open for more ideas. Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Wednesday, November 26, 2008 10:49 AM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: Re: [Ironruby-core] IronRuby and XNA. Super and Generics Thanks John! I will do that. Just for curiosity, what will be the syntax to call generic methods? :) 2008/11/26 John Lam (IRONRUBY) <jflam at microsoft.com><mailto:jflam at microsoft.com>: We can''t consume generic methods today. It''s on the list of things to do though. You can work around this by defining a concrete method in C# that calls the appropriate generic method and call the concrete method from IronRuby. Thanks, -John -----Original Message----- From: ironruby-core-bounces at rubyforge.org<mailto:ironruby-core-bounces at rubyforge.org> [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Dudu Bai?o Sent: Tuesday, November 25, 2008 6:26 PM To: ironruby-core at rubyforge.org<mailto:ironruby-core at rubyforge.org> Subject: [Ironruby-core] IronRuby and XNA. Super and Generics Hi guys! Im playing with XNA trying to run the simplest xna example: To show a SpriteBatch on screen. After some tests I found some problems: 1- The "Microsoft::Xna::Framework::Game" expects that we implement some methods like "Update", "Drawn" etc, and inside the method we have to call the base class (super) actual method passing some parameters. If I try to do this: def update(game_time) super(game_time) end I get this error: my_game.rb:23:in `update'': wrong number or type of arguments for `update'' (ArgumentError) from Snippets.scripting:0:in `Update'' from Microsoft.Xna.Framework.Game:0:in `Run'' from program.rb:23:in `main'' from :0 2- XNA uses generic functions to load the game contents. How can I convert the code above to IronRuby? // This is a texture we can render. Texture2D myTexture; protected override void LoadContent() { myTexture = Content.Load<Texture2D>("mytexture"); } Can IronRuby consume generics? Thanks! _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97267.EC66D550] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97267.EC66D550] ________________________________ _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org> http://rubyforge.org/mailman/listinfo/ironruby-core -- Orion Edwards Web Application Developer T: +64 7 859 2120 F: +64 7 859 2320 E: orion.edwards at open2view.com <mailto:orion.edwards at open2view.com> Open2view.com The Real Estate Website [cid:image001.jpg at 01C97267.EC66D550] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/a1d06577/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 8147 bytes Desc: image001.jpg URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/a1d06577/attachment-0001.jpg>
Let''s let Tomas implement content.method(:load).of(Texture2D).call(?mytexture?) ... and then we can play around with the different syntax in context. Then it''s pick-the-syntax-you-want =) From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ryan Riley Sent: Friday, January 09, 2009 1:51 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax I like Tomas''s idea the best. Generics are not native to Ruby, so most people using them will likely have a C#/VB background, which means Tomas''s syntax would be more familiar. The "_of" syntax isn''t bad, but forcing a ".do" or ".call" at the end isn''t ideal, even if it does have a bit of a Ruby flavor. Adding a ".of()" to the class is okay, but many classes may have generic methods even when the class itself is not a generic. (I''m thinking primarily of static and extension method classes here.) Passing the generic types as the first parameters seems the most explicit and understandable translation to me. ~ Ryan On Fri, Jan 9, 2009 at 3:12 PM, Jimmy Schementi <Jimmy.Schementi at microsoft.com<mailto:Jimmy.Schementi at microsoft.com>> wrote: Here are the ideas that stand out to me: I like Tomas''s idea, since it reads like C#/VB, but adding an argument to the front urks me: content.load of(Texture2D), "mytexture" Shri, having the "_of" appended to a generic method name and requiring a ".do" after it is how you would work with lambdas (except you do ".call"), but since we''re talking about .NET methods, not .NET delegates. So, I''d like the syntax to look more like a method call. Also, as Tomas says, mangling gets more complicated ... content.load_of(Texture2D).call "mytexture" How about adding an "of" method to the class/object, to put the class in a generic "mode"? The method probably shouldn''t be called "of", but you get the idea. It reads different than C#, but seems the most Rubyesk without changing the arguments. content.of(Texture2D).load "mytexture" Thoughts? If no one likes my idea, I think Tomas''s is a fine compromise. ~js -- Ryan Riley ryan.riley at panesofglass.org<mailto:ryan.riley at panesofglass.org> http://panesofglass.org/ http://wizardsofsmart.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/d14aacab/attachment.html>
Foo.of(Bar).new works today ? since it''s about instantiating generic types ? this discussion was only about generic methods. From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ryan Riley Sent: Friday, January 09, 2009 2:33 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax How would this look for instantiating a generic object? my_object = Foo.method(:new).of(Bar).call That seems strange. Perhaps we need to possibilities: the above for generic methods and the following for generic classes: my_object = Foo.of(Bar).new # where Foo would be defined as Foo<T> in C# my_clone = my_object.clone # where clone would have a C# signature of T Clone<T>() or should that be: my_clone = my_object.method(:clone).of(Bar).call? # and allow my_object.clone to have an overloaded # C# signature of object Clone()? ~Ryan On Fri, Jan 9, 2009 at 3:45 PM, Tomas Matousek <Tomas.Matousek at microsoft.com<mailto:Tomas.Matousek at microsoft.com>> wrote: Mine has also an issue that just occurred to me. If you do: class C content.load of(Texture2D), "foo" end "of" resolves to Module#of which would return a C<Texture2D> if C was a generic type or throws an exception. So that''s not good either. We would need a different method name for generic method constructor than for generic type. Maybe "method_of"? As for your idea: content.of(T).load is looks backwards. The content is not of T? the load is. I think this would be confusing. Until we figure out some nice clean solution that works in 100% cases, I would implement the following as the first step for generic method support: content.method(:load).of(Texture2D).call("mytexture") (Note, you can do the same in Ruby for regular methods: "foo".method(:center).call(100)) anything else is just a convenience and anyone could define it via standard Ruby means. Tomas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/d91d7821/attachment.html>
Generic types already work: List = List.of(Object).new Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ryan Riley Sent: Friday, January 09, 2009 2:33 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] Generic method synxtax How would this look for instantiating a generic object? my_object = Foo.method(:new).of(Bar).call That seems strange. Perhaps we need to possibilities: the above for generic methods and the following for generic classes: my_object = Foo.of(Bar).new # where Foo would be defined as Foo<T> in C# my_clone = my_object.clone # where clone would have a C# signature of T Clone<T>() or should that be: my_clone = my_object.method(:clone).of(Bar).call? # and allow my_object.clone to have an overloaded # C# signature of object Clone()? ~Ryan On Fri, Jan 9, 2009 at 3:45 PM, Tomas Matousek <Tomas.Matousek at microsoft.com<mailto:Tomas.Matousek at microsoft.com>> wrote: Mine has also an issue that just occurred to me. If you do: class C content.load of(Texture2D), "foo" end "of" resolves to Module#of which would return a C<Texture2D> if C was a generic type or throws an exception. So that''s not good either. We would need a different method name for generic method constructor than for generic type. Maybe "method_of"? As for your idea: content.of(T).load is looks backwards. The content is not of T? the load is. I think this would be confusing. Until we figure out some nice clean solution that works in 100% cases, I would implement the following as the first step for generic method support: content.method(:load).of(Texture2D).call("mytexture") (Note, you can do the same in Ruby for regular methods: "foo".method(:center).call(100)) anything else is just a convenience and anyone could define it via standard Ruby means. Tomas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/e41b3129/attachment-0001.html>
Oops! Sorry for being a bit behind! On Fri, Jan 9, 2009 at 5:37 PM, Jimmy Schementi < Jimmy.Schementi at microsoft.com> wrote:> Foo.of(Bar).new works today ? since it''s about instantiating generic > types ? this discussion was only about generic methods. > > > > *From:* ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] *On Behalf Of *Ryan Riley > *Sent:* Friday, January 09, 2009 2:33 PM > *To:* ironruby-core at rubyforge.org > *Subject:* Re: [Ironruby-core] Generic method synxtax > > > > How would this look for instantiating a generic object? > > > my_object = Foo.method(:new).of(Bar).call > > That seems strange. Perhaps we need to possibilities: the above for generic > methods and the following for generic classes: > > my_object = Foo.of(Bar).new > # where Foo would be defined as Foo<T> in C# > > my_clone = my_object.clone > # where clone would have a C# signature of T Clone<T>() > > or should that be: > > my_clone = my_object.method(:clone).of(Bar).call? > # and allow my_object.clone to have an overloaded > # C# signature of object Clone()? > > ~Ryan > > On Fri, Jan 9, 2009 at 3:45 PM, Tomas Matousek < > Tomas.Matousek at microsoft.com> wrote: > > Mine has also an issue that just occurred to me. If you do: > > > > class C > > content.load of(Texture2D), "foo" > > end > > > > "of" resolves to Module#of which would return a C<Texture2D> if C was a > generic type or throws an exception. > > So that''s not good either. We would need a different method name for > generic method constructor than for generic type. Maybe "method_of"? > > > > As for your idea: > > content.of(T).load > > > > is looks backwards. The content is not of T? the load is. I think this > would be confusing. > > > > Until we figure out some nice clean solution that works in 100% cases, I > would implement the following as the first step for generic method support: > > > > content.method(:load).of(Texture2D).call("mytexture") > > > > (Note, you can do the same in Ruby for regular methods: > "foo".method(:center).call(100)) > > > > anything else is just a convenience and anyone could define it via standard > Ruby means. > > > > Tomas > > > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-- Ryan Riley ryan.riley at panesofglass.org http://panesofglass.org/ http://wizardsofsmart.net/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/21c6754b/attachment.html>