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








_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to