emacs-devel
[Top][All Lists]
Advanced

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

Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?


From: Pascal J. Bourguignon
Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?
Date: Mon, 16 Jul 2012 17:19:11 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Lennart Borgman <address@hidden> writes:

> On Mon, Jul 16, 2012 at 5:00 PM, Pascal J. Bourguignon
> <address@hidden> wrote:
>> Bastien <address@hidden> writes:
>>
>>> Hi Pascal,
>>>
>>> "Pascal J. Bourguignon" <address@hidden> writes:
>>>
>>>> (defun mysubstring (str start end)
>>>>   (substring str (max start 0)
>>>>                  (if end
>>>>                      (min end (length str))
>>>>                      (length str))))
>>>>
>>>> and use (mysubstring "abc" 0 4) --> "abc"
>>>> instead of substring.
> ...
>> Technically, one good reason to signal an error instead of silently
>> clipping the arguments is that exactly it detects an error.  Since lisp
>
> It is a good reason not to change the old behaviour. However
> introducing a new function in Emacs like the one you suggest would
> save time for all those who need this function. (It is hard for me
> even to come up with an example where I do not want this instead of
> the old one.)

You cut out the relevant part:

Well, lisp has this great advantage over other programming languages
that it is really very accomodating to your specific needs.

Look how emacs lisp provides a cl package with macros and functions
similar to those provided in Common Lisp.

Similarly, nothing prevents you to write an emacs lisp package with
macros and functions having a Javascript, or Ruby or Python or C++
look-and-feel, that would help programmers coming from those languages
to more easily adapt and feel more comfortable with emacs lisp, just
like cl helps me, a Common Lisp programmer, be more comfortable with
emacs lisp.

(require 'js)
(js-substring "abc" "0" 1000) --> "abc" ; and let JavaScript 
                                        ; programmers be happy!

(just document those functions and macros well, so that other emacs lisp
programmers can still understand what's happening).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.




reply via email to

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