Sanoblast wrote:

> >>> Looking back, now that Vim script has become much more complex, a bit
> >>> more type checking would be good.
> >>>       
> >> A valid point. Mabye this could be done by an assert command/function 
> >> that checks its arguments or does nothing depending on an option (maybe 
> >> 'debug')/flag/variable?
> >>     
> >
> > Problem is the syntax of type declarations.  Would require function
> > prototypes, for example.  Vim script follows Python here: no type
> > declarations.
>
> I'm not sure if I can follow you here. I was thinking of something 
> really simple in the line of:
> 
>     fun! Foo(a, b)
>         assert a:a >= 0 && a:a <= 10
>         assert type(a:b) == 0, "Not a string"
>         return a:a + a:b
>     endf
> 
>     assert Foo(1, 2) == 3
>     assert Foo(1, -2) == -1
> 
> and maybe
> 
>     assert_raise Foo(1, "bla")
> 
> Similar commands are used in some other languages. The idea is that vim 
> scripts could run in some sort of debug mode where these assertions are 
> evaluated and in "normal" mode where they are ignored/stripped at 
> read/compile-time (if this is possible with the current interpreter) and 
> thus don't result in a speed penalty. That's probably not quite what you 
> meant but I think it would help (IMHO sufficiently) when writing 
> slightly non-trivial functions.

This would help a little bit, but not much.  At least it requires
executing the lines of code in various ways to detect the problems.  You
won't get any warnings when a script is loaded and functions are
defined without being executed.

You can already do quite a lot if you define your own assert function or
command for this.  The eval() function helps a lot here.  To avoid the
overhead you can comment-out the lines.  Charles Campbell does this in
his scripts.

-- 
Biting someone with your natural teeth is "simple assault," while biting
someone with your false teeth is "aggravated assault."
                [real standing law in Louisana, United States of America]

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Reply via email to