Forum > General

Incompatibility with Borland Pascal in expressions like "string + + string"

(1/4) > >>

Avinash:
In Borland Pascal programs two consecutive pluses were often used when writing string expressions in several lines

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---S := some_long_string_expression +     + some_long_string_expression +     + some_long_string_expression;
It looks good and improves the readability of the code.
FPC doesn't understand more than one plus for strings (although it does for numbers).
To minimize the editing of old code when adapting to FPC, I partially solved the issue by operator overloading:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  Operator + (const S: String): String; Inline;  begin    Result := S;  end;
But two problems remained unresolved:
(a) this does not work for definitions of multi-line string constants
(b) it doesn't work in expressions like

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---S := some_long_string_expression +     + CHAR + some_long_string_expression;
I was unable to overload the operator for Char in a similar way («Impossible operator overload»).

It is not difficult to correct the code a little, but maybe some solutions are still possible?

winni:
Hi!

You don't need to overload anything. It is all there.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  s = 'abc'+'d'+'efg' +#32 +'hij';var p : pchar;      msg : string; beginp := ' XYZ';msg :=  s + p;showMessage (msg);end; 
Winni

MarkMLl:
I'm one of the noisier people around here when it comes to asking for language extensions, but I've never seen anything like this before and wish I hadn't today.

Strings aren't numbers, they aren't signed, and + isn't defined as a unary operator on them. If it was, it would be far more useful as an alias of StrToInt().

MarkMLl

winni:
Hi!
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- String3 := String1 + String2;
This horrible Syntax was introduced by Turbo Pascal and stolen from Basic.

The original Pascal Syntax - which also exists n fpc - is


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---String3 := concat (String1,String2); 

A lot of bad ideas where introduced by Turbo Pascal like the mini sets with only 256 elements.

Or the "else" instead of "otherwise" in the case statement.

And the Unit concept was not their idea but stolen from UCSD Pascal. There the Units were called Library.

High time to get rid of that trash.

Winni

MarkMLl:
@Winni I'm happy enough with operators, and in fact would prefer to see more flexibility in being able to define and use them. However in retrospect + as concatenation has- IMO- turned out to be a very bad idea, since it's meant that the language can't easily also use + for vector summation.

I came across a book in the university library (i.e. quite a few years ago) which discussed monadic and dyadic operators, but didn't really get the idea until I started tinkering with APL comparatively recently. The practical upshot is that an operator not appearring to make sense in the current context is not sufficient grounds to build an "ignore this" rule into the compiler: call it a syntax error but don't just drop it.

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version