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

Re: [Scheme-reports] Query - Pairs and Lists



30 minutes ago, Per Bothner wrote:
> 
> You could have a bit or separate typecode for non-list cons
> cells - for example LIST_PAIR vs NON_LIST_PAIR.  Cons creates
> a LIST_PAIR if the cdr is '() or a LIST_PAIR, and creates a
> NON_LIST_PAIR otherwise.  set-cdr! checks the new cdr if it
> is a NON_LIST_PAIR *or* if the set-cdr! would create a cycle.
> 
> In that case checking for a pure list is O(1).  Only set-cdr!
> becomes order-of-magnitude slower, but it's not a function
> we want to encourage use of anyway.

`set-cdr!' is much worse:

  (define foo (cons 1 '()))
  (define bar (cons 1 foo))
  (list? bar)
  (set-cdr! foo 1)
  (list? bar)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports