[vim7 scripting] split without error ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[vim7 scripting] split without error ?

marc chantreux-2
Hi all,

this works :

let x='this is'
let [ y , z ] = split(x,' ')

but if you split with something that does not exists :

let x='this is'
let [ y , z ] = split(x,':')

it comes with an error message. I thought that the final result
will be :

x=='this:is'
y==''

but it's not ... would it be the same in the final vim7 ?

regards
mc
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [vim7 scripting] split without error ?

marc chantreux-2
mea culpa !

> shouldn't it be
>
>   x=='this is'
>   y==''
>
> ?
> split() should only split into elements,
> not changing individual elements.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [vim7 scripting] split without error ?

Bram Moolenaar
In reply to this post by marc chantreux-2

Marc Chantreus wrote:

[Note: discussions about Vim 7 should go to the vim-dev list, this is
about development]

> this works :
>
> let x='this is'
> let [ y , z ] = split(x,' ')
>
> but if you split with something that does not exists :
>
> let x='this is'
> let [ y , z ] = split(x,':')
>
> it comes with an error message. I thought that the final result
> will be :
>
> x=='this:is'

I assume you meant x=='this is' here.

> y==''
>
> but it's not ... would it be the same in the final vim7 ?

Unpacking a list to variables requires that the list has enough items.
If it doesn't then you get an error message.

Obviously you can first check that the list has sufficient length or use
exception handling to catch the error.

More general: If you are not sure how long a list is then you shouldn't
unpack it to variables.

--
A fool must search for a greater fool to find admiration.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [vim7 scripting] split without error ?

marc chantreux-2
> [Note: discussions about Vim 7 should go to the vim-dev list, this is
> about development]

i apologize. thanks to all
mc
Loading...