[r6rs-discuss] [Formal] Requirement to detect circular lists

From: Abdulaziz Ghuloum <aghuloum>
Date: Tue Oct 3 05:20:44 2006

On Oct 3, 2006, at 4:10 AM, Dan Muresan wrote:
>
> Seriously and objectively though, do you have a more elegant rewrite of
> those contraptions? Or do you think that allowing those contraptions
> would
> impact performance?

I have more elegant ways of writing these functions. See below.

On Oct 2, 2006, at 7:30 AM, AndrevanTonder wrote:

> Here is another useful program that would be illegal under r6rs:
>
> (define threes (list 1))
> (set-cdr! threes threes)

Why is (1 1 1 1 1 1 ...) called threes? Typo?

> (define (smallest-multiple-larger-than-10 k)
> (let ((sum 0))
> (lambda (x)
> (set! sum (+ sum x))
> (when (> sum 10)
> (k sum)))))
> (call/cc (lambda (break)
> (map (smallest-multiple-larger-than-10 break) threes)))

Did we really need to construct an infinite list, use call/cc and set!,
and force a sequential left-to-right evaluation in map just to get 11?

To get the smallest multiple of X (X != 0) that's larger than Y, you can
derive the mathematical formula:

(define smallest-multiple-of-x-larger-than-y
   (lambda (x y)
     (* x (quotient (+ (abs x) y) x))))

Right? I sure hope this qualifies as more elegant.

Aziz,,,
Received on Tue Oct 03 2006 - 05:20:46 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC