Re: Scheme question: convert a range

2015-11-17 Thread Jacques Menu
Hello David N. and Andrew,

Great, all your suggestions are of some use to me.

Thanks!

JM


> Le 17 nov. 2015 à 14:19, Andrew Bernard  a écrit :
> 
> Hi Jacques,
> 
> You could base a solution on this approach:
> 
>  c'1 -\markup {
>   \column {
>   \column {
>   #(string-append
>   "commllen = "
>   (string-concatenate (map number->string '(1 2
>   }
>   }
>   }
> 
> 
> [Pardon the formatting - it’s late and my mailer won’t behave.]
> 
> Andrew
> 
> 


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


Re: Scheme question: convert a range

2015-11-17 Thread Andrew Bernard
Hi Jacques,

You could base a solution on this approach:

  c'1 -\markup {
\column {
\column {
#(string-append
"commllen = "
(string-concatenate (map number->string '(1 2
}
}
}


[Pardon the formatting - it’s late and my mailer won’t behave.]

Andrew



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


Re: Scheme question: convert a range

2015-11-17 Thread David Nalesnik
Jacques,

On Tue, Nov 17, 2015 at 6:32 AM, Jacques Menu  wrote:

> Message says that #(string-append… is not a markup.
>
> > Le 17 nov. 2015 à 13:31, Jacques Menu  a écrit :
> >
> > 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
>

Why not:
{
  c'1 -\markup {
\column {
  \column {
#(string-append
  "commllen = "
  (format #f "~a" (function '(3 . 7)))
  )
  }
}
  }
}


Regarding your approach:

First, it's "list->string" and that deals with a list of character data,
not strings.

You could do something like:

{
  c'1 -\markup {
\column {
  \column {
#(string-append
  "commllen = "
  (apply string-append (map number->string (function '(3 . 7
  )
  }
}
  }
}

But I'm guessing that's not the output format you want.

Hope this helps,
DN
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Scheme question: convert a range

2015-11-17 Thread Jacques Menu
Message says that #(string-append… is not a markup.

> Le 17 nov. 2015 à 13:31, Jacques Menu  a écrit :
> 
> 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  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
>> lilypond-user@gnu.org
>> https://lists.gnu.org/mailman/listinfo/lilypond-user
> 


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


Re: Scheme question: convert a range

2015-11-17 Thread Jacques Menu
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  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
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user


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


Re: Scheme question: convert a range

2015-11-16 Thread Andrew Bernard
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


Re: Scheme question: convert a range

2015-11-16 Thread David Nalesnik
On Mon, Nov 16, 2015 at 3:22 PM, Simon Albrecht 
wrote:

> On 16.11.2015 22:20, Thomas Morley wrote:
>
>> (define (foo pair)
>>(if (and (integer? (car pair)) (integer? (cdr pair)))
>>(iota (1+ (interval-length pair)) (car pair) 1))
>>#f)
>>
>> (foo '(3 . 7))
>> --> (3 4 5 6 7)
>>
>
> An equally good solution.
> Thank you, Simon
>
>
Interesting that all these responses show up in my inbox hours after I sent
mine, though these were sent earlier!
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Scheme question: convert a range

2015-11-16 Thread David Nalesnik
On Mon, Nov 16, 2015 at 5:33 PM, David Nalesnik 
wrote:


>
>> If not, something like this would work:
>>
>
(for all cases)
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Scheme question: convert a range

2015-11-16 Thread David Nalesnik
On Mon, Nov 16, 2015 at 5:24 PM, David Nalesnik 
wrote:

> Hi Simon,
>
> On Sun, Nov 15, 2015 at 12:53 PM, Simon Albrecht 
> 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
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Scheme question: convert a range

2015-11-16 Thread David Nalesnik
Hi Simon,

On Sun, Nov 15, 2015 at 12:53 PM, Simon Albrecht 
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
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Scheme question: convert a range

2015-11-16 Thread Thomas Morley
2015-11-15 19:53 GMT+01:00 Simon Albrecht :
> 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?
>
> TIA, Simon



Hi Simon,

(define (foo pair)
  (if (and (integer? (car pair)) (integer? (cdr pair)))
  (iota (1+ (interval-length pair)) (car pair) 1))
  #f)

(foo '(3 . 7))
--> (3 4 5 6 7)


HTH,
  Harm

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


Re: Scheme question: convert a range

2015-11-16 Thread pls
Simon Albrecht  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)

HTH
Patrick




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


Re: Scheme question: convert a range

2015-11-16 Thread Simon Albrecht

On 16.11.2015 23:30, pls wrote:

Simon Albrecht  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

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


Re: Scheme question: convert a range

2015-11-16 Thread Simon Albrecht

On 16.11.2015 22:20, Thomas Morley wrote:

(define (foo pair)
   (if (and (integer? (car pair)) (integer? (cdr pair)))
   (iota (1+ (interval-length pair)) (car pair) 1))
   #f)

(foo '(3 . 7))
--> (3 4 5 6 7)


An equally good solution.
Thank you, Simon

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


Re: Scheme question: convert a range

2015-11-16 Thread Simon Albrecht

On 16.11.2015 21:59, David Kastrup wrote:

Simon Albrecht  writes:


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?

(let ((x '(3 . 7)))
   (iota (- (cdr x) (car x) -1) (car x)))


Nice! Thanks.

Yours, Simon

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


Re: Scheme question: convert a range

2015-11-16 Thread Urs Liska
(iota 7 3)

Am 15.11.2015 um 19:53 schrieb Simon Albrecht:
> 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?
>
> TIA, Simon
>
> ___
> lilypond-user mailing list
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user


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


Re: Scheme question: convert a range

2015-11-16 Thread David Kastrup
Simon Albrecht  writes:

> 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?

(let ((x '(3 . 7)))
  (iota (- (cdr x) (car x) -1) (car x)))

-- 
David Kastrup

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


Scheme question: convert a range

2015-11-16 Thread Simon Albrecht

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?

TIA, Simon

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