|
View:
New views
12 Messages
—
Rating Filter:
Alert me
|
|
|
Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'Hi, Boo is awesome from what I read about it. I plan to even contribute money if it delivers the language features promised especially the ability to extend it into a Domain Specific Language which is what we need for tickzoom project which is commercial. To get started, I simply used #Develop to convert a whole project in C# to Boo to see what happens. I get a lot of this exact error or variations on it: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed' This error line code is something like (simplified) : TickZoom.Api.Elapsed elapsed = new Elapsed(4,28,00); double EndOfDay = new Elapsed(4,30,0); if elapsed <= endOfDay: print "day is is over" The TickZoom.Api.Elapsed C# struct has an implicit cast to double, like so: public static implicit operator double( Elapsed elapsed ) { return elapsed.elapsed; } In c#, that originated this code, the implicit casting works. I just tried this: if elapsed as double < endOfDay: And got a different error: 'TickZoom.Api.Elapsed' is a value type. The 'as' operator can only be used with reference types. Background: The .NET TimeSpan struct doesn't meet our needs for performance since it's immutable. So the Elapsed struct encapsulates as double value and offers many mutable time calculations on it. But it's very useful to be able to use it directly without casting to the internal double that it encapsulates. How can Boo interopwith C# in this way? Sincerely, Wayne --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'On Sat, Nov 7, 2009 at 8:08 PM, tickzoom <mwaynewalter@...> wrote: > ... > Operator '<=' cannot be used with a left hand side of type 'double' > and a right hand side of type 'TickZoom.Api.Elapsed' > Right, that's currently not supported. I've filed a ticket (http://jira.codehaus.org/browse/BOO-1263). > I just tried this: > > if elapsed as double < endOfDay: > It should be 'cast(double, elapsed) < endOfDay'. Best regards, Rodrigo --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'Okay. I'll use that as a work around. Thanks! - Wayne
On Sun, Nov 8, 2009 at 7:51 AM, Rodrigo B. de Oliveira <rodrigobamboo@...> 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'Looking at the code, i was thinking. Why coudn't we write "variable as type", when variable is a valuetype and type too ?? I always have a problem with cast, it's not Booish enough. Just one ideia. Cheers, On Sun, Nov 8, 2009 at 2:42 PM, Wayne Walter <mwaynewalter@...> wrote: > Okay. I'll use that as a work around. Thanks! - Wayne > > On Sun, Nov 8, 2009 at 7:51 AM, Rodrigo B. de Oliveira > <rodrigobamboo@...> wrote: >> >> On Sat, Nov 7, 2009 at 8:08 PM, tickzoom <mwaynewalter@...> wrote: >> > ... >> > Operator '<=' cannot be used with a left hand side of type 'double' >> > and a right hand side of type 'TickZoom.Api.Elapsed' >> > >> >> Right, that's currently not supported. I've filed a ticket >> (http://jira.codehaus.org/browse/BOO-1263). >> >> > I just tried this: >> > >> > if elapsed as double < endOfDay: >> > >> >> It should be 'cast(double, elapsed) < endOfDay'. >> >> Best regards, >> Rodrigo >> >> > > > > > -- Georges "Artifex" http://gbenatti.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'I tried that. It didn't work. It said you can't do that with a valuetype it must be a reference.
Wayne On Mon, Nov 9, 2009 at 8:21 AM, gbenatti@... <gbenatti@...> 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'Yep, it doesn't work. My real question is, why not ? I can't see a reason behind it. Syntactically, i think it would be more Boo like to have as act like a cast for valuetypes. Probably for people that was not there in the beginning like me, the first thing that they will try to do is the var as double, like you did. If it is the expected behavior for people that are new to the language, i think it should be "the behavior" Just my 2 cents, On Mon, Nov 9, 2009 at 11:34 AM, Wayne Walter <mwaynewalter@...> wrote: > I tried that. It didn't work. It said you can't do that with a valuetype it > must be a reference. > > Wayne > > On Mon, Nov 9, 2009 at 8:21 AM, gbenatti@... <gbenatti@...> > wrote: >> >> Looking at the code, i was thinking. >> >> Why coudn't we write "variable as type", when variable is a valuetype >> and type too ?? >> >> I always have a problem with cast, it's not Booish enough. >> >> Just one ideia. >> >> Cheers, >> >> On Sun, Nov 8, 2009 at 2:42 PM, Wayne Walter <mwaynewalter@...> >> wrote: >> > Okay. I'll use that as a work around. Thanks! - Wayne >> > >> > On Sun, Nov 8, 2009 at 7:51 AM, Rodrigo B. de Oliveira >> > <rodrigobamboo@...> wrote: >> >> >> >> On Sat, Nov 7, 2009 at 8:08 PM, tickzoom <mwaynewalter@...> >> >> wrote: >> >> > ... >> >> > Operator '<=' cannot be used with a left hand side of type 'double' >> >> > and a right hand side of type 'TickZoom.Api.Elapsed' >> >> > >> >> >> >> Right, that's currently not supported. I've filed a ticket >> >> (http://jira.codehaus.org/browse/BOO-1263). >> >> >> >> > I just tried this: >> >> > >> >> > if elapsed as double < endOfDay: >> >> > >> >> >> >> It should be 'cast(double, elapsed) < endOfDay'. >> >> >> >> Best regards, >> >> Rodrigo >> >> >> >> >> > >> > >> > > >> > >> >> >> >> -- >> Georges "Artifex" >> http://gbenatti.net >> >> > > > > > -- Georges "Artifex" http://gbenatti.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'Understood. Only, there may be value to using different syntax even if it's not the
ugly cast( double, value). Why? Well, as is very specific functionality more than a cast. It will make the reference null of it's not castable. With a valuetable, null is impossble. So what value would you assign if it's not castable? On the other hand, perhaps you could use "as" in Boo and treat it differently for valuetypes so it gives a run time CastException if the object can't be cast. If that's possible (I'm sure it is) they I would agree that Boo as one syntax for this using "as". Wayne On Mon, Nov 9, 2009 at 8:42 AM, gbenatti@... <gbenatti@...> 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'On Mon, Nov 9, 2009 at 11:42 AM, gbenatti@... <gbenatti@...> wrote: > > Yep, it doesn't work. > > My real question is, why not ? I can't see a reason behind it. > 'as' is a try cast. It returns null to signal failure. It could return a nullable value type version for value types but that's not where I intend to go with it. I've been thinking for some time now in unifying casts and nullable casts and about removing the overloaded meaning of the 'as' keyword. Regular Casts (throw upon failure) <expression> cast <type> Nullable casts (null upon failure) <expression> cast? <type> It can be used with nullable types but not with value types. The error message should suggest using a nullable type whenever a value type is used. def foo(o): i = o cast? int # ERROR: 'cast?' cannot be used with value type 'int'. Did you mean 'int?'? Thoughts? Rodrigo --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'Hummm.. Well, i don't really see a problem in overloading the meaning of as, in the case of value types. But, i like the idea of this cast and cast?, and if the dual meaning of as is not desirable, i would be glad of have this cast forms On Mon, Nov 9, 2009 at 12:10 PM, Rodrigo B. de Oliveira <rodrigobamboo@...> wrote: > > On Mon, Nov 9, 2009 at 11:42 AM, gbenatti@... <gbenatti@...> wrote: >> >> Yep, it doesn't work. >> >> My real question is, why not ? I can't see a reason behind it. >> > > 'as' is a try cast. It returns null to signal failure. > > It could return a nullable value type version for value types but > that's not where I intend to go with it. > > I've been thinking for some time now in unifying casts and nullable > casts and about removing the overloaded meaning of the 'as' keyword. > > Regular Casts (throw upon failure) > > <expression> cast <type> > > Nullable casts (null upon failure) > > <expression> cast? <type> > > It can be used with nullable types but not with value types. The error > message should suggest using a nullable type whenever a value type is > used. > > def foo(o): > i = o cast? int > # ERROR: 'cast?' cannot be used with value type 'int'. Did you mean 'int?'? > > Thoughts? > Rodrigo > > > > -- Georges "Artifex" http://gbenatti.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'gbenatti@... wrote:
> Hummm.. Well, i don't really see a problem in overloading the meaning > of as, in the case of value types. > But, i like the idea of this cast and cast?, and if the dual meaning > of as is not desirable, i would be glad of have this cast forms > "as" already has two meanings: x as object = SomeClass() a as string = x # InvalidCastException b = x as string # null c as int = x # InvalidCastException d = x as int # Compiler error Adding a third meaning in the case 'd' would be even more confusing. I like the idea of "cast" and "cast?"; then 'as' would unambiguously refer to variable declarations. Case 'b' probably should still be supported for backward compatibility (at least for a few Boo releases); but could produce a compiler warning ("please use 'cast?' instead"). Daniel |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'I Agree ;) + 1 On Mon, Nov 9, 2009 at 2:24 PM, Daniel Grunwald <daniel@...> wrote: > gbenatti@... wrote: >> Hummm.. Well, i don't really see a problem in overloading the meaning >> of as, in the case of value types. >> But, i like the idea of this cast and cast?, and if the dual meaning >> of as is not desirable, i would be glad of have this cast forms >> > "as" already has two meanings: > > x as object = SomeClass() > a as string = x # InvalidCastException > b = x as string # null > c as int = x # InvalidCastException > d = x as int # Compiler error > > Adding a third meaning in the case 'd' would be even more confusing. > > I like the idea of "cast" and "cast?"; then 'as' would unambiguously > refer to variable declarations. > Case 'b' probably should still be supported for backward compatibility > (at least for a few Boo releases); but could produce a compiler warning > ("please use 'cast?' instead"). > > Daniel > > -- Georges "Artifex" http://gbenatti.net --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Operator '<=' cannot be used with a left hand side of type 'double' and a right hand side of type 'TickZoom.Api.Elapsed'Rodrigo, it would be nice to add implicit casting too!
- Bill On Nov 9, 10:10 am, "Rodrigo B. de Oliveira" <rodrigobam...@...> wrote: > On Mon, Nov 9, 2009 at 11:42 AM, gbena...@... <gbena...@...> wrote: > > > Yep, it doesn't work. > > > My real question is, why not ? I can't see a reason behind it. > > 'as' is a try cast. It returns null to signal failure. > > It could return a nullable value type version for value types but > that's not where I intend to go with it. > > I've been thinking for some time now in unifying casts and nullable > casts and about removing the overloaded meaning of the 'as' keyword. > > Regular Casts (throw upon failure) > > <expression> cast <type> > > Nullable casts (null upon failure) > > <expression> cast? <type> > > It can be used with nullable types but not with value types. The error > message should suggest using a nullable type whenever a value type is > used. > > def foo(o): > i = o cast? int > # ERROR: 'cast?' cannot be used with value type 'int'. Did you mean 'int?'? > > Thoughts? > Rodrigo -- 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@.... For more options, visit this group at http://groups.google.com/group/boolang?hl=. |
| Free embeddable forum powered by Nabble | Forum Help |