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

Re: gEDA: gnetlist ERROR: Stack overflow



Stefan Petersen <spe@stacken.kth.se> writes:

   (define (pads:display-connections nets)
     (let ((k ""))
       (for-each (lambda (in-string)
		   (set! k (string-append k in-string)))
		 (map (lambda (net)
			(string-append " " (car net) "." (car (cdr net))))
		      nets))
       (string-append k "\n")))

the other (standard) approach to this type of problem is to create a tree of
strings, then flatten on output, avoiding `string-append' (and the non-linear
big-O its usage introduces) altogether.  all netlisting is flattening, in
essence.

a quick untested rewrite:

 (define (pads:connections-data nets)
   (list (map (lambda (net)
                (list " " (car net) "." (car (cdr net))))
              nets)
         "\n"))
 
 (define (flatten tree . out)
   (let ((out (if (null? out) display (car out))))
     (letrec ((walk (lambda (x)
                      (cond ((string? x) (out x))
                            ((list? x) (for-each walk x))
                            (else (error "bad type:" x))))))
       (walk tree))))
   
 (define (pads:display-connections nets)
   (flatten (pads:connections-data nets)))


hth,
thi