New operator Set-Append

Features wanted...
Post Reply
PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

New operator Set-Append

Post by PeterH »

We have operator "=" to Set a variable.

What I often wish is a short form as "Set-Append operator" ("=." is just an example):

Code: Select all

   $listitems =. $entry;         // meaning:
   $listitems = $listitems . $entry;
OK: just sometimes the reverse, "Set-Prepend":

Code: Select all

   $listitems .= $entry;         // meaning:
   $listitems = $entry . $listitems;
It's just to save some typing, and some space in the lines.
(With indentation etc lines can be rather long sometimes. Shorter looks better. 8) )
Win11 Pro 223H2 Gerrman

bdeshi
Posts: 4249
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: New operator Set-Append

Post by bdeshi »

:tup:

nice to have (at least) these as well : +=, -=, /=, \=, *=

[edited]
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: New operator Set-Append

Post by PeterH »

Ha: just created some text - but Sammay has edited his text and I didn't notice :P Quite funny :tup:
Though I'm late: my prepared post :arrow:

Just to say: this could also be used for add, subtract, multiply and divide, eg =+, =-, =* and =/
(=+ and =- would be analog to incr, but I'd prefer the syntax of =+)
(OK: to inverse the operand for subtraction and division can be 2 more versions.)
Basically I'd prefer the = on left, can be read as "set to concationation" or "Set to sum".

Though: my main use and interest is just concatenation, as I really use it very often.

And to say again: to use =. is just an example - you might have other Ideas. But containing the = shows that it's relative to the set command.
Win11 Pro 223H2 Gerrman

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: New operator Set-Append

Post by PeterH »

Just had a laugh :lol:

So if I did explain it bad - I'm just looking for the same as the VB operator &= does. :maf:
Found it via a link to VB-docs from klownboy: thanks for that!

And I'd really use it very often. Again and again...
Win11 Pro 223H2 Gerrman

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: New operator Set-Append

Post by highend »

Yeah, me too, so +5 :mrgreen:
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60567
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: New operator Set-Append

Post by admin »

PeterH wrote:We have operator "=" to Set a variable.

What I often wish is a short form as "Set-Append operator" ("=." is just an example):

Code: Select all

   $listitems =. $entry;         // meaning:
   $listitems = $listitems . $entry;
OK: just sometimes the reverse, "Set-Prepend":

Code: Select all

   $listitems .= $entry;         // meaning:
   $listitems = $entry . $listitems;
Never heard about "Set-Prepend". In PHP (XY's role model) it's like this:

Code: Select all

$a = "Hello";
$a .= " John!";
echo $a; // Outputs Hello John!
Anyway, I always planned to add these operators, so hey-ho let's go!

BTW, I personally never liked the sequence .=, I find =. more natural. I'm inclined to allow both ways...

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: New operator Set-Append

Post by PeterH »

:whistle: :shock: :D :D :D

That's fine! Hey! :D

"Set-Prepend" was just another idea, so:

Code: Select all

 $a = "John";
 $a =. "Hello ";
says "Hello John". (Sometimes I must build a string right to left.)
But no question: what you've made are the most often needed expressions.

You said you "Experimentally added ... Compound Assignment Operators .=, +=, -=, *=, /=, \= ."
What's the experiment?
Win11 Pro 223H2 Gerrman

Filehero
Posts: 2644
Joined: 27 Feb 2012 18:50
Location: Windows 10 Pro x64

Re: New operator Set-Append

Post by Filehero »

:tup: :tup: :tup: :)

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: New operator Set-Append

Post by PeterH »

For completeness: just changed one script to contain several .= :arrow: seems to work fine!
Not just simple concatenations, but a bit more complex like:

Code: Select all

 $props .= SubStr("     $nr", -5) . " $propnm = (" . SubStr("     $lenval", -4) . ") $propval<crlf>";
:tup:

So thanks a lot!
Win11 Pro 223H2 Gerrman

jupe
Posts: 2794
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: New operator Set-Append

Post by jupe »

Nice!, even my meager scripting abilities will benefit from this, thanks.

:D

admin
Site Admin
Posts: 60567
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: New operator Set-Append

Post by admin »

PeterH wrote:You said you "Experimentally added ... Compound Assignment Operators .=, +=, -=, *=, /=, \= ."
What's the experiment?
Well, I was a bit surprised how easy it was to add it, so I added "Experimentally" as a voodoo-kind of protection against a rude awakening. Like when you take the umbrella along in order to prevent the rain -- usually works well. :)

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: New operator Set-Append

Post by PeterH »

Fine, that quite some scripters seem to be glad.
Fine, that it was easy.
Fine, that the voodoo seems to help.
Best of all, that you were surprised :biggrin:

So: all is well :appl:

Have a fine Sunday!
(I hope you like it cold.)
Win11 Pro 223H2 Gerrman

Post Reply