Re: Interval list



* "Geoffrey Summerhayes" <1166641110.485574.241490@xxxxxxxxxxxxxxxxxxxxxx> :
|
| The general idea is for the new interval to overwrite the entries
| in the current list.
|
| The list is sorted on 'from' consisting of (from attributes)
| with the next entry in the list indicating the end of the interval.
| Somewhat akin to run-length encoding.
|
| Precondition (start<end)
|
| Works AFAICT, but is there a better way?

Finally got around to using LOOP to figure out a worse way :)

(defun insert-interval (list start end new-attribs)
(loop with x ;X is non nil if we are inside the new interval
for (a b . rest) on list
for (from . attribs) = a and (to) = b

if (<= from start to)
do (assert (null x)) (setq x t)
and if (< from start) collect a end
and collect (cons start new-attribs)
else unless x collect a

if (<= from end to)
do (assert x)
and if (< end to) collect (cons end attribs) and do (setq x nil) end

if (endp rest) unless x collect b else collect (list end)
while rest))


[lightly tested. Does it meet your spec?]
--
Madhu
.



Relevant Pages

  • Re: Interval list
    ... Finally got around to using LOOP to figure out a worse way:) ... do (assert (null x)) (setq x t) ... and collect (cons start new-attribs) ...
    (comp.lang.lisp)
  • Re: dot meaning
    ... (setq xx (cons c nil)) ... (reverse xx) ...
    (comp.lang.lisp)
  • Re: better way to enumerate
    ... (defun enumerate (start end) ... (setq x nil) ... (setq x (cons i x)) ...
    (comp.lang.lisp)
  • Re: A style question
    ... 0;; throwaway value to avoid forever testing if nil ... T if the last input char was read before ... (SETQ ORIG-PT (COPY-BP BP)) ... (BADFUNCHK (CAAR FORM) ...
    (comp.lang.lisp)
  • how to speed up ecb ? why my emacs is so slowe?
    ... I use emacs 21.2.1, but it is so slowely when I programming with c++ ... (let ((b nil) ... (setq to-string (read-from-minibuffer ...
    (comp.emacs)