Forums

Decimal Literal

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Decimal Literal

Postby torial » Mon Dec 06, 2010 3:39 pm

I have found that when trying to declare a decimal literal, such as -100000000d, I get an error: 'Expecting EOL, but got "d" (ID) instead.' This is easily resolved by adding a period and a zero: -100000000.0d

Despite there being an easy resolution, I'm unsure why it is required to have a .0 for decimal literals. Given that Cobra is very smart about figuring many other things out, why isn't it smart enough to treat it as a decimal w/o choking? Is this something I should write a bug for, or is it WAD?
torial
 
Posts: 229
Location: IA

Re: Decimal Literal

Postby Charles » Mon Dec 06, 2010 3:42 pm

I can't think of any problems with whole number literals having suffixes like d, f32, f64 and f to set their type. Any objections?

Should we also have "n" for "number" which is a type in Cobra?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Decimal Literal

Postby todd.a » Tue Dec 07, 2010 12:36 am

We definitely need one for byte/uint8. Will come in handy for byte arrays.
todd.a
Site Admin
 
Posts: 81
Location: Chicago, IL

Re: Decimal Literal

Postby Charles » Tue Dec 07, 2010 3:13 am

We already have that covered:
x = 5u8
trace x
# outputs:
# trace: x=5 (Byte); at ...
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Decimal Literal

Postby todd.a » Tue Dec 07, 2010 8:09 am

Ah, sweet.
todd.a
Site Admin
 
Posts: 81
Location: Chicago, IL

Re: Decimal Literal

Postby torial » Tue Dec 07, 2010 8:41 am

I love the idea of "n" for number.
torial
 
Posts: 229
Location: IA

Re: Decimal Literal

Postby Charles » Tue Dec 07, 2010 9:17 pm

Done in changeset:2467:

Support numeric literals like `45n` for `number` and `45d` for decimal. Previously, the `d` suffix required a decimal portion (`45.0d`) and there was no `n` suffix available.
reported-by:torial


Please test it and let me know how it goes.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Decimal Literal

Postby hopscc » Thu Dec 09, 2010 3:27 am

It seems since that patch the cobra tests fail - specifically Tests/110-basics-two/110-int-types.cobra
Code: Select all


RUN ..\Tests\110-basics-two\110-int-types.cobra
    C:\home\hops\src\cobra\wkspace1\Source\..\Tests\110-basics-two\110-int-types.cobra
    Test #1
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(185): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(187): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(219): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(221): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(236): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(238): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(253): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Skipping duplicate message: c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(255): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(185): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(187): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(189): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(219): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(221): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(223): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(236): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(238): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(240): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(242): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(253): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(255): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
c:\home\hops\src\cobra\wkspace1\Tests\tests\110-basics-two\110-int-types.cobra(257): error: The call is ambiguous between the following methods or properties: "Cobra.Lang.CobraImp.IsTrue(float?)" and "Cobra.Lang.CobraImp.IsTrue(decimal?)" (C#)
Compilation failed - 13 errors, 0 warnings
----------------------------------------------------------------------------------------------------

hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: Decimal Literal

Postby Charles » Thu Dec 09, 2010 3:36 am

Did you do a "cobra -bsl" to produce a new Cobra.Lang.dll? I think this is the problem.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Decimal Literal

Postby hopscc » Thu Dec 09, 2010 3:54 am

My apologies, so it is
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand


Return to Discussion

Who is online

Users browsing this forum: No registered users and 77 guests