Author Topic: About Enums  (Read 541 times)

0 Members and 1 Guest are viewing this topic.

Josť Roca

  • Sr. Member
  • ****
  • Posts: 263
About Enums
« on: September 28, 2018, 12:14:54 AM »
I don't see an option such Explicit, that allows to use the name of the enum as a namespace. This means that the member names of the enums must be unique.

Code: [Select]
Enum MyEnum
   option1 = 1
   option2
   option3
End Enum

Enum MyEum2
   option1 = 10
End Enum

print option1
print option2
print option3

In the above code, the use of option1 = 10 in the second enum causes that option1 = 1 is no longer accessible. If Explicit was available, we could use MyEnum.Option1 and MyEnum2.Option2.

And what is worse, the second option1 replaces silently the first option1, without giving an error.
« Last Edit: October 14, 2018, 07:27:34 PM by Josť Roca »

Josť Roca

  • Sr. Member
  • ****
  • Posts: 263
Re: About Enums
« Reply #1 on: September 28, 2018, 12:19:16 AM »
Similar problem with constants.

Code: [Select]
const x = 10
const x = 11
print x   ' prints 11

The compiler doesn't complain.

This is dangerous because it can cause hard to find bugs.

Josť Roca

  • Sr. Member
  • ****
  • Posts: 263
Re: About Enums
« Reply #2 on: September 28, 2018, 02:03:50 AM »
String equates doesn't seem to accept embedded double quotes.

$s = "Hello ""World"""

prints "Hello World"

Josť Roca

  • Sr. Member
  • ****
  • Posts: 263
Re: About Enums
« Reply #3 on: September 28, 2018, 02:11:30 AM »
Is there a way that

%n = 12345.56

won't become 12345.559999999999 ?

Josť Roca

  • Sr. Member
  • ****
  • Posts: 263
Re: About Enums
« Reply #4 on: September 28, 2018, 02:45:41 AM »
It seems that enum bit only accepts bit in lowercase. ENUM bit works, but ENUM BIT or ENUM Bit does not.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3980
    • Oxygen Basic
Re: About Enums
« Reply #5 on: September 28, 2018, 02:48:11 AM »
Josť,

To trap duplicate definitions:

#unique on

otherwise new definitions override older ones.

#unique may be switched on and off for any section of code.

Overriding definitions always allowed within a new scope:
Code: [Select]
#unique on
enum x
a=1,b,c
end enum
scope
  enum y
  a=10,b,c
  end enum
  print b '11
end scope
print b '2

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3980
    • Oxygen Basic
Re: About Enums
« Reply #6 on: September 28, 2018, 03:28:19 AM »
I've fixed the BIT case conversion.


%n 123.45
This is deployed unconverted, but you will see it cannot be stored precisely in a float. You will need to restrict the decimal places of the float when printing:

Code: [Select]
%n 123.45
print n
single nn=n
print nn
print str(nn,2) '123.45

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3980
    • Oxygen Basic
Re: About Enums
« Reply #7 on: September 28, 2018, 03:47:50 AM »
For embedded quotemarks use `
as the outer quotemark (ascii 96)

Code: [Select]
'Embedded quote marks:
$s `"Hello World"`
print s
'prints "Hello World"

Arnold

  • Hero Member
  • *****
  • Posts: 786
Re: About Enums
« Reply #8 on: September 28, 2018, 03:57:49 AM »
Regarding embbedded quotes (Reply #2): I am used to do it this way:

string qu=chr(34)
'$qu=chr(34)
$s = "Hello " qu "World" qu ". And Goodbye."
print s
« Last Edit: September 28, 2018, 04:17:22 AM by Arnold »

Josť Roca

  • Sr. Member
  • ****
  • Posts: 263
Re: About Enums
« Reply #9 on: September 28, 2018, 04:50:25 AM »
Thanks Roland. It is a workaround, but I'm currently trying to ascertain if something that doesn't works as I expect or as I would like is a bug, an oversight or my ignorance of the language.

I'm also writing a documentation page related with the questions that I'm asking.
See: https://github.com/JoseRoca/WinPBX/blob/master/docs/Oxygen/Variables.md

I try to document a keyword and, if I have doubts, I post a question. Maybe Charles can use these pages as a draft and improve them.
« Last Edit: September 28, 2018, 07:42:03 AM by Josť Roca »

John

  • Hero Member
  • *****
  • Posts: 3556
Re: About Enums
« Reply #10 on: September 28, 2018, 06:56:52 AM »
Wow!

Great job and a productive O2 day.