lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme question: convert a range


From: David Nalesnik
Subject: Re: Scheme question: convert a range
Date: Mon, 16 Nov 2015 17:33:28 -0600



On Mon, Nov 16, 2015 at 5:24 PM, David Nalesnik <address@hidden> wrote:
Hi Simon,

On Sun, Nov 15, 2015 at 12:53 PM, Simon Albrecht <address@hidden> wrote:
Hello,

The subject certainly seems cryptic – it’s difficult to summarize, but an example will make it clear immediately.
I want to write a scheme procedure, which takes a pair like #'(3 . 7) and returns a list with all the numbers in the range: #'(3 4 5 6 7)
How is this done most easily?


Well, if the numbers are ascending you could do something like:

(define (expand-interval arg)
   (iota (- (1+ (cdr arg)) (car arg)) (car arg)))

(display (expand-interval '(3 . 7)))

If not, something like this would work:

(define (expand-interval arg)
   (let ((step (if (> (car arg) (cdr arg)) -1 1)))
     (iota (1+ (abs (- (cdr arg) (car arg)))) (car arg) step)))

--David


reply via email to

[Prev in Thread] Current Thread [Next in Thread]