Page 1 of 1
Concatenating string constants
Posted: Thu Feb 23, 2012 12:45 pm
by cfbsoftware
We are considering implementing an extension to Oberon in Astrobe to allow the use of + as a concatenation operator for string constants. This would be useful if you wanted to include double-quotes or non-printing characters in strings.
e.g.
Code: Select all
CONST
QuotedString = 022X + "String" + 022X;
or if you prefer:
Code: Select all
CONST
Quotes = 022X;
QuotedString = Quotes + "String" + Quotes;
An example of its use with non-printing characters would be e.g.
Code: Select all
CONST
UnixNewLine = 0AX;
DOSNewLine = 0DX + 0AX;
Any comments?
Re: Concatenating string constants
Posted: Fri Feb 24, 2012 7:08 pm
by kevinhely
Hi,
I think your proposal is a good idea. I thought I had identified a couple of (minor) objections but they faded away on examination. Here they are, for the record:
1) The + operator is already overloaded in Oberon to denote addition for numeric types and union for the SET type; string concatenation does not enjoy the commutativity of + that is shared by these operations (and there is no corresponding - operator either). However, since the operation is only for string
constants, this hardly matters.
2) I thought it might be in the "spirit" of the language to implement it as a standard procedure rather than as an operator (the shift operations could have been denoted by operators but Wirth opted for standard procedures instead). Somebody suggested as much in a post some months back, I think. The down side is coming up with a short name that isn't ugly (CAT?
) and having to write something like CAT(022X, CAT("String", 022X)) instead of your nicer 022X + "String" + 022X.
Best regards,
Kevin.
Re: Concatenating string constants
Posted: Thu Apr 26, 2012 9:57 pm
by 4GlCoder
Does this influence the current 60 character limitation?
I opt for more consistent rules: e.g.:
CONST
Pi =3.14159268;
twoPi = 2*Pi;
This should not give compiler errors..
Re: Concatenating string constants
Posted: Fri Apr 27, 2012 8:26 am
by cfbsoftware
4GlCoder wrote:Does this influence the current 60 character limitation?
No - that is a separate issue. The concatenated CONST string would be limited to 60 characters unless the limit was also increased.
4GlCoder wrote:
I opt for more consistent rules: e.g.:
CONST
Pi =3.14159268;
twoPi = 2*Pi;
This should not give compiler errors
This is currently documented as a compiler restriction. Only INTEGERs can be used in an expression in CONST declarations. It may be relaxed in the future.
Re: Concatenating string constants
Posted: Tue Dec 23, 2014 10:36 pm
by cfbsoftware
4GlCoder wrote:Does this influence the current 60 character limitation?
The maximum length of a string constant has been increased to 256 characters (including the terminating null) in the v5.2 releases of Astrobe.