On Mar 24 2013, Moritz Heidkamp wrote:

Peter Bex <peter....@xs4all.nl> writes:
As I understand it, strict-types declares variables to never change
their types.  So once it's looked at the initial declaration of the
variable, it assigns it a type of null, and then it can never change.

    -strict-types assume variable do not change their type

The set! would change the type from NULL to LIST (or maybe PAIR),
invalidating that assumption.

Ah, very good, that should explain it. I somehow had it remembered as
"assume functions are always called with correctly typed arguments" or
something. Should have RTFM :-)

I guess the problem is something different.

Though in a way the explanation is correct.  -strict-types assumes
'() to be null from the initialization.  Short of a way to declare
the type of foobar as (list-of <whatever>) this fails when it's used
as the initial and correct value of type (list-of <whatever>) with
zero length.

What the optimizer should do is to see into the doloop and notice
the ambiguous type null being refined to a list.


Find attached two more variants.  strcttps2.scm, which convinces
chicken to do the right thing, ans strcttps2.scm, which fails
the other way around.


Best

/Jörg





......
(module
 foo
 (bar)
 (import scheme chicken)

 (define (bar . args)
   (let ((foobar (list 1)))
     (set! foobar (cdr foobar))
     (do ((rest args (cddr rest)))
	 ((null? rest))
       (if (null? (cdr rest))
	   (error (car rest)))
       (case (car rest)
	 ((#:foobar)
	  (set! foobar (cons (cadr rest) foobar)))))
     (if (null? foobar)
	      'gaga
	      foobar)))

)

(import foo)

(display (bar #:foobar 42))
(newline)
(module
 foo
 (bar)
 (import scheme chicken)

 (define (bar . args)
   (let ((foobar (list 1)))
     (set! foobar (cdr foobar))
     (do ((rest args (cddr rest)))
	 ((null? rest)
	  (if (null? foobar)
	      'gaga
	      foobar))
       (if (null? (cdr rest))
	   (error (car rest)))
       (case (car rest)
	 ((#:foobar)
	  (set! foobar (cons (cadr rest) foobar)))))))

)

(import foo)

(display (bar))
(newline)
_______________________________________________
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to