Minor scripting related wishes (a generic thread)

Features wanted...
SammaySarkar
Posts: 4235
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Minor scripting related wishes (a generic thread)

Post by SammaySarkar »

Null if $c=Null was a constant like True False ...

"And I think it's not really neccessary as long as you can express the meaning of a non-specified operand by supplying the default value for this operand"I know, but asked because built-in functions already have default values defined. Redundundancy...
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: Minor scripting related wishes (a generic thread)

Post by PeterH »

SammaySarkar wrote:Null if $c=Null was a constant like True False ...

"And I think it's not really neccessary as long as you can express the meaning of a non-specified operand by supplying the default value for this operand"I know, but asked because built-in functions already have default values defined. Redundundancy...
But you know that TRUE/FALSE are *inside* the values of all possible strings: any string resolving to 0 is FALSE, any other string is TRUE.
And if you *set* TRUE or FALSE you just set 1 or 0. (Identical '1' or '0'.)

What you are looking for is a variable content saying "I'm no string". But this is outside the definition of a variable representing any string, including the nul string "".
But inside a function there can be tested: is a parameter specified or not - if not a default is used. Now you want to specify a variable for a parameter, but wish it's meaning to be "nothing specified". No... :naughty:
W7(x64) SP1 German
( +WXP SP3 )

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

Re: Minor scripting related wishes (a generic thread)

Post by SammaySarkar »

PeterH wrote:Now you want to specify a variable for a parameter, but wish it's meaning to be "nothing specified". No...
I took the concept of a Null constant name from other languages, where $c = Null; is possible. In JS:

Code: Select all

var foo = null;
maybe in XYscript lanuguage I should have said this instead $c = $Null where $Null is a special or defined variable whose value is empty.

anyways let it go, i asked for it and Don said not possible now.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 50601
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Minor scripting related wishes (a generic thread)

Post by admin »

FYI: I checked this in PHP and AFAIK it does not offer a way to set a variable to a value that would be equivalent to omitting it:

Code: Select all

// test 1: error in line 3  ( echo test($b); ) ------------------------------------------
$b = "x";
unset($b);
echo test($b);
function test($a = "def") {
  return $a;
}

// test 2: no error, line 3 echoes NULL
$b = "x";
$b = NULL;
echo test($b);
function test($a = "def") {
  return $a;
}
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Minor scripting related wishes (a generic thread)

Post by PeterH »

admin wrote:FYI: I checked this in PHP and AFAIK it does not offer a way to set a variable to a value that would be equivalent to omitting it:

Code: Select all

// test 1: error in line 3  ( echo test($b); ) ------------------------------------------
$b = "x";
unset($b);
echo test($b);
function test($a = "def") {
  return $a;
}

// test 2: no error, line 3 echoes NULL
$b = "x";
$b = NULL;
echo test($b);
function test($a = "def") {
  return $a;
}
I think both execute as expected :whistle: I'd interpret the 1st case in another way: :D
You defined that an undefined var returns it's name as it's value - so it does :arrow: no error.

If you'd wish you could change functions to interpret a non-defined (= non-initialized) var as "no parameter". [like isset()] But I don't think it would make sense.
(Overloading: uninitialized variable might be an error; but then also might be "no parameter meant".)
W7(x64) SP1 German
( +WXP SP3 )

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

Re: Minor scripting related wishes (a generic thread)

Post by PeterH »

SammaySarkar wrote:
PeterH wrote:Now you want to specify a variable for a parameter, but wish it's meaning to be "nothing specified". No...
I took the concept of a Null constant name from other languages, where $c = Null; is possible. In JS:

Code: Select all

var foo = null;
maybe in XYscript lanuguage I should have said this instead $c = $Null where $Null is a special or defined variable whose value is empty.
Could it be that in JS a variable has more states than in XY? I.e. that variables can also have a type, like string and integer? Then it's possible to define info outside the string-contents.
W7(x64) SP1 German
( +WXP SP3 )

admin
Site Admin
Posts: 50601
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Minor scripting related wishes (a generic thread)

Post by admin »

PeterH wrote:If you'd wish you could change functions to interpret a non-defined (= non-initialized) var as "no parameter". [like isset()] But I don't think it would make sense.
(Overloading: uninitialized variable might be an error; but then also might be "no parameter meant".)
I think I could do that. Whether it makes sense, well, that's a good question.

I could add more states to variables, also NULL. I'm the coder, I can do everything I want. :mrgreen: But is NULL the same as "omitted"? Not in the languages I have heard of.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Minor scripting related wishes (a generic thread)

Post by SammaySarkar »

no not the same. "No value/omitted" would be prerreferred, because the concept of null is completely absent in xyscripting.

But I think it can cause too much trouble.

As it stands, introducing an empty value constant may be possible, but detecting this in one expression is not possible now afaik.

When a var is initialized but not given any value, it should logically have and return empty. (instead of returning var name) :bug:
set $a;

this will have to convey that $a has no value. How? '' ? then how will it differ from $a = '';
?
And how to use this fact in expressions?

if ($a == ??) { echo '$a is really empty'; }

Mightn't this feature break compatibility (somehow) ?



hh, did I open a can of worms!
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

admin
Site Admin
Posts: 50601
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Minor scripting related wishes (a generic thread)

Post by admin »

Let's close the can before the worms come out.
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

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

Re: Minor scripting related wishes (a generic thread)

Post by PeterH »

@Sammay: set $a; doesn't return $a, it returns nothing, also called an empty string - the same as $a='';

If you never did set $a, or unset $a; - then it is undefined and returns the string $a. (As if it were no variable, but just the string $a would be meant.)

In the end it seams you want a variable, but it should contain less than an empty string. I can't imagine...
W7(x64) SP1 German
( +WXP SP3 )

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

Re: Minor scripting related wishes (a generic thread)

Post by SammaySarkar »

PeterH wrote:set $a; doesn't return $a, it returns nothing
Absolutely right. I wonder why I said that, and even extrapolated on that. My unthinkably embarrassing mistake. (Maybe a worm got out :whistle: )
Thanks for the correction.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

nerdweed
Posts: 593
Joined: 25 Feb 2012 07:47

Re: Minor scripting related wishes (a generic thread)

Post by nerdweed »

On file operations, the "Goto Last Target (Ctrl+Alt+F7), offers a nice functionality of taking to the last target as well as selecting the copied/moved files (even if they were renamed on collisions).

Wish: a variable to hold full qualified path names in the destination.

admin
Site Admin
Posts: 50601
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Minor scripting related wishes (a generic thread)

Post by admin »

Good idea. Next version has this:

Code: Select all

echo <get "targetitems">;
PS: Just saw it does not really work yet in 0003 ... wait...
FAQ | XY News RSS | XY Twitter | Stay home! 🎸 Or wear a mask! 😷

nerdweed
Posts: 593
Joined: 25 Feb 2012 07:47

Re: Minor scripting related wishes (a generic thread)

Post by nerdweed »

Yippee. Thanks. Time to optimize some scripts.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: Minor scripting related wishes (a generic thread)

Post by SkyFrontier »

Sometimes readurl() pops a message:
"url not found. error #0".
which in turn halts the script sequence.
It should first return a usable value instead.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

Post Reply