Concatenating string constants

Topics related to the use of Oberon language features

Concatenating string constants

Postby cfbsoftware » Thu Feb 23, 2012 12:45 pm

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?
cfbsoftware
Site Admin
 
Posts: 387
Joined: Fri Dec 31, 2010 12:30 pm

Re: Concatenating string constants

Postby kevinhely » Fri Feb 24, 2012 7:08 pm

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.
kevinhely
 
Posts: 23
Joined: Wed May 18, 2011 3:35 am

Re: Concatenating string constants

Postby 4GlCoder » Thu Apr 26, 2012 9:57 pm

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..
4GlCoder
 
Posts: 27
Joined: Fri Jul 22, 2011 2:47 pm

Re: Concatenating string constants

Postby cfbsoftware » Fri Apr 27, 2012 8:26 am

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.
cfbsoftware
Site Admin
 
Posts: 387
Joined: Fri Dec 31, 2010 12:30 pm

Re: Concatenating string constants

Postby cfbsoftware » Tue Dec 23, 2014 10:36 pm

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.
cfbsoftware
Site Admin
 
Posts: 387
Joined: Fri Dec 31, 2010 12:30 pm


Return to Oberon Language

cron