This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: srfi-1 on long lists?


Marco VEZZOLI wrote:

Maybe we could do a better job by implementing some code in Java?

That shouldn't be needed. This seems to work:


(define (list-copy (lis :: <list>)) :: <list>
  (let recur ((lis :: <list> lis)
	      (result :: <list>  '())
	      (prev :: <list>  '()))
    (if (pair? lis)
	(let ((p :: <pair> (cons (car lis) '()))
	      (next :: <list> (cdr lis)))
	  (if (null? prev)
	      (recur next p p)
	      (begin
		(set-cdr! prev p)
		(recur next result p))))
	result)))

Unfortunately, Kawa doesn't manage to recognize car and cdr
at compile-time, thus generating sub-optimimal code,
probably because those are defined using define-procedure.
That ought to be fixed.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]