Deref Anywhere is Major Break in Backward Compatibility

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by TheQwerty »

admin wrote:Wow, little overkill maybe? ;)
Probably... :lol:

And the Interpolate SC is definitely.

nerdweed
Posts: 653
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by nerdweed »

If you wanted to go even further - I know we've seen some requests for fine tuning which variables are resolved so this deref SC could really be an interpolate SC with flag:
I have just been wondering how to avoid the variable on left side in a Heredoc from resolving. I had been using a place holder variable but it gets unmanagable with longer scripts

The below code fails and hence as it can't assign 2 to 1

Code: Select all

 $flag=1 ;
 $Check=<<<FOO
$flag=2 ;
#Foo ;
My current Workaround

Code: Select all

 $flag=1 ;
 $var_flag = '$flag' ;
 $Check=<<<FOO
$var_flag=2 ;
#Foo ;

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by PeterH »

Maybe some typo?

Test:

Code: Select all

 $flag=1 ;
 $Check=<<<FOO
$flag=2 ;
FOO;
Edit: I first saw the typo - but this doesn't help on not resolving variables in heredoc.
Last edited by PeterH on 14 Jul 2014 15:39, edited 1 time in total.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by TheQwerty »

@nerdweed: I don't think the interpolate SC would actually help with that scenario. Currently you just have to be very smart about your usage of variables in and outside of the HEREDOC.

If I was hard-pressed to use the same variable in each I'd probably do some post-processing like so:

Code: Select all

 $flag = 1;
 $Check = <<<FOO
$:flag = $flag + 2;
FOO;
 $Check = Replace($Check, '$:', '$');
 Text $Check;
The problem is you have to pick a pattern that you know won't be in the interpolated HEREDOC - so I had to make sure I didn't put a literal '$:' in FOO and also that no variable could contain that.

No matter what using the same variable names sure makes it difficult to find a compromise between the desired functionality and legible code.

Maybe Don could give us a new XY var: '<$ flag>' which would get resolved to '$flag' thus making the above:

Code: Select all

 $flag = 1;
 $Check = <<<FOO
<$ flag> = $flag + 2;
FOO;
 Text $Check;
I suppose that could also offer another way to do derefs: '<*$ flag>'

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by PeterH »

@ dereference:

Seems the problem is because * is added in front of the variable, and so is ambiguous.

:idea: What about using eg. $*var, or even $$var? This is unique.

nerdweed
Posts: 653
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by nerdweed »

PeterH wrote:Maybe some typo?
Yes, but only here. I typed it from memory and is was a dummy code. :biggrin:
TheQwerty wrote:No matter what using the same variable names sure makes it difficult to find a compromise between the desired functionality and legible code.
It was just a simple example. I have some scripts which I have added as UDC and use Heredoc to generate a runtime menu and load it - like here http://www.xyplorer.com/xyfc/viewtopic. ... 30#p104976
TheQwerty wrote: Maybe Don could give us a new XY var: '<$ flag>' which would get resolved to '$flag' thus making the above:

Code: Select all

 $flag = 1;
 $Check = <<<FOO
<$ flag> = $flag + 2;
FOO;
 Text $Check;
I suppose that could also offer another way to do derefs: '<*$ flag>'
This sounds great.

I will check the post processing idea as well. Thanks

Post Reply