[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: request for a new function, say, `sequence'

From: Kenichi Handa
Subject: Re: request for a new function, say, `sequence'
Date: Wed, 26 Mar 2003 09:18:58 +0900 (JST)
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.2.92 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI)

In article <address@hidden>, "Satyaki Das" <address@hidden> writes:
>>  >>  (defun dev-charseq (from &optional to)
>>  >>    (if (null to) (setq to from))
>>  >>    (mapcar (function (lambda (x) (indian-glyph-char x 'devanagari)))
>>  >>            (devanagari-range from to)))
>>  > (defun dev-charseq (lower &optional upper)
>>  >   (if (null upper) (setq upper lower))
>>  >   (loop for x from lower to upper
>>  >         collect (indian-glyph-char x 'devanagiri)))
>>  It's not the point.  How to use a list returned by `range'
>>  (or `sequence') and how to make such a list is a different
>>  thing.

> I am trying to show that by using existing macros and functions we
> can express the algorithms as clearly and succintly as with the
> new `range'.

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.

> 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.

The defvar part can be written as:

(defvar dev-consonants
  (append (loop for x from (decode-char 'ucs #x0915) to (decode-char 'ucs 
                collect x)
          (loop for x from (decode-char 'ucs #x0958) to (decode-char 'ucs 
                collect x)))

but using `range' is much more handy and easier to read.

> 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.  And, `range' surely
makes writing code easier and makes the code simpler as well
as dolist, dotimes, while, and etc. do.

> I think calling the new function `sequence' or `range' is a
> mistake. Lisp already has the functions `string' and `vector'
> which are data type constructors. Either of the suggested names
> sound like a new data type (in fact there is already a data type
> called sequence and a predicate sequencep) and so inconsistent
> with the current naming conventions.

I see your point.

> 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

Ken'ichi HANDA

reply via email to

[Prev in Thread] Current Thread [Next in Thread]