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

Dmitry Gutov <address@hidden> writes:

>> Ditto for Ruby: String::slice also gets an index and a length, not two
>> indices.
>
> True, but it also accepts range as parameter. Neither form
> raises error:
>
> irb(main):007:0> "abc".slice(1, 10)
> => "bc"
> irb(main):008:0> "abc".slice(0..1)
> => "ab"

I just wanted to point out that the (int, int) version specifies it
second argument to be no index.

But, yes, the version that gets a range argument with the meaning of
taking the range's first and last value as start/end indices invalidates
my argument that indexes are usually strict quite a bit.

> Same thing with JavaScript:

Yes, but JS explicitly says that both arguments are indexes, just like
Elisp's substring.  So JS's substring function is really different while
C++ and Ruby are not really comparable because their arguments have a
different meaning.

But JS is different (unexpected) in many other ways, too:

  https://www.destroyallsoftware.com/talks/wat/

> So far I don't see another language, aside from Emacs Lisp, that
> interprets negative value of second index as "count from the end", yet
> raises an "out of range" error if that value is too big.

I don't, too.

Bye,
Tassilo



reply via email to

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