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: Bastien
Subject: Re: Why (substring "abc" 0 4) does not return "abc" instead of an error?
Date: Mon, 16 Jul 2012 17:46:25 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux)

Hi Pascal,

"Pascal J. Bourguignon" <address@hidden> writes:

> First, emacs and lisp were invented long before JS, Ruby, Python, C++
> and a lot of other _currently_ popular languages and other languages
> that were popular but are now forgotten ;-)
>
> So emacs and lisp have another, older tradition.
>
> If you were to invent a new lisp (or better, just writing a new lisp
> application or library), then you could design a consistent set of
> operators with a more "modern" look-and-feel; (the "modern" style spread
> out in the 20's, it's an old style).

I'm not into a ancient vs. modern quarrel.

> Technically, one good reason to signal an error instead of silently
> clipping the arguments is that exactly it detects an error.  Since lisp
> is a dynamically typed language, the type of the objects is controlled
> by what the functions accept.  If you (or your compiler) formalize the
> types accepted by the functions, then type inference can be implemented
> and the program can be (for the most parts) type checked statically
> too.  But even without static type checking with type inference, it's
> useful to set up such constraints and signal such errors.
>
> You could also accept non integer values for start and end.  Obviously
> any real would be good too (but will you truncate or round?).  What
> about complex numbers (if there were complexes in emacs lisp)?  Or just
> what about other objects, what if we pass a string:
>
>     (mysubstring str "42" "end-2")

I'm not interested in doing crazy stuff, I'm interested in

(substring "abc" 0 4 t)
  => "abc"

where `t' is the value of an option third NOERROR argument.

(substring "abc" 0 4) would still throw an error, so that
the change does not break any code.

> We can imagine several useful behaviors.  But would a library/language
> that would accept any type of arguments and values for any parameter be
> really that useful?  Have a look at PHP and similar languages that
> coerce everything everywhere.  I'm not sure that entirely helps writing
> clean and bug-free programs.

:)  But please, this is not a language issue, just a suggestion
on a useful extension to `substring'.

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

I'm not really interested in other programmers, just in what I could
write in Elisp.

-- 
 Bastien



reply via email to

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