[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme question: convert a range
From: |
Jacques Menu |
Subject: |
Re: Scheme question: convert a range |
Date: |
Tue, 17 Nov 2015 13:31:35 +0100 |
Hello folks,
I’ve tried to integrate such a pure Scheme function:
guile> (define (function arg)
(if (and (integer? (car arg)) (integer? (cdr arg)))
(iota (1+ (interval-length arg)) (car arg) 1)
)
)
guile> (function '(3 . 7))
(3 4 5 6 7)
as part of a markup, but to no avail. Here is one of my attempts:
\version "2.19.30"
#(define (function arg)
(if (and (integer? (car arg)) (integer? (cdr arg)))
(iota (1+ (interval-length arg)) (car arg) 1)
)
)
{
c'1 -\markup {
\column {
\column {
#(string-append
"commllen = " (list->sting (map #'number->string (function '(3 . 7))))
)
}
}
}
}
Thanks for your help!
JM
> Le 17 nov. 2015 à 02:10, Andrew Bernard <address@hidden> a écrit :
>
> 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
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user
- Re: Scheme question: convert a range, (continued)
- Re: Scheme question: convert a range, pls, 2015/11/16
- Re: Scheme question: convert a range, Urs Liska, 2015/11/16
- Re: Scheme question: convert a range, Thomas Morley, 2015/11/16
- Re: Scheme question: convert a range, David Nalesnik, 2015/11/16
- Re: Scheme question: convert a range, Andrew Bernard, 2015/11/16
- Re: Scheme question: convert a range,
Jacques Menu <=