Page 1 of 1

Dereference opereator in interpolation

Posted: 11 Aug 2023 23:57
by PeterH
The dereference operator defines a restriction not to be used in interpolation, i.e. in heredoc and in double quotes.
Is there a good reason for this?
As it means that every time you need a deref. variable in heredoc or quotes, you must first copy it to a temp- (or dummy-)var, and refer to that in the text. I'd think the combi of deref and a var, i.e. *$xxx, is rather unique and should not be the reason.

So, if possible, I wish to allow dereferenced vars in interpolation.

Re: Dereference opereator in interpolation

Posted: 12 Aug 2023 10:55
by admin
Indeed, I see no good reason not to allow dereferencing in interpolation, and curiously (though I comment and document everything I do) I can find no explanation for why I stopped allowing it in v14.30.0006 - 2014-07-14 14:30.

So, experimentally, I will allow it.

Re: Dereference opereator in interpolation

Posted: 12 Aug 2023 12:17
by PeterH
To be true - I didn't really expect it. But if you don't ask...

OK: I'll be the first to test it :mrgreen:
(Just to say: I'm the user using <<<#>>> for heredoc)

Thanks!

Re: Dereference opereator in interpolation

Posted: 12 Aug 2023 12:18
by admin
I made it like this now ...

Code: Select all

Note that the dereferencing is performed recursively until the task is completely done:
  // It's a fish! (*$vd2 -> *$vd -> $v -> "fish")
    $v = "fish"; $vd = '$v'; $vd2 = '*$vd'; echo "It's a *$vd2!"; //fish (*$vd2 -> *$vd -> $v -> "fish")
... but I guess this is not really expected. I'd like to hear what you think.

Re: Dereference opereator in interpolation

Posted: 12 Aug 2023 12:30
by PeterH
OK: a bit strange as for one '*' there can be several substitutions.
There *can* be situations where it is negative - but I think more are positive.
And I can think of no situation where I have a dereferenced variable containing another var name, i.e. where it would happen unexpected.

So I would say it's OK to be recursive.
(As I know me I would use it somewhen :oops: )

Re: Dereference opereator in interpolation

Posted: 12 Aug 2023 12:37
by PeterH
...but:
as there is / there seems no way to disable it, you would never be able to prevent these multiple substitutions.

edit typos :whistle:

Re: Dereference opereator in interpolation

Posted: 12 Aug 2023 20:17
by PeterH
1) Tested! :tup:
Will wait a bit before I delete the old/commented instructions :roll:

2) As long as there would be no ability to *prevent* recursive substitutions, I think it's OK that you didn't do it!

And once again: thanks! :beer:

Re: Dereference opereator in interpolation

Posted: 10 Sep 2023 11:21
by admin

Re: Dereference opereator in interpolation

Posted: 10 Sep 2023 12:05
by PeterH
Thanks for the hint!

It seems nothing changed for a new installation.
That means: a new installation does not work with (all/some) old scripts. Bad for new users downloading old scripts :-(

Wouldn't it be helpful to define AID as an operand of the SETTING command - so any old script could be made working bei adding

Code: Select all

 setting AID 0; // or alike
This would be easy to explain, and old scripts could be made working by just adding this stmt, without any further manipulation.

Re: Dereference opereator in interpolation

Posted: 10 Sep 2023 12:08
by admin
By "old" you mean "at most 4 weeks", right?

Re: Dereference opereator in interpolation

Posted: 10 Sep 2023 12:34
by PeterH
You are right: I misinterpreted the dflt of AID as the general dflt of this setting! (Though the first chapter does explain it :oops: )
(But I must say: I liked it!)

Before next misunderstanding: is AID only for the current script, or is it permanent?
(As you don't mention a .ini-setting it seems to be restricted to the current script? *Like* a setting-operand :roll: )

Re: Dereference opereator in interpolation

Posted: 10 Sep 2023 12:37
by admin
Yes, restricted to the current script. If you really need dereferencing in interpolation (and it's only you so far ;) ) you have to work for it and type 4 characters: aid;

Re: Dereference opereator in interpolation

Posted: 10 Sep 2023 12:49
by PeterH
OK: aid; in each script (needing interpolation).

I thought about a wish for settingP aid 1; - but if it's only me...
(...I know what to do if a new script of mine starts to show *$varname :whistle: )
...and in the end it's only a few.

(The end: I will be out now.)