[racket-dev] srfi41 for racket
Is it a good idea to adapt PLT-Scheme implementation of srfi41 to Racket?
In principle, this is trivial.
However, when I adapted srfi41 for PLT-Scheme, Eli Barzilay advised me not to double the code for promises.
I did not follow his advice.
I now intend to follow his advice.
This has consequences that at first sight may seem undesirable. For example it would no longer be possible to distinguish a stream from a plain promise. It is not possible to provide a reliable predicate for streams. This also holds for the standard implementation. For example:
#lang racket
(require srfi/41)
(define improper-stream ((stream-lambda () 1)))
(stream? improper-stream) ; -> #t
(stream-null? improper-stream) ; -> error
(stream-pair? improper-stream) ; -> error
Hence the claim that a stream is either stream-null or a stream-pair is not fulfilled.
The document of srfi41 also claims that stream-null is unique. It is not:
(define another-stream-null (stream-filter number? (stream 'a 'b 's)))
(equal? stream-null another-stream-null) ;-> #f, yet:
(stream-null? another-stream-null) ; -> #t
In the docs for a new implementation I would like to make a distinction between abstract streams (with abstract predicates but without true (complete) predicates) and concrete streams. A concrete stream would be:
concrete-stream ::= null
concrete-stream ::= promise (any promise, and forcing may yield anything)
concrete-stream ::= pair whose cdr is a concrete stream (and the car probably, but not necessarily a promise)
When using stream functions on concrete streams that do not satisfy the requirements of abstract streams, errors will be reported (just like in th standard implementation) It is possible to make a predicate for concrete-streams, but it seems rather useless to me.
In srfi41 attempts have been made to conceal the internally defined syntax stream-lazy. Yet stream-lazy can easily be exposed, as in:
(define-syntax my-stream-lazy
(syntax-rules ()
((_ expr) ((stream-lambda () expr)))))
While it is possible to maintain almost all provided syntaxes and procedures of PLT's srfi41, some changes would be noticeable:
1:
(stream-lambda formals definition ... body ...1)
can also be written as
(lambda formals (lazy (let () definition ... body ...)))
To me this seems an improvement.
2:
stream-null would just be a synonym for null. There is no reason to wrap it in a promise.
3:
A stream-pair could be a promise that yieds a pair, but it could also be a pair whose cdr is a promise. There is no reason to wrap a pair of promises in another promise.
Your comments/critics/advises are welcome.
Thanks, Jos
Hartelijke groet,
Jos Koot
Carrer d'Argentona 17 baixos
ES 08302 MATARO
España/Spanje /Spain
+34937412360
+34679944599
((((λ(x)(((((((x x)x)x)x)x)x)x))
(λ(x)(λ(y)(x(x y)))))
(λ(x)(cons'greeting x)))
'()) ; That's a lot of greetings.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20100719/b52fafe9/attachment.html>