Weblogs Forum
The Adventures of a Pythonista in Schemeland/7

18 replies on 2 pages. Most recent reply: Oct 20, 2008 10:17 PM by Michele Simionato

 Previous Topic Next Topic
 Flat View: This topic has 18 replies on 2 pages [ « | 1 2 ]
 Grant Rettke Posts: 23 Nickname: grettke Registered: Nov, 2008
Re: The Adventures of a Pythonista in Schemeland/7 Posted: Nov 2, 2008 8:07 AM
> It doesn't please me to point this out. I'd much rather
> someone tell me that Lisp makes it possible to blur the
> separation safely (and have it be true, of course.)

You could say the same thing about any language.

Lisp doesn't magically make all of your problems go away, otherwise there wouldn't be any work for the programmer! :)

 Grant Rettke Posts: 23 Nickname: grettke Registered: Nov, 2008
Re: The Adventures of a Pythonista in Schemeland/7 Posted: Nov 2, 2008 8:21 AM
Here are more descriptive formal arguments for the lambda-clauses:
`(stop-on)(start-on stop-on)(start-on stop-on increment)`

Here is the non-tail-recursive version, the only change is in the named let 'loop' (almost identical of course)
`(let loop ((n start-on)) (if (check n stop-on) '() (cons n (loop (+ n increment)))))`

 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)

 Michele Simionato Posts: 222 Nickname: micheles Registered: Jun, 2008
Re: The Adventures of a Pythonista in Schemeland/7 Posted: Nov 3, 2008 8:07 PM
> (define (ranger n (n0 0) (s 1))

This is not valid Scheme syntax, which implementations are you using?

 Flat View: This topic has 18 replies on 2 pages [ « | 1  2 ]
 Previous Topic Next Topic