Re: [Scheme-reports] Query - Pairs and Lists Per Bothner (04 Mar 2012 20:14 UTC)
Re: [Scheme-reports] Query - Pairs and Lists Eli Barzilay (04 Mar 2012 20:42 UTC)
Re: [Scheme-reports] Query - Pairs and Lists Per Bothner (04 Mar 2012 21:26 UTC)

Re: [Scheme-reports] Query - Pairs and Lists Eli Barzilay 04 Mar 2012 20:41 UTC

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@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports