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: Simon Albrecht
Subject: Re: Scheme question: convert a range
Date: Mon, 16 Nov 2015 23:36:37 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

On 16.11.2015 23:30, pls wrote:
Simon Albrecht <address@hidden> writes:
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?
You mean something like this?

#+BEGIN_SRC scheme :results output
(define pair (cons 3 7))
(define (range first last)
   (if (>= first (+ last 1))
     '()
     (cons first (range (+ first 1) last))))
(display (range (car pair) (cdr pair)))
#+END_SRC

#+RESULTS:
: (3 4 5 6 7)

Yeah, that’s the recursion way to do it – and without any SRFI.

Thank you,
Simon



reply via email to

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