Hi Simon,
On Sun, Nov 15, 2015 at 12:53 PM, Simon Albrecht <[email protected]>
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 ((dir (if (> (car arg) (cdr arg)) -1 1)))
(let loop ((elt (car arg)) (result '()))
(if (= elt (+ dir (cdr arg)))
(reverse result)
(loop (+ dir elt) (cons elt result))))))
HTH,
David
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user