Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
12th November 2008, 11:26 | #1 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Result of NOP()
The function NOP() currently returns a value of 0 (implemented as C++ NULL).
Would it not be better to return an 'undefined' value, ie a value for which Defined() returns false? That way, it would be different from any other value and guaranteed to produce an error if you try to use it in an operation. If it's indistinguishable from zero, its utility is debatable - you might just as well write "0". |
12th November 2008, 21:25 | #2 | Link |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
That's an interesting idea. I like it. It might break existing scripts though, but those scripts would have been using NOP() improperly anyway, and it'd be nice to catch those errors.
It'd make my Undefined() function less magical though. Oh well. |
12th November 2008, 23:13 | #3 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
Despite being a big fan of your functions, I didn't realise that Undefined() existed - found it now in jdl-util.avsi. I suppose that weakens the case for changing NOP(), but it would be nice to have this in the core. As I said, zero seems like a poor substitute. |
|
20th November 2008, 13:42 | #4 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Maybe only a few people are interested in this issue, but for the record, I resolved it by defining this function in an avsi file in my plugins folder:
Code:
# Redefine NOP() to give 'undefined' value function NOP() {} Code:
x = Undefined |
20th November 2008, 21:38 | #5 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
For better or worse NOP() is the way it is. Changing it now would violate our do no harm concept.
Your idea is an interesting one and indicates it might be useful to add a new function whose return value is in the undefined state, but as you have shown, it is trivial to roll your own with a simple function declaration. |
21st November 2008, 05:05 | #6 | Link | ||
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Quote:
Quote:
|
||
21st November 2008, 20:10 | #7 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
I can't find anything in the docs that specifies what it should do one way or the other, but rooting around in the source code, I see the parser (ScriptParser::ParseBlock) treats the result as a fresh AVSValue. Code:
return result ? result : PExpression(new ExpConstant(AVSValue())); |
|
22nd November 2008, 07:53 | #8 | Link |
AviSynth Enthusiast
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
|
Well, if Wilbert or someone is willing to formalize it in the docs and to guarantee that behavior won't change, okay.
I suppose I also could do: Code:
function UndefinedHelper(val "dummyArg") { return dummyArg } function Undefined() { return UndefinedHelper() } |
22nd November 2008, 15:17 | #9 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
@stickboy
If you don't like the empty function, how about Code:
function Undefined() { dummy=0 } [Indeed, the concept of the 'undefined' value, although well-defined at the API level, is essentially missing from the language-level documentation and is only hinted at with the explanation of Defined().] Hopefully, the 'implicit last' problem will be recognised as a bug (and fixed), making your original definition work in all cases. |
22nd November 2008, 17:17 | #10 | Link | |
Moderator
Join Date: Nov 2001
Location: Netherlands
Posts: 6,364
|
Quote:
|
|
22nd November 2008, 22:36 | #12 | Link |
Avisynth Developer
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
|
@Gavino,
Code:
function Undefined() { dummy=0 } Code:
function Undefined() { } At the script level the undefined state has been really only intended for unsupplied optional arguments to user defined function. Stickboys two function solution is about only using nailed down features to get the desired result, i.e. not risking boundary case code and tempting fate. I don't really see a problem nailing down the current behaviour and documenting it so it can be formally used. One should do a pass through the code and make sure everything is consistent. |
23rd November 2008, 01:38 | #13 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
I understand what was behind stickboy's concerns. It wasn't clear to me either how much of the current implementation could be considered 'nailed down', but I thought it unlikely the parser would change. And I wasn't sure whether the omission of certain details in the docs was deliberate or an oversight. I was already planning to verify my writeup with actual test cases and a cross-check with the code. |
|
26th November 2008, 15:15 | #14 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
I have now updated the wiki to cover 'undefined' values and tie down the rules for return values.
I have tried to make the documentation accurate and complete without being too pedantic or including unnecessary details. With things like this it can be tricky to get the right balance, so I hope I've achieved it. I have made changes to the following pages: Grammar Script variables Boolean functions (for Defined()) User defined script functions The full AviSynth grammar I have also taken the opportunity to correct any errors I spotted on those pages. You can use the history/diff facility to see what's changed. (Note that in some cases, the changes span more than one iteration.) |
Thread Tools | Search this Thread |
Display Modes | |
|
|