Deutsch   English   Français   Italiano  
<v2uqqu$3b7ev$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <No_spamming@noWhere_7073.org>
Newsgroups: comp.lang.scheme
Subject: Re: (Mastermind) puzzle (with 3 digits) -- Elegant (readable) code Sought
Date: Sun, 26 May 2024 08:11:11 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <v2uqqu$3b7ev$1@dont-email.me>
References: <urh3vu$2br0h$1@dont-email.me> <urjq6t$31cu6$1@dont-email.me> <87edcxegiu.fsf@nightsong.com> <87zfvi5ipv.fsf@eder.anydns.info>
Injection-Date: Sun, 26 May 2024 10:11:11 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8a141804df277ee017ff79d46698b570";
	logging-data="3513823"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX180DDaE9RGkcE9UWid9Vhd+"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:o1rN5F3gDb2YKg/b2ZzazZIC3ks=
Bytes: 1526

On 3/1/2024, Andreas Eder wrote:

> I would write it without the second define using a named let:
> 
> (define (range n)
>   (let go ((n n) (a '()))
>     (if (< n 0)
>         a
>         (go (1- n) (cons n a)))))

Looks good.

Using "do":

(define (range n)
  (do ((i n (- i 1))
       (a '() (cons i a)))
    ((< i 0) a)))


Using "unfold-right" in Gauche Scheme:

(use srfi-1)

Gauche doesn't have "1-".

(define (1- n) (- n 1))

(define (range n) (unfold-right negative? values 1- n)) 

(range 9)
  ===>
(0 1 2 3 4 5 6 7 8 9)