Re: [Gauche-devel] seq-null?, seq-empty?, collection-null? or collection-empty?
R7RS Scheme scripting engine
Status: Beta
Brought to you by:
shirok
|
From: Jens T. <ka...@be...> - 2010-07-02 07:50:17
|
Shiro Kawai <sh...@la...> writes: > From: Jens Thiele <ka...@be...> > >> I first was looking for seq-empty? and seq-null? Only, after I didn't >> find it I thought: "hmm maybe look for collection-empty/null?" >> >> My usage often would be to replace null? with seq-empty/null?, using >> (ref <> 0) as car replacement and (subseq <> 1) as cdr replacement. > > Although symmetry to lists is nice, you usually want to avoid > that pattern, since subseq may take O(n) time and/or space; > you'll never know. > > I tend to think it would be better to provide a wrapper; > that is, > > (first <sequence>) -> element > (rest <sequence>) -> <wrapped-sequence> > > where <wrapped-sequence> wraps any concrete sequence type. > For a vector, it can hold the original vector and an index, > hence it's O(1). ups - i somehow thought subseq does that in some way > Still it would be slower than the implicit > iterator constructs such as fold and for-each, which are > recommended over this first/rest idiom. i see - thanks! ... leaving to grep for subseq ... ;-) |