Page 1 of 1
New operator Set-Append
Posted: 04 Oct 2017 15:17
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.

)
Re: New operator Set-Append
Posted: 04 Oct 2017 15:43
by bdeshi
nice to have (at least) these as well : +=, -=, /=, \=, *=
[edited]
Re: New operator Set-Append
Posted: 06 Oct 2017 13:56
by PeterH
Ha: just created some text - but Sammay has edited his text and I didn't notice

Quite funny
Though I'm late: my prepared post
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.
Re: New operator Set-Append
Posted: 24 Jan 2018 11:13
by PeterH
Just had a laugh
So if I did explain it bad - I'm just looking for the same as the VB operator
&= does.
Found it via a link to VB-docs from klownboy: thanks for that!
And I'd really use it
very often. Again and again...
Re: New operator Set-Append
Posted: 24 Jan 2018 11:16
by highend
Yeah, me too, so +5

Re: New operator Set-Append
Posted: 03 Feb 2018 12:36
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...
Re: New operator Set-Append
Posted: 03 Feb 2018 16:10
by PeterH
That's fine! Hey!
"Set-Prepend" was just another idea, so:
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?
Re: New operator Set-Append
Posted: 03 Feb 2018 16:34
by Filehero
Re: New operator Set-Append
Posted: 03 Feb 2018 16:36
by PeterH
For completeness: just changed one script to contain several
.= 
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>";
So thanks a lot!
Re: New operator Set-Append
Posted: 03 Feb 2018 16:53
by jupe
Nice!, even my meager scripting abilities will benefit from this, thanks.

Re: New operator Set-Append
Posted: 03 Feb 2018 17:07
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.

Re: New operator Set-Append
Posted: 03 Feb 2018 22:16
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
So: all is well
Have a fine Sunday!
(I hope you like it cold.)