emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Add new lisp function length= with bytecode support


From: Richard Stallman
Subject: Re: [PATCH] Add new lisp function length= with bytecode support
Date: Mon, 06 Mar 2017 13:00:32 -0500

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > I would agree; having length= makes it seem strange not to have the others.

Why add length= as a primitive?  Why is it important enough to justify that?

Unless you're concerned about improper lists, 
length= can be implemented as follows:

(defun length= (list n)
  (if (= n 0)
      (null list)
    (let ((tail (nthcdr (1- n) list)))
      (and (consp tail)
           (not (cdr tail))))))

This will run almost as fast as a primitive, for long lists,
since nthcdr does most of the work.

If we want to make it safe for improper lists,
it would be better to add nthcdr-safe as a primitive.
That would make it easy to implement length= or length< or length>
or length>= if you want them.

-- 
Dr Richard Stallman
President, Free Software Foundation (gnu.org, fsf.org)
Internet Hall-of-Famer (internethalloffame.org)
Skype: No way! See stallman.org/skype.html.




reply via email to

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