Author Topic: O2 quirks  (Read 7124 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Re: O2 quirks (can reopen a namespace)
« Reply #15 on: October 15, 2018, 09:25:01 AM »
In o2, a namespace can be reopened any time for simpler access to its variables.

But this may conflict with any implementation of nested namespaces.

  • Guest
Re: O2 quirks
« Reply #16 on: October 15, 2018, 01:52:30 PM »
I never have needed to use nested namespaces. I just have tried it to see if they are supported or not, but it is not something that I need. If they are not, I simply will put in my notes: "Nested namespaces are not supported". End of the history. What would be useful is that if they're not supported the compiler will catch any attempt to do it as an error. As you can see, I'm obsessed with error trapping.

In your example in the help file

Code: [Select]
int i=1
'
namespace aa
int i=10
namespace bb
int i=20
end namespace
'
print i + aa::i + bb::i '31
'
namespace bb
print i '20
end namespace

I noticed that you are opening namespace bb before closing namespace aa and I thought that nested namespaces were supported. But maybe you forget to close the namespace? This is another error that should be trapped :)

What really interests me are the constructors and transient objects we already have talked about. Thanks to them, and the oveloading operators, that in FB work with user defined types, I have developed several data types with FreeBasic to support variants, safe arrays, currency, decimal, etc.

> Yes, print is an overrideable core procedure, not a statement.

With overrideable do you mean that I can write my own overloaded print procedure? If yes, which is the prototype? That could be very useful, for example, to print the contents of objects like a variant.
« Last Edit: October 15, 2018, 02:18:51 PM by José Roca »

JRS

  • Guest
Re: O2 quirks
« Reply #17 on: October 15, 2018, 03:24:38 PM »
I heard the word VARIANT twice in that post. Are you getting close with a COM O2 solution?

José Roca

  • Guest
Re: O2 quirks
« Reply #18 on: October 15, 2018, 03:41:01 PM »
I can't do anything until my suggested changes regarding constructors and transient objects are implemented.

Charles Pegge

  • Guest
Re: O2 quirks (namespaces / using with)
« Reply #19 on: October 16, 2018, 02:30:51 AM »
Will keep namespaces non-nestable, which means that they do not have to be ended before starting another one. (this also applies to extern blocks).

namespace names will be able to contain extra double colons:

namespace ns::lengthy::deep


A simple extension of with syntax will enable lengthy namespace prefixes to be represented by 2 dots '..'

Code: [Select]
namespace ns::lengthy::deep
  int a=2
end namespace
'
with ns::lengthy::deep::
  print ns::lengthy::deep::a '2
  ..a = 4 'in assignment
  print ..a + ..a 'in expression
  int b[10]
  b[..a]=5 'syntax testing as indexer
end with
print b[4] '5

Charles Pegge

  • Guest
Re: O2 quirks (enumerations anon and named)
« Reply #20 on: October 16, 2018, 02:51:42 AM »
Named and anonymous enumerations will be supported.

If unique is disabled, it will still be possible to use named-enumeration members as though they were anonymous.

Code: [Select]
#unique on
enum bit ee
 a,b,c,d
end enum

print ee.c '4

Code: [Select]
#unique off
enum bit ee
 a,b,c,d
end enum

print c '4

Charles Pegge

  • Guest
Re: O2 quirks (core function overloading / print)
« Reply #21 on: October 16, 2018, 04:28:18 AM »

An example that relays back to the core print function:

Code: [Select]
function print(float a,b)
=========================
  print str(a,b) 'relay to core print function
end function

'#recordof print
print pi(),5
print "ok"


Charles Pegge

  • Guest
Re: O2 quirks (print overloading)
« Reply #22 on: October 16, 2018, 04:38:44 AM »
Another example. using a class or UDT:

Code: [Select]
'print overloading

type vector
===========
  float x,y,z
end type

function print(vector*v)
========================
  print v.x ", " v.y ", " v.z 'relay to core print
end function

vector a={1.5, 2.5, 3.5}
print a
print "ok"