Dr. Scheme doesn't have functins in MIT Scheme Reference

Started by
3 comments, last by Anonymous P 17 years, 2 months ago
I was all excited about the nice list-manipulation functions that the MIT Scheme Reference told me about. Alas, my poor compiler, Dr. Scheme, does not have such functions. In particular, I was wishing to use find-matching-item and delete-matching-item, but I had no such luck. As it turns out, there are no such functions in the PLT implementation of Scheme. What is this? Two versions of the same language - even the same dialect - have wildly different functions available. Where is the standard library? The PLT Scheme is rather lacking in its built-in ones. However, I do not wish to switch to a different IDE at the moment (are any actually any good that are vaguely user-friendly other than Dr. Scheme?). Is there any way that I could get the MIT implementation of Scheme to be used in PLT Scheme? That would be excellent! Perhaps a techpack or a new language would do the trick? Thanks in advanced.
Advertisement
Quote:
As it turns out, there are no such functions in the PLT implementation of Scheme. What is this? Two versions of the same language - even the same dialect - have wildly different functions available. Where is the standard library? The PLT Scheme is rather lacking in its built-in ones.


The PLT library is rather impressive, in my opinion. It is the R5RS standard which is intentionally slim.

The MIT functions which you reference are, in any case, trivial to implement (and good practice). For example:

(define (find-matching-item p? alist)  (cond ((null? alist)         #f)        ((p? (car alist))         (car alist))        (else         (find-matching-item p? (cdr alist)))))(define (delete-matching-items p? alist)  (define (helper accum alist)    (cond ((null? alist)           (reverse accum))          ((p? (car alist))           (helper accum (cdr alist)))          (else           (helper (cons (car alist) accum) (cdr alist)))))  (helper (list) alist))


They are NOT, however, good library functions, in my humble opinion.

The first one is ambiguous: what happens when you want to find the value #f in a list? #f and nil are distinct in scheme, prescisely to avoid a host of ambiguities in lisp (lisp treats nil and false as the same constant, resulting in similar ambiguities).

The way to resolve this ambiguity is to return multiple values on the stack (something standard R5RS can't do IIRC, but PLT scheme can) or a data structure (eg, a pair where the first value denotes failure or success and the second value is the value you seek in the list).

The second is better expressed using the (idiomatic across FP languages) filter function.
The R5RS standard. Quite minimalistic as mentioned above.

The PLT Scheme reference, which is not that lacking.
Quote:Original post by Anonymous P
The way to resolve this ambiguity is to return multiple values on the stack (something standard R5RS can't do IIRC, but PLT scheme can)...


(values v1 ... vn)

Of course, if you want to handle variant continuations e.g. success/1 | failure/0 you'd need to use an ADT.
Doh. My bad, sorry. I clearly didn't recall correctly.

This topic is closed to new replies.

Advertisement