On 21/07/09 19:25, Ben Fritz wrote:
>
>
>
> On Jul 21, 12:01 pm, Ben Fritz<fritzophre...@gmail.com>  wrote:
>>
>> I need to stop trying to multitask before I make myself look like more
>> of an idiot.
>>
>> [snip]
>>
>> Zero evaluates as false and a
>> non-empty string evaluates as true, so just check the value before you
>> use it.
>>
>> You'll need an additional "return 0" within your catch, but the rest
>> of the function should "just work".
>
> Ugh, so much for the "not looking like an idiot".
>
> This would work, except:
>
> a) In Vim, unlike Perl, apparently non-null strings DON'T evaluate to
> true (is this documented anywhere? I can't find it if it is!)
> b) you weren't returning a string anyway.

A string which begins with a decimal number, or with 0 then an octal 
number, or with 0x or 0X then a hex number, evaluates as that number. 
Any other string evaluates as zero.

When evaluating as a Boolean, it is first converted to a Number. Then 
zero counts as FALSE and anything else counts as TRUE.

This is documented about one page below ":help variables".

>
> Returning 0 should still work, but check that type(project) == type
> ({}) for your sentinal, rather than checking for true/false of the
> value itself.

This checks for a Dictionary. To test for a string, use type('').

(Using a Dictionary as if it were a Number doesn't work, it throws an 
exception. Using a String as a Number does work, as above.)


Best regards,
Tony.
-- 
Oh, I don't blame Congress.  If I had $600 billion at my disposal, I'd
be irresponsible, too.
                -- Lichty & Wagner

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to