|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
static methods and duck typingHi all. Has there been any consideration given to late-bound static methods in Boo? I'd like to see an IQuackFu style resolution for static methods of a duck typed class. I'm not sure how exactly it would work. I think it would involve some change to RuntimeServices and a new compiler step. I'm willing to invest some time in creating a patch for it if there's no reason why it wouldn't work or wouldn't be desirable. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typing>>>integer as duck = typeof(int)
System.Int32 >>>integer.Parse("5") 5 On Fri, Jun 13, 2008 at 7:16 PM, Nathan Stott <nrstott@...> wrote:
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typingThis is what I'd like to have work: [Boo.Lang.DuckTypedAttribute] class MyClass: static def QuackInvoke(.....): do stuff.... MyClass.SayHello("") On Fri, Jun 13, 2008 at 11:22 AM, Ayende Rahien <ayende@...> wrote: >>>>integer as duck = typeof(int) > System.Int32 >>>>integer.Parse("5") > 5 > > On Fri, Jun 13, 2008 at 7:16 PM, Nathan Stott <nrstott@...> wrote: >> >> Hi all. >> >> Has there been any consideration given to late-bound static methods in >> Boo? I'd like to see an IQuackFu style resolution for static methods >> of a duck typed class. >> >> I'm not sure how exactly it would work. I think it would involve some >> change to RuntimeServices and a new compiler step. >> I'm willing to invest some time in creating a patch for it if there's >> no reason why it wouldn't work or wouldn't be desirable. >> >> > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typingInterfaces exist at an instance level, if you called a static method that didnt' exist what instance would recieve the unhandled call? I'm interested in seeing a snippet of code that would illustrate the usecase you would like to see working.
On Fri, Jun 13, 2008 at 11:16 AM, Nathan Stott <nrstott@...> wrote:
-- Justin Chase http://www.justnbusiness.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typingMy goal is to be able to write convention based methods a la ruby activerecord. class ActiverecordBase: static def QuackInvoke(...) ... class Person(ActiveRecordBase): pass persons = Person.FindByNameAndAge("bill", 28) the method names would be parsed by the quack static method of the class to perform db operations. On Fri, Jun 13, 2008 at 11:27 AM, Justin Chase <justin.m.chase@...> wrote: > Interfaces exist at an instance level, if you called a static method that > didnt' exist what instance would recieve the unhandled call? I'm interested > in seeing a snippet of code that would illustrate the usecase you would like > to see working. > > > On Fri, Jun 13, 2008 at 11:16 AM, Nathan Stott <nrstott@...> wrote: >> >> Hi all. >> >> Has there been any consideration given to late-bound static methods in >> Boo? I'd like to see an IQuackFu style resolution for static methods >> of a duck typed class. >> >> I'm not sure how exactly it would work. I think it would involve some >> change to RuntimeServices and a new compiler step. >> I'm willing to invest some time in creating a patch for it if there's >> no reason why it wouldn't work or wouldn't be desirable. >> >> > > > > -- > Justin Chase > http://www.justnbusiness.com > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typingI guess you'd have to do it by convention since you can't guarantee that static methods are defined with an interface.
On Fri, Jun 13, 2008 at 11:37 AM, Nathan Stott <nrstott@...> wrote:
-- Justin Chase http://www.justnbusiness.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typingYes, it would have to be by convention, or via some type of attribute on the class declaring that it used method xxx for resolving late-bound static methods. I'm planning on looking into this more in the coming week. On Sat, Jun 14, 2008 at 10:57 AM, Justin Chase <justin.m.chase@...> wrote: > I guess you'd have to do it by convention since you can't guarantee that > static methods are defined with an interface. > > > On Fri, Jun 13, 2008 at 11:37 AM, Nathan Stott <nrstott@...> wrote: >> >> My goal is to be able to write convention based methods a la ruby >> activerecord. >> >> class ActiverecordBase: >> static def QuackInvoke(...) >> ... >> >> class Person(ActiveRecordBase): >> pass >> >> persons = Person.FindByNameAndAge("bill", 28) >> >> the method names would be parsed by the quack static method of the >> class to perform db operations. >> >> On Fri, Jun 13, 2008 at 11:27 AM, Justin Chase <justin.m.chase@...> >> wrote: >> > Interfaces exist at an instance level, if you called a static method >> > that >> > didnt' exist what instance would recieve the unhandled call? I'm >> > interested >> > in seeing a snippet of code that would illustrate the usecase you would >> > like >> > to see working. >> > >> > >> > On Fri, Jun 13, 2008 at 11:16 AM, Nathan Stott <nrstott@...> >> > wrote: >> >> >> >> Hi all. >> >> >> >> Has there been any consideration given to late-bound static methods in >> >> Boo? I'd like to see an IQuackFu style resolution for static methods >> >> of a duck typed class. >> >> >> >> I'm not sure how exactly it would work. I think it would involve some >> >> change to RuntimeServices and a new compiler step. >> >> I'm willing to invest some time in creating a patch for it if there's >> >> no reason why it wouldn't work or wouldn't be desirable. >> >> >> >> >> > >> > >> > >> > -- >> > Justin Chase >> > http://www.justnbusiness.com >> > > >> > >> >> > > > > -- > Justin Chase > http://www.justnbusiness.com > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typingOn Sat, Jun 14, 2008 at 5:29 PM, Nathan Stott <nrstott@...> wrote: > > Yes, it would have to be by convention, or via some type of attribute > on the class declaring that it used method xxx for resolving > late-bound static methods. You could introduce a singleton object in the type as an entry point for the dynamic dispatching of queries: class Person(...): public static final Queries = ActiveRecordQueries[of Person]() // implements IQuackFu ... found = Person.Queries.FindByName("Brian") Or you could use some form of compile time metaprogramming which doesn't really give the same effect but at least has the potential for code completion: namespace Spikes import Boo.Lang.Compiler import Boo.Lang.Compiler.Ast import Boo.Lang.Compiler.MetaProgramming class ActiveRecordAttribute(AbstractAstAttribute): override def Apply(node as Node): klass as ClassDefinition = node for field in fieldsOf(klass): name = "FindBy${field.Name}" method = [| public static def $name(value): print $name, value return array($klass, 0) |] klass.Members.Add(method) def fieldsOf(type as TypeDefinition): return f as Field for f in type.Members.Select(NodeType.Field) code = [| import Spikes [ActiveRecord] class Person: public Name as string for p in Person.FindByName("foo"): print p.Name |] compile(code, typeof(ActiveRecordAttribute).Assembly).EntryPoint.Invoke(null, (null,)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: static methods and duck typingThat looks like a very promising approach. Thanks Rodrigo. On Sun, Jun 15, 2008 at 11:11 AM, Rodrigo B. de Oliveira <rodrigobamboo@...> wrote: > > On Sat, Jun 14, 2008 at 5:29 PM, Nathan Stott <nrstott@...> wrote: >> >> Yes, it would have to be by convention, or via some type of attribute >> on the class declaring that it used method xxx for resolving >> late-bound static methods. > > You could introduce a singleton object in the type as an entry point > for the dynamic dispatching of queries: > > class Person(...): > > public static final Queries = ActiveRecordQueries[of Person]() > // implements IQuackFu > > ... > > > found = Person.Queries.FindByName("Brian") > > Or you could use some form of compile time metaprogramming which > doesn't really give the same effect but at least has the potential for > code completion: > > namespace Spikes > > import Boo.Lang.Compiler > import Boo.Lang.Compiler.Ast > import Boo.Lang.Compiler.MetaProgramming > > class ActiveRecordAttribute(AbstractAstAttribute): > > override def Apply(node as Node): > > klass as ClassDefinition = node > > for field in fieldsOf(klass): > name = "FindBy${field.Name}" > method = [| > public static def $name(value): > print $name, value > return array($klass, 0) > |] > klass.Members.Add(method) > > def fieldsOf(type as TypeDefinition): > return f as Field for f in type.Members.Select(NodeType.Field) > > code = [| > > import Spikes > > [ActiveRecord] > class Person: > public Name as string > > for p in Person.FindByName("foo"): > print p.Name > |] > > compile(code, > typeof(ActiveRecordAttribute).Assembly).EntryPoint.Invoke(null, > (null,)) > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Boo Programming Language" group. To post to this group, send email to boolang@... To unsubscribe from this group, send email to boolang-unsubscribe@... For more options, visit this group at http://groups.google.com/group/boolang -~----------~----~----~----~------~----~------~--~--- |
| Free Forum Powered by Nabble | Forum Help |