Wondering if I am not comprehending everything about namespaces...
I'm ok with functions and #defines in namespaces... but DIM'ing strings and initializing them in there... also using NULLs in string initialization... and accessing any of those attempted strings outside the namespace... seems to be an issue for me.
Note: The real initialization literals are longer. I just cut them off for this test rig to get rid of the code wrapping.
See comments for issues:
Code: Select all
namespace test_ns
'
#define _NUL_ chr(0)
#define _TAB_ chr(9)
#define _LF_ chr(10)
#define _CR_ chr(11)
#define _SPC_ chr(32)
#define _DQ_ chr(34)
#define _SQ_ chr(39)
#define _DEL_ chr(127)
'
' NAMESPACE related Compiler Errors with STRING variables:
'
' Variable define and initialize:
' 11: No strings will compile with a literal "chr(0)" in them.
' 87: Can't initialize a variable length string.
'
' Variable use:
' 42: Strings that compile are not visible outside the namespace.
'
' CONST
' ---------------------------------------
' _NUL_
' error 11: Expected constant, _WORD_BREAK_CHARS_ in 'const _WORD_BREAK_CHARS_ as String = _NUL_ ...
'const _WORD_BREAK_CHARS_ as String = _NUL_ + _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
' NO _NUL_
' Compiles - but not visible outside the namespace.
' error 42: Variable not declared, _WORD_BREAK_CHARS_ in 'print "len of ...
'const _WORD_BREAK_CHARS_ as String = _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
'
' Variable length
' ---------------------------------------
' _NUL_
' error 87: Var-len strings cannot be initialized in 'dim _WORD_BREAK_CHARS_ as String = _NUL_ ...
'dim _WORD_BREAK_CHARS_ as String = _NUL_ + _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
' NO _NUL_
' error 87: Var-len strings cannot be initialized in 'dim _WORD_BREAK_CHARS_ as String = _NUL_ ...
'dim _WORD_BREAK_CHARS_ as String = _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
'
' Fixed length
' ---------------------------------------
' _NUL_
' error 11: Expected constant in 'dim _WORD_BREAK_CHARS_ as String * 37 = _NUL_ ...
'dim _WORD_BREAK_CHARS_ as String * 37 = _NUL_ + _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
' NO _NUL_
' Compiles - but not visible outside the namespace.
' error 42: Variable not declared, _WORD_BREAK_CHARS_ in 'print "len of ...
dim _WORD_BREAK_CHARS_ as String * 37 = _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
'
' Fixed length - SHARED
' ---------------------------------------
' _NUL_
' error 11: Expected constant in 'dim shared _WORD_BREAK_CHARS_ as String * 37 = _NUL_ ...
'dim shared _WORD_BREAK_CHARS_ as String * 37 = _NUL_ + _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
' NO _NUL_
' Compiles - but not visible outside the namespace.
' error 42: Variable not declared, _WORD_BREAK_CHARS_ in 'print "len of ...
'dim shared _WORD_BREAK_CHARS_ as String * 37 = _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
'
end namespace
' Everything with a local DIM as CONST STRING works.
' Just a problem with defining and initializing STRINGs in namespace.
'
'''dim _WORD_BREAK_CHARS_ as const String = _NUL_ + _TAB_ + _LF_ + _CR_ + _SPC_ + "!" + _DQ_ + "#$%&" + _SQ_
'
print
print
print "outside namespace: len of _WORD_BREAK_CHARS_ = "; len( _WORD_BREAK_CHARS_)
'print "outside namespace: len of _WORD_BREAK_CHARS_ = "; len( test_ns._WORD_BREAK_CHARS_)
print
print