Re: [Gauche-devel] seq-null?, seq-empty?, collection-null? or collection-empty?
R7RS Scheme scripting engine
Status: Beta
Brought to you by:
shirok
|
From: Shiro K. <sh...@la...> - 2010-07-02 06:03:32
|
From: Jens Thiele <ka...@be...> Subject: Re: [Gauche-devel] seq-null?, seq-empty?, collection-null? or collection-empty? Date: Fri, 25 Jun 2010 19:36:01 +0200 > 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). Still it would be slower than the implicit iterator constructs such as fold and for-each, which are recommended over this first/rest idiom. > Regarding collections-empty? I am not sure about the use cases, though i > remember at least once looking for hash-table-empty? Unfortunately I > can't remember in what context. > > jens > > PS: just as side-note: i also would prefer -empty? over -null? and I > think it is a bit unfortunate that there is such a mix: > > from the info index: > 9 matches for "null\?\|empty\?" in buffer: *info* > 205:* attlist-null?: SSAX data types. (line 142) > 1223:* hook-empty?: Hooks. (line 39) > 1934:* null?: List predicates. (line 10) > 2149:* queue-empty?: Queue. (line 25) > 2205:* rbtree-empty?: Red black tree. (line 42) > 2929:* stream-null?: Stream library. (line 22) > 3060:* string-null?: SRFI-13 String predicates. > 3632:* tree-map-empty?: Treemaps. (line 31) > 3977:* vector-empty?: Vector library. (line 34) Yeah I do prefer 'empty?', too. The 'null?' came from existing standard and/or library. --shiro |