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 Per Bothner 04 Mar 2012 21:22 UTC

On 03/04/2012 12:41 PM, Eli Barzilay wrote:
> 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)

Indeed.  In which case the idea of two kinds of cons operator
(creating a LIST_PAIR and NON_LIST_PAIR, respectively),
is appealing - at least if we were starting from scratch.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/

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