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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 12th November 2008, 11:26   #1  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
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".
Gavino is offline   Reply With Quote
Old 12th November 2008, 21:25   #2  |  Link
stickboy
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.
stickboy is offline   Reply With Quote
Old 12th November 2008, 23:13   #3  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by stickboy View Post
It'd make my Undefined() function less magical though. Oh well.
Thanks for your support, stickboy.
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.
Gavino is offline   Reply With Quote
Old 20th November 2008, 13:42   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
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() {}
@stickboy - perhaps you could change your Undefined function to use this method. Because of the issue in this thread, the code
Code:
x = Undefined
gives error "Undefined: Cannot be called with any arguments." if 'last' is defined at this point.
Gavino is offline   Reply With Quote
Old 20th November 2008, 21:38   #5  |  Link
IanB
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.
IanB is offline   Reply With Quote
Old 21st November 2008, 05:05   #6  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
Quote:
Originally Posted by Gavino View Post
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() {}
Is that behavior defined to return the "undefined" value and not garbage?
Quote:
@stickboy - perhaps you could change your Undefined function to use this method. Because of the issue in this thread, the code
Code:
x = Undefined
gives error "Undefined: Cannot be called with any arguments." if 'last' is defined at this point.
Hmm... yeah, that's a problem. I always explicitly use parentheses when calling functions though.
stickboy is offline   Reply With Quote
Old 21st November 2008, 20:10   #7  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by stickboy View Post
Is that behavior defined to return the "undefined" value and not garbage?
I discovered it by accident - I had left a function as a placeholder and forgot to fill in its body. Surprised to find it did not give a syntax error, I experimented further and found it did indeed give an 'undefined' value.

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()));
Since the AVSValue() constructor gives a proper 'undefined' value, it can be relied on not to be garbage.
Gavino is offline   Reply With Quote
Old 22nd November 2008, 07:53   #8  |  Link
stickboy
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() }
stickboy is offline   Reply With Quote
Old 22nd November 2008, 15:17   #9  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
@stickboy

If you don't like the empty function, how about
Code:
function Undefined() { dummy=0 }
which also works, though the docs are silent on this one too.

[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.
Gavino is offline   Reply With Quote
Old 22nd November 2008, 17:17   #10  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,366
Quote:
[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().]
I'm still not sure how this 'undefined' stuff works. Gavino, could you add about this to the online docs? (You probably can explain it better than me )
Wilbert is offline   Reply With Quote
Old 22nd November 2008, 20:17   #11  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by Wilbert View Post
Gavino, could you add about this to the online docs?
OK, I'll have a go and report back here when done.
Gavino is offline   Reply With Quote
Old 22nd November 2008, 22:36   #12  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
@Gavino,
Code:
function Undefined() { dummy=0 }
and
Code:
function Undefined() { }
are the same. They both rely on the same boundary case code in the parser for the final return value, which is currently without formal definition.

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.
IanB is offline   Reply With Quote
Old 23rd November 2008, 01:38   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Quote:
Originally Posted by IanB View Post
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.
OK, thanks - that sets my mind at rest.

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.
Gavino is offline   Reply With Quote
Old 26th November 2008, 15:15   #14  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
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.)
Gavino is offline   Reply With Quote
Old 26th November 2008, 21:58   #15  |  Link
Wilbert
Moderator
 
Join Date: Nov 2001
Location: Netherlands
Posts: 6,366
Great thanks! I will look at it and copy it over to the offline docs.
Wilbert is offline   Reply With Quote
Old 4th January 2010, 04:32   #16  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
I have added a new script function "Undefined()" to CVS, it returns an AVSValue() i.e. the undefined state.
IanB is offline   Reply With Quote
Old 4th January 2010, 12:11   #17  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,433
Thanks, Ian (and Happy New Year ).
Gavino is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:27.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.