[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: request for a new function, say, `sequence'
From: |
Satyaki Das |
Subject: |
Re: request for a new function, say, `sequence' |
Date: |
Tue, 25 Mar 2003 17:44:02 -0800 |
Kenichi Handa <address@hidden> writes:
> In your example code, you united the implementaion of range
> and usage of the returned list. In such a way, of course,
> it is natural that we can make a function that uses `range'
> more concise and efficient.
This should be done only if it doesn't affect the readability and
simplicity of the code.
> > Do you have a counter-example to this?
>
> How about the code something like this.
>
> (defvar dev-consonants
> (append (range (decode-char 'ucs #x0915) (decode-char 'ucs #x0939))
> (range (decode-char 'ucs #x0958) (decode-char 'ucs #x095F))))
>
> (defun dev-looking-at-syllable ()
> (and (memq (following-char) dev-consonants)
> (looking-at dev-syllable-pattern)))
>
> The first `memq' is to avoid the heavy `looking-at' in an
> unnecessary case.
This seems like a reasonable usage scenario for `range'. However
since you are doing this for efficiency reasons, isn't it more
efficient to compare with <= than to use memq to to compare it
with 45 separate integers?
> The defvar part can be written as:
>
> (defvar dev-consonants
> (append (loop for x from (decode-char 'ucs #x0915) to (decode-char 'ucs
> #x0939)
> collect x)
> (loop for x from (decode-char 'ucs #x0958) to (decode-char 'ucs
> #x095F)
> collect x)))
Or you could do it in one loop and collect with a when. But I
agree that this could easily get quite hairy if there are lots of
ranges to consider.
> but using `range' is much more handy and easier to read.
Agreed.
> > IMO, a new builtin function is needed if and only if it makes
> > writing code easier or makes it simpler.
>
> I'm not requesting a builtin function.
Sorry about the bad terminology. I meant a library function.
> And, `range' surely
> makes writing code easier and makes the code simpler as well
> as dolist, dotimes, while, and etc. do.
Agreed. But I would be careful in its use, since it can
potentially cons a lot (if used inside of a loop for instance).
> > So I suggest that a more descriptive name be chosen -- for
> > instance something like `make-sequence-of-numbers'.
>
> I don't insist on having TYPE argument, always returning a
> list is ok. So, for instance, make-number-list, is also
> acceptable.
Yes, this seems reasonable if you don't want the vectors and
string types.
Satyaki
- Re: request for a new function, say, `sequence', (continued)
- Re: request for a new function, say, `sequence', Satyaki Das, 2003/03/24
- Re: request for a new function, say, `sequence', Kenichi Handa, 2003/03/24
- Re: request for a new function, say, `sequence', Satyaki Das, 2003/03/24
- Re: request for a new function, say, `sequence', Kenichi Handa, 2003/03/24
- Re: request for a new function, say, `sequence', Satyaki Das, 2003/03/25
- Re: request for a new function, say, `sequence', Kenichi Handa, 2003/03/25
- Re: request for a new function, say, `sequence', Satyaki Das, 2003/03/25
- Re: request for a new function, say, `sequence', Kenichi Handa, 2003/03/25
- Re: request for a new function, say, `sequence',
Satyaki Das <=
- Re: request for a new function, say, `sequence', Luc Teirlinck, 2003/03/25
- Re: request for a new function, say, `sequence', Edward O'Connor, 2003/03/26
- Re: request for a new function, say, `sequence', Thien-Thi Nguyen, 2003/03/26
- Re: request for a new function, say, `sequence', Kenichi Handa, 2003/03/26
- Re: request for a new function, say, `sequence', Richard Stallman, 2003/03/26
- Re: request for a new function, say, `sequence', Stefan Monnier, 2003/03/25
- Re: request for a new function, say, `sequence', Kenichi Handa, 2003/03/25
- Re: request for a new function, say, `sequence', Miles Bader, 2003/03/25
- Re: request for a new function, say, `sequence', Luc Teirlinck, 2003/03/25
- Re: request for a new function, say, `sequence', Miles Bader, 2003/03/25