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 21:43:52 +0200
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux)

Bastien <address@hidden> writes:

> (defun string-tail (string n)
>   "Return N characters starting from the end of STRING.
> If N is larger than the length of STRING, return it."
>   (let* ((l (length string))
>        (s (- l n))
>        (d (if (> s 0) s 0)))
>     (substring string d l)))

Or simpler:

(defun string-tail (string n)
  (let ((l (length string)))
    (if (> n l)
        string
      (substring string (- l n) l))))

-- 
 Bastien



reply via email to

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