[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme question: convert a range
From: |
Andrew Bernard |
Subject: |
Re: Scheme question: convert a range |
Date: |
Tue, 17 Nov 2015 12:10:04 +1100 |
User-agent: |
Microsoft-MacOutlook/0.0.0.151105 |
Hi Simon,
Fellow listers have posted many answers while I was cooking up this one. All
good!
(use-modules (srfi srfi-1))
(define (range r)
(let ((start (car r))
(end (cdr r)))
(iota (+ (- end start) 1) start 1)))
That’s pure Scheme of course. Thomas Morley’s answer is more in the vernacular
of lilypond. But I just wanted to point out the list functions you would expect
to exist but don’t in R5RS are in SRFI-1. But lilypond looks after all that for
you.
The purely recursive solutions are nice, because lists are intrinsically
recursively defined, but Functional programmers tend avoid doing that and
prefer to hide the recursion behind generalised functions such as iota. A lot
easier on the brain and the maintainer. Just a matter of FP style. There are
many views!
Andrew
- Re: Scheme question: convert a range, (continued)