Ответ на сообщение «Re: Adding items'List to items'List2», 
присланное в 23:18:25 06 октября 2010, Среда.
Отправитель: Benjamin R. Haskell:

Why you are using `strlen()'? Vim neither stores string length alongside with 
string nor recognizes when `strlen' is used in boolean context, so using 
`empty()' or `()==#""' is better as it does not require to loop over the entire 
string for a null byte. 

Текст сообщения:
> On Wed, 6 Oct 2010, epanda wrote:
> > Hi,
> > 
> > I have two Lists:
> > let list1=['','','','barfoo']
> > let list2=['foo','bar','foobar']
> > 
> > I would like to obtain this List :
> > listResult = ['foo','bar','foobar','barfoo']
> > 
> > ..without looping manually by for or while around my List.
> 
> It's unclear from the description why the result is the way it is.
> Does it need to start at the first non-empty item of list1?  Or does it
> only need to know the length of list2?
> 
> If the former: (append non-empty elements of list1 to list2)
> 
> let listResult = extend(copy(list2), filter(list1, 'strlen(v:val)'))
> 
> :help extend()
> :help copy()  " only if you need to use list2 again later
> :help filter()
> :help strlen() " only needed if '0' is a valid item
> 
> If the latter: (just append anything beyond the end of list2 from list1)
> 
> if len(list1) > len(list2)
>       let listResult = extend(copy(list2), list1[len(list2):])
> endif
> 
> :help list-index, then search for 'Sublist'

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to