The Artima Developer Community
Sponsored Link

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

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
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
Reply to this message Reply
Advertisement
> 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
Reply to this message Reply
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
Reply to this message Reply
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
Reply to this message Reply
> (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 ]
Topic: The Adventures of a Pythonista in Schemeland/9 Previous Topic   Next Topic Topic: Is There An Equivalent of WordPress for Podcasting?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use