Array concatenation lazarus / 62-General ---------------------------------------------------------------------- VTwin · 2021-11-03 20:27 Shout out to Free Pascal. I just came across this: https://rosettacode.org/wiki/Array_concatenation#Free_Pascal Simply brilliant! Thanks Free Pascal devs! ---------------------------------------------------------------------- Thaddy · 2021-11-04 08:30 I prefer Concat() over +. I am happy there is a modeswitch for it. I have quite a lot of code with operator overloads. Syntax is almost just as brief. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i array2 := concat(array0,array1);Added this to rosetta code and also added a result array, that was missing in the first example. ---------------------------------------------------------------------- VTwin · 2021-11-04 12:31 Thanks Thaddy, I did not think out the full consequences before posting.  I also override + as vector addition (not concatenation) for integer and float arrays, so concat is a better alternative for me. While it may make sense for strings, I will avoid it. Modeswitch off! Thanks for editing Rosetta. Free Pascal's concise syntax shines. ---------------------------------------------------------------------- BobDog · 2021-11-04 13:05 Concatenate longwords. Is there a freepascal way? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  function concatL(n1:longword;n2:longword):qword ;varres:qword;begin     plongword(@res)[0]:=n1 ;     plongword(@res)[1]:=n2 ;     exit( res);  end;  var a,b:longword; q:qword;  begin a:=1314; b:=1066; q:=concatL( a,b); writeln(q); writeln(lo(q),' ',hi(q)); writeln('Press return to end . . .'); readln;  end. ---------------------------------------------------------------------- MarkMLl · 2021-11-04 13:10 Quote from: VTwin on November 04, 2021, 01:31:58 pmThanks Thaddy, I did not think out the full consequences before posting.  I also override + as vector addition (not concatenation) for integer and float arrays, so concat is a better alternative for me. While it may make sense for strings, I will avoid it. Modeswitch off! IMO, if Pascal hadn't offered simple string concatenation from its earliest days it would have made even less impact relative to BASIC et al. However now that overrides are available and widely used it would be desirable if concatenation functionality could be decoupled from the + operator: Perl uses . but in my own scripting etc. I prefer _ (with a non-alphanumeric on each side). MarkMLl ---------------------------------------------------------------------- Thaddy · 2021-11-04 13:20 Quote from: BobDog on November 04, 2021, 02:05:10 pm To concat would be a simple shl operation on the first and an add to the second. Your code does not make sense. ---------------------------------------------------------------------- BobDog · 2021-11-04 16:15 I can get a or b shl x to work  lower down the data types, but not for qword - longword. Maybe you could help. Anyway there are many ways to concatenate in the upper two ranges of integer types. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  usessysutils,strutils;   function concatL(n1:longword;n2:longword):qword ;varres:qword;begin     plongword(@res)[0]:=n1 ;     plongword(@res)[1]:=n2 ;     exit( res); end;    function concatL2(n1:longword;n2:longword):qword ; typeunion =recordcase integer of0:(a:qword);1:(b,c:longword);end; var  u:union; begin u.b:=n1; u.c:=n2; exit(u.a); end;  function concatL3(n1:longword;n2:longword):qword ; var a,b:ansistring; ans:qwor d; t:word; begin a:=inttohex(n1,8); b:=inttohex(n2,8); val('$'+b+a,ans ,t); exit(ans); end;  var a,b:longword; q:qword=0;   begin a:=42949672 94; b:=4294967295; q:=concatL(a,b); writeln(q); q:=0; q:=concatL2(a,b) ; writeln(q); q:=0; q:=concatL3(a,b); writeln(q); writeln(lo(q),' ',hi(q)); writeln('Press return to end . . .'); readln;  end. ---------------------------------------------------------------------- VTwin · 2021-11-04 19:30 Quote from: MarkMLl on November 04, 2021, 02:10:27 pmIMO, if Pascal hadn't offered simple string concatenation from its earliest days it would have made even less impact relative to BASIC et al. To clarify, I will not avoid string concatenation using +, it is too ingrained. I meant "I will avoid it for dynamic arrays". ---------------------------------------------------------------------- Thaddy · 2021-11-04 20:58 May have been confusing: string concats - the original subject - differ from integer concats. Hence my last reply is only applicable to integer concats (any type) and the result from two longints with a shift and add is a concat and not an addition. Of course provided a result that is twice the size of the integers. Before you say silly, this is a pretty normal operation for hardware access (pins) ---------------------------------------------------------------------- Thaddy · 2021-11-04 21:12 @VTwin I forgot to thank you for the original entry!  Feel free to edit my addition. ---------------------------------------------------------------------- PascalDragon · 2021-11-05 12:44 Quote from: VTwin on November 03, 2021, 09:27:55 pmShout out to Free Pascal. I just came across this: https://rosettacode.org/wiki/Array_concatenation#Free_Pascal Simply brilliant! Thanks Free Pascal devs! See also here (and points 2.2.3 till 2.2.8 ) and this announcement mail. ---------------------------------------------------------------------- VTwin · 2021-11-05 13:47 Quote from: PascalDragon on November 05, 2021, 01:44:11 pmSee also here (and points 2.2.3 till 2.2.8 ) and this announcement mail. Many thanks! I had not yet done a thorough reading of the new features in 3.2.0. I love the new features supporting dynamic arrays. ---------------------------------------------------------------------- Kays · 2021-11-05 17:53 Quote from: VTwin on November 03, 2021, 09:27:55 pmhttps://rosettacode.org/wiki/Array_concatenation#Free_Pascal Simply brilliant! Thanks Free Pascal devs!And thanks to the guy documenting it there.    But seriously, this expression of thanks by you should serve us as a reminder that we’ll need to continually work on publicity.