chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] continuation example: different behavior from other


From: Ricardo Gabriel Herdt
Subject: Re: [Chicken-users] continuation example: different behavior from other Scheme implementations
Date: Sat, 19 Oct 2019 15:29:45 +0200
User-agent: Posteo Webmail

Am 19.10.2019 14:18 schrieb address@hidden:
The exact behaviour of re-
entering a continuation captured during execution of "map" is, I think,
dependent on implementation details (there may be a note about this in the
SRFI-1 document or R7RS, I can't remember right now).

Many thanks for the fast and detailed answer.

I found this in R5RS/R7RS/SRFI-1: "The dynamic order in which proc is applied to the elements of the lists is unspecified". Indeed redefining map in all implementations as

(define (map f l)
  (cond ((null? l) '())
(else (cons (f (car l))
    (map f (cdr l))))))

make all behave the same way (I know this is not a complete map implementation, is just an example).

R7RS adds this: "If multiple returns occur from map, the values returned by earlier returns are not mutated". Does this mean returns through continuation calls?

I was curious how CHICKEN implements map and found the following in library.scm:

(define (##sys#map p lst0)
  (let loop ((lst lst0))
    (cond ((eq? lst '()) lst)
  ((pair? lst)
   (cons (p (##sys#slot lst 0)) (loop (##sys#slot lst 1))) )
  (else (##sys#error-not-a-proper-list lst0 'map)) ) ))

...
(set! scheme#map
    (lambda (fn lst1 . lsts)
      (if (null? lsts)
  (##sys#map fn lst1)
  (let loop ((all (cons lst1 lsts)))
    (let ((first (##sys#slot all 0)))
      (cond ((pair? first)
     (cons (apply fn (mapsafe (lambda (x) (car x)) all #t 'map))
           (loop (mapsafe (lambda (x) (cdr x)) all #t 'map)) ) )
    (else (check (##core#inline "C_i_cdr" all) #t 'map)
          '() ) ) ) ) ) ) )
...

So still I don't get why calling any stored continuation appends the result to the previously computed "numbers", but if the standard allows this behavior it's not a big deal.

Regards,

Ricardo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]