Dereference opereator in interpolation

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

Dereference opereator in interpolation

Post 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.
Win11 Pro 223H2 Gerrman

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

Re: Dereference opereator in interpolation

Post 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.

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

Re: Dereference opereator in interpolation

Post 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!
Win11 Pro 223H2 Gerrman

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

Re: Dereference opereator in interpolation

Post 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.

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

Re: Dereference opereator in interpolation

Post 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: )
Win11 Pro 223H2 Gerrman

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

Re: Dereference opereator in interpolation

Post 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:
Win11 Pro 223H2 Gerrman

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

Re: Dereference opereator in interpolation

Post 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:
Win11 Pro 223H2 Gerrman

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

Re: Dereference opereator in interpolation

Post by admin »


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

Re: Dereference opereator in interpolation

Post 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.
Win11 Pro 223H2 Gerrman

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

Re: Dereference opereator in interpolation

Post by admin »

By "old" you mean "at most 4 weeks", right?

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

Re: Dereference opereator in interpolation

Post 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: )
Win11 Pro 223H2 Gerrman

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

Re: Dereference opereator in interpolation

Post 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;

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

Re: Dereference opereator in interpolation

Post 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.)
Win11 Pro 223H2 Gerrman

Post Reply