maxi gas
Posts: 1
Nickname: maxigas
Registered: Nov, 2008
|
|
Re: The Adventures of a Pythonista in Schemeland/7
|
Posted: Nov 3, 2008 12:42 PM
|
|
i wrote range in a more basic and i think more idiomatic functional style, please check it out and tell me if it's correct. the second function could be omitted with some more work, it is just a workaround for the right argument order.
(define (ranger n (n0 0) (s 1)) (let* ((*= (if (<= s 0) > <)) (i (+ n0 s))) (if (*= i (+ n s)) (cons n0 (ranger n i s)) '())))
(define (range (arg1 'nil) (arg2 'nil) (arg3 'nil)) (if (eq? arg2 'nil) (ranger arg1) ;; (ranger n (n0 0) (s 1)) (if (eq? arg3 'nil) (ranger arg2 arg1) ;; (ranger n n0 (s 1)) (ranger arg2 arg1 arg3)))) ;; (ranger n n0 s)
|
|