Re: scheme-question about accumulating lists of lists

2019-04-23 Thread Thomas Morley
Hi David,

Am Di., 23. Apr. 2019 um 04:12 Uhr schrieb David Pirotte :
> ...
> > Now `core-guile-condition´ feels like a case for `match´, but I
> > couldn't make it work.
> > Is this a bad use case and alist searching is always preferable?
>
> I would do this:
[...]

regarding your code, it's all obvious.
And I ask myself why I didn't get there ...

>
> > As a side note.
> > I'd like to download the "Guile Reference Manual" as one big-page
> > .html, but couldn't find any for 2.9.1.
> > Not yet done?
>
> No, but you could locally build it, using the glib gendoc.sh script, let me 
> know if
> you need help with this, I can cook sometig for you ...

First I tried in my git-guile-repository
cd doc/ref
../../build-aux/gendocs.sh guile "GNU Guile 2.9.1 Reference Manual"
which gave me:
../../build-aux/gendocs.sh: cannot read ./gendocs_template.
../../build-aux/gendocs.sh: it is available from
http://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/gendocs_template.
Though I see gendocs.sh in the doc-folder, shouldn't gendocs.sh find it there?
I then did in doc/ref
wget  http://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/gendocs_template
../../build-aux/gendocs.sh guile "GNU Guile 2.9.1 Reference Manual"

Success.

Thanks,
  Harm

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


Re: scheme-question about accumulating lists of lists

2019-04-22 Thread David Pirotte
Hello THomas,

> ...
> Now `core-guile-condition´ feels like a case for `match´, but I
> couldn't make it work.
> Is this a bad use case and alist searching is always preferable?

I would do this:

(define (is-spanner? grob)
  (match grob
((g-key . g-vals)
 (let ((meta (assq-ref g-vals 'meta)))
   (and meta
(eq? (assq-ref meta 'class)
 'Spanner)
g-key)

Which you could generalize:

(define (lp-grob-is-a? grob class)
  (match grob
((g-key . g-vals)
 (let ((meta (assq-ref g-vals 'meta)))
   (and meta
(eq? (assq-ref meta 'class)
 class)
g-key)

Then filtering becomes:

(define grobs
  '((Name-1 . ((foo . x)
   (bar . y)
   (buzz . z)
   (meta . ((name . Name-1)
(class . Spanner)
(ifaces . (i1 i2 i3))
(Name-2 . ((foo . m)
   (bar . n)
   (buzz . o)
   (meta . ((name . Name-2)
(class . Not-a-Spanner)
(ifaces . (i4 i5 i6))
(Name-3 . ((foo . m)
   (bar . n)
   (buzz . o)
   (meta . ((name . Name-3)
(class . Spanner)
(ifaces . (i7 i8 i9

scheme@(guile-user)> (filter-map
(lambda (grob)
  (lp-grob-is-a? grob 'Spanner))
grobs)
$6 = (Name-1 Name-3)

> As a side note.
> I'd like to download the "Guile Reference Manual" as one big-page
> .html, but couldn't find any for 2.9.1.
> Not yet done?

No, but you could locally build it, using the glib gendoc.sh script, let me 
know if
you need help with this, I can cook sometig for you ...

David.


pgpDLtncfEjE5.pgp
Description: OpenPGP digital signature
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: scheme-question about accumulating lists of lists

2019-04-22 Thread Thomas Morley
Am So., 21. Apr. 2019 um 23:51 Uhr schrieb David Pirotte :

> > Whether 'pattern matching' will be useful to hide complexity to make
> > life easier for our users or whether it adds an abstraction layer,
> > which would make it even harder for users to write their own
> > guile-code, I can't judge currently.
>
> Ok, I believe it does help a lot, maybe even more scheme beginners actually, 
> and so
> do our maintainers, here is an extract of the (latest) manual, section "6.6.8 
> Pairs":
>
> ...
> Since a very common operation in Scheme programs is to access the car 
> of a
> car of a pair, or the car of the cdr of a pair, etc., the procedures 
> called
> caar, cadr and so on are also predefined. However, using these 
> procedures is
> often detrimental to readability, and error-prone. Thus, accessing the
> contents of a list is usually better achieved using pattern matching
> techniques (see Pattern Matching).
> ...
>
> But of course do as you wish, there is nothing 'wrong' writing good scheme 
> code using
> 'old' destructuring techniques, but it will, always imo, be more difficult to 
> read
> and maintain.

Hi David,

please don't get me wrong, read my "I can't judge currently" as: I
don't have the knowledge yet to say anything reasonable about (ice-9
match).

To increase my knowledge I started playing around with `match´ and
tried to get all LP-grob-names which are Spanner out of
`all-grob-descriptions`.
`all-grob-descriptions` is an alist, if you don't have LilyPond at
hand you may use `test-alist` below.

In the example below (all in a .ly-file, but apart from
`lp-assoc-get-condition´ it works in a guile-prompt as well) I coded
different conditions how to get the result.
`lp-assoc-get-condition´ is what I'd use
`alist-searching-condition´ is also possible ofcourse, don't using own
LP-procedures.
`core-guile-condition´ has the worst syntax I could think of ;)

#(begin

(define test-alist
  '(
(Name-1
 . (
(foo . x)
(bar . y)
(buzz . z)
(meta . ((name . Name-1)
 (class . Spanner)
 (ifaces . (i1 i2 i3)))
;; (Name2 . ...) etc
 )

(define (core-guile-condition g) ;; worst
  (and
(eq? 'Spanner (cdr (car (cdr (cdr (car (last-pair (cdr g
(car g)))

(define (alist-searching-condition g)
  (and (eq? 'Spanner (assq-ref (assq-ref (cdr g) 'meta) 'class)) (car g)))

(define (lp-assoc-get-condition g)
  ;;`assoc-get´ relies on C++ defined `ly:assoc-get´
  ;; From LP Internal Reference:
  ;; Function: ly:assoc-get key alist default-value strict-checking
  ;;   Return value if key in alist, else default-value (or #f if not
specified).
  ;;   If strict-checking is set to #t and key is not in alist, a
  ;;   programming_error is output.
  (and (eq? 'Spanner (assoc-get 'class (assoc-get 'meta (cdr g (car g)))

(pretty-print
  (filter-map
core-guile-condition
;alist-searching-condition
;lp-assoc-get-condition
  ;all-grob-descriptions
  test-alist
  ))
  )

Now `core-guile-condition´ feels like a case for `match´, but I
couldn't make it work.
Is this a bad use case and alist searching is always preferable?

As a side note.
I'd like to download the "Guile Reference Manual" as one big-page
.html, but couldn't find any for 2.9.1.
Not yet done?

Thanks,
  Harm

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


Re: scheme-question about accumulating lists of lists

2019-04-21 Thread David Pirotte
Hi Thomas,

> ...
> Thanks again!

You're welcome.

I used 'funny' (weird) procedure and variable names, but if the procedure is to 
be
exposed to your users, and with the objective of making it simple to use, read 
and
maintain, as you described later in your answer, you could write it as - using
(ice-9 match):

(define (lp-map proc lp-list)
  "Apply PROC to each element of LP-LIST. An LP-LIST must be a list of
lists of items - (cons '(a b c) (cons '(d e f) (cons '(g h i) '( -
or a list of lists of items plus a pair of list of items - (cons '(a b
c) (cons '(d e f) '(g h i))).  Each sublist item must
statisfy (not (pair? item)).  The result(s) of the procedure
applications are saved and returned in a list."
  (let loop ((lp-list lp-list)
 (result '()))
(match lp-list
  ((elt . rest)
   (if (pair? elt)
   (loop rest
 (cons (proc elt) result))
   (reverse! (cons (proc lp-list) result
  (()
   (reverse! result)

This version also matches the built-in map argument order. If you need an 
lp-map that
accepts more then an lp-list, let me know:   "lp-map proc lp-list1 lp-list2 ..."

Now, it is worth pointing that if the above code is ok, it is not very robust: 
it
strongly depends on well formed LP-LIST, and will fail otherwise, as (not
very well) described in the procedure comment, consider this example:

(define bad-lp-list
  (cons '(a b c) (cons '(1 2 3) '((x) y z

scheme@(guile-user)> (lp-map car bad-lp-list)
$2 = (a 1 x y)

> I think you're wrong.
> It's not in the guile-1.8-docs, but below worked:

Oh, great.

> ...
> Among keeping things simple is the attempt to use very little
> additional guile-modules.

I am all in favor of simplicity (who would not?), though I don't agree that not
using additional Guile modules does (always) help to achieve that goal.

> Whether 'pattern matching' will be useful to hide complexity to make
> life easier for our users or whether it adds an abstraction layer,
> which would make it even harder for users to write their own
> guile-code, I can't judge currently.

Ok, I believe it does help a lot, maybe even more scheme beginners actually, 
and so
do our maintainers, here is an extract of the (latest) manual, section "6.6.8 
Pairs":

...
Since a very common operation in Scheme programs is to access the car 
of a
car of a pair, or the car of the cdr of a pair, etc., the procedures 
called
caar, cadr and so on are also predefined. However, using these 
procedures is
often detrimental to readability, and error-prone. Thus, accessing the
contents of a list is usually better achieved using pattern matching
techniques (see Pattern Matching).
...

But of course do as you wish, there is nothing 'wrong' writing good scheme code 
using
'old' destructuring techniques, but it will, always imo, be more difficult to 
read
and maintain.

David.


pgpWdxXCqa_hL.pgp
Description: OpenPGP digital signature
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: scheme-question about accumulating lists of lists

2019-04-21 Thread Thomas Morley
Am So., 21. Apr. 2019 um 02:34 Uhr schrieb David Pirotte :
>
> Hi Thomas,
>
> > ...
> > Thanks pointing me to this possibility, in my use-case I then could do:
> > (define (p) (cons '(1 2 3) '(4 5 6)))
> > (define l1 '(a b c))
> > (define l2 '(x y z))
> > (cons* l1 l2 (car (p)) (cdr (p)) '())
> > =>
> > ((a b c) (x y z) (1 2 3) (4 5 6))
>
> Yes, if you can (you mentioned the code was not yours and couldn't be
> changed ...) that would be a lot cleaner, imo, and will let you use 'built-in'
> scheme, guile and srfi-1 procedures that work on lists, as mentioned in my 
> first
> answer.

Yep, I can't change the 'consing' built-in procedure, (I tried to
patch it but it gives an unexpected error at on first sight absolutely
unrelated location, should investigate ...).

> > > (define (blue-walk blue proc)
> > >   (let loop ((blue blue)
> > >  (result '()))
> > > (match blue
> > >   ((a . rest)
> > >(if (pair? a)
> > >(loop rest
> > >  (cons (proc a) result))
> > >(reverse! (cons (proc (cons a rest))
> > >result
> > >   (()
> > >(reverse! result)
>
> In the above code, I am performing an extra and therefore useless cons, here
> is a correction (not a bug, but one should _always_ avoid consing whenever 
> possible):
>
> (define (blue-walk blue proc)
>   (let loop ((blue blue)
>  (result '()))
> (match blue
>   ((a . rest)
>(if (pair? a)
>(loop rest
>  (cons (proc a) result))
> ->   (reverse! (cons (proc blue)
>result
>   (()
>(reverse! result)

Thanks again!

> > My guile-knowledge is mostly limited to what LilyPond needs.
> > As far as I can tell (ice-9 match) isn't used in our source.
> > So I need to study your `blue-walk´ from scratch.
>
> In this particular case, match is 'convenient', but not really indispensable 
> - and I
> see now it's not in guile-1.8.

I think you're wrong.
It's not in the guile-1.8-docs, but below worked:

~$ guile
guile> (version)
"1.8.8"
guile> (use-modules (ice-9 match))
guile> (define blue
  (cons '(a b c) (cons '(1 2 3) '(x y z
guile> (define fox
  (cons '(a b c) (cons '(1 2 3) (cons '(x y z) '()
guile> (define (blue-walk blue proc)
  (let loop ((blue blue)
 (result '()))
(match blue
  ((a . rest)
   (if (pair? a)
   (loop rest
 (cons (proc a) result))
   (reverse! (cons (proc blue)
   result
  (()
   (reverse! result)
guile> (blue-walk blue cdr)
((b c) (2 3) (y z))
guile> (blue-walk fox cdr)
((b c) (2 3) (y z))
guile>

> Here is a version that does not need match (though
> you might not even need it if you can (cons* a b c ... '()) as you mentioned 
> here
> above):
>
> (define (fox-walk fox proc)
>   (let loop ((fox fox)
>  (result '()))
> (if (null? fox)
> (reverse! result)
> (let ((a (car fox)))
>   (if (pair? a)
>   (loop (cdr fox)
> (cons (proc a) result))
>   (reverse! (cons (proc fox)
>   result)))
>
> Now, if/when you (lily devs I mean, not just you of course) plan to use 2.0, 
> 2.2 or
> 3.0 (2.9.1 is it is ...) [*], it is highly recommended to use match 
> 'everywhere'
> you'd use car, cdr, cadr ... but not only, look at the "7.7 Pattern Matching"
> section of a recent manual for more ...  the code is/becomes a lot more 
> readable,
> and match is not only extremely powerful, but also extremely fast (no 
> figures, but
> it's being said there is no penalty compared to using 'older' destructuring
> techniques ... (referred to, among guilers, 'the car cdr hell' :))

Other devs may drop in here, but this is my very basic understanding
about LilyPond/guile-relationship:
LilyPond uses guile as it's extending language.
Among LilyPond users there are musicians with little or even no
programming  background up to experienced programmers with interests
in type-setting music.
(Actually I was one of those musicians with no programming background.
Ok, probably one could say I had some ambitions.)

To give the former the possibility to extend LilyPond with guile we
try to keep things as simple as possible (it's sometimes scaring
enough), give the users strong tools at hand which hide complexity,
and do things in a modular way so they can be changed in detail
without affecting other stuff, if possible. David Kastrup did
wagonloads of work in this regard (and the C++ layer as well).

Among keeping things simple is the attempt to use very little
additional guile-modules.

So far my general basic understanding.

Whether 'pattern matching' will be useful to hide complexity to make
life easier for our users or whether it adds an abstraction layer,
which would make it even harder for users to write their own
guile-code, I can't judge currently.


Re: scheme-question about accumulating lists of lists

2019-04-20 Thread David Pirotte
Hi Thomas,

> ...
> Thanks pointing me to this possibility, in my use-case I then could do:
> (define (p) (cons '(1 2 3) '(4 5 6)))
> (define l1 '(a b c))
> (define l2 '(x y z))
> (cons* l1 l2 (car (p)) (cdr (p)) '())
> =>  
> ((a b c) (x y z) (1 2 3) (4 5 6))

Yes, if you can (you mentioned the code was not yours and couldn't be
changed ...) that would be a lot cleaner, imo, and will let you use 'built-in'
scheme, guile and srfi-1 procedures that work on lists, as mentioned in my first
answer.

> > (define (blue-walk blue proc)
> >   (let loop ((blue blue)
> >  (result '()))
> > (match blue
> >   ((a . rest)
> >(if (pair? a)
> >(loop rest
> >  (cons (proc a) result))
> >(reverse! (cons (proc (cons a rest))
> >result
> >   (()
> >(reverse! result)

In the above code, I am performing an extra and therefore useless cons, here
is a correction (not a bug, but one should _always_ avoid consing whenever 
possible):

(define (blue-walk blue proc)
  (let loop ((blue blue)
 (result '()))
(match blue
  ((a . rest)
   (if (pair? a)
   (loop rest
 (cons (proc a) result))
->   (reverse! (cons (proc blue)
   result
  (()
   (reverse! result)

> My guile-knowledge is mostly limited to what LilyPond needs.
> As far as I can tell (ice-9 match) isn't used in our source.
> So I need to study your `blue-walk´ from scratch.

In this particular case, match is 'convenient', but not really indispensable - 
and I
see now it's not in guile-1.8.  Here is a version that does not need match 
(though
you might not even need it if you can (cons* a b c ... '()) as you mentioned 
here
above):

(define (fox-walk fox proc)
  (let loop ((fox fox)
 (result '()))
(if (null? fox)
(reverse! result)
(let ((a (car fox)))
  (if (pair? a)
  (loop (cdr fox)
(cons (proc a) result))
  (reverse! (cons (proc fox)
  result)))

Now, if/when you (lily devs I mean, not just you of course) plan to use 2.0, 
2.2 or
3.0 (2.9.1 is it is ...) [*], it is highly recommended to use match 'everywhere'
you'd use car, cdr, cadr ... but not only, look at the "7.7 Pattern Matching"
section of a recent manual for more ...  the code is/becomes a lot more 
readable,
and match is not only extremely powerful, but also extremely fast (no figures, 
but
it's being said there is no penalty compared to using 'older' destructuring
techniques ... (referred to, among guilers, 'the car cdr hell' :))

David.

[*] I know why the change hasn't been made, I don't expect any answer here,
just mentioning that if/when ... (saying this so you save your energy 
and to
avoid to start yet another conversation on this already deeply discussed
mater among you ...)


pgp_tUmxGgAZD.pgp
Description: OpenPGP digital signature
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: scheme-question about accumulating lists of lists

2019-04-20 Thread Thomas Morley
Hi David,

Am Sa., 20. Apr. 2019 um 03:52 Uhr schrieb David Pirotte :
>
> Hi again,
>
> Replying twice to myself in a row, how is that :)
> A little tired I guess ...
>
> > > Note that the above will only work if the last 'blue item' has 3 
> > > elements, you'd
> > > need to adapt for other use case (which also 'speak' in favor of the 
> > > cleaner
> > > approach.
>
> > Actually, I didn't like what I wrote, here is a slightly better code:
>
> And here is a corrected version: the code in the mail I'm answering now would 
> not
> return proper (expected) results for any other operator then car ... this one 
> will
> let you really walk :)
>
> (use-modules (ice-9 match))
>
> (define blue
>   (cons '(a b c) (cons '(1 2 3) '(x y z
>
> (define fox
>   (cons '(a b c) (cons '(1 2 3) (cons '(x y z) '()

Thanks pointing me to this possibility, in my use-case I then could do:
(define (p) (cons '(1 2 3) '(4 5 6)))
(define l1 '(a b c))
(define l2 '(x y z))
(cons* l1 l2 (car (p)) (cdr (p)) '())
=>
((a b c) (x y z) (1 2 3) (4 5 6))

>
> (define (blue-walk blue proc)
>   (let loop ((blue blue)
>  (result '()))
> (match blue
>   ((a . rest)
>(if (pair? a)
>(loop rest
>  (cons (proc a) result))
>(reverse! (cons (proc (cons a rest))
>result
>   (()
>(reverse! result)
>
> scheme@(guile-user)> (load "blue.scm")
> ;;; note: source file /usr/alto/projects/guile/blue.scm
> ;;; ...
> scheme@(guile-user)> (blue-walk blue car)
> $2 = (a 1 x)
> scheme@(guile-user)> (blue-walk fox car)
> $3 = (a 1 x)
> scheme@(guile-user)> (blue-walk blue cdr)
> $4 = ((b c) (2 3) (y z))
> scheme@(guile-user)> (blue-walk fox cdr)
> $5 = ((b c) (2 3) (y z))

My guile-knowledge is mostly limited to what LilyPond needs.
As far as I can tell (ice-9 match) isn't used in our source.
So I need to study your `blue-walk´ from scratch.

Thanks a lot,
  Harm

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


Re: scheme-question about accumulating lists of lists

2019-04-19 Thread David Pirotte
Hi again,

Replying twice to myself in a row, how is that :)
A little tired I guess ...

> > Note that the above will only work if the last 'blue item' has 3 elements, 
> > you'd
> > need to adapt for other use case (which also 'speak' in favor of the cleaner
> > approach.  

> Actually, I didn't like what I wrote, here is a slightly better code:

And here is a corrected version: the code in the mail I'm answering now would 
not
return proper (expected) results for any other operator then car ... this one 
will
let you really walk :)

(use-modules (ice-9 match))

(define blue
  (cons '(a b c) (cons '(1 2 3) '(x y z

(define fox
  (cons '(a b c) (cons '(1 2 3) (cons '(x y z) '()

(define (blue-walk blue proc)
  (let loop ((blue blue)
 (result '()))
(match blue
  ((a . rest)
   (if (pair? a)
   (loop rest
 (cons (proc a) result))
   (reverse! (cons (proc (cons a rest))
   result
  (()
   (reverse! result)

scheme@(guile-user)> (load "blue.scm")
;;; note: source file /usr/alto/projects/guile/blue.scm
;;; ...
scheme@(guile-user)> (blue-walk blue car)
$2 = (a 1 x)
scheme@(guile-user)> (blue-walk fox car)
$3 = (a 1 x)
scheme@(guile-user)> (blue-walk blue cdr)
$4 = ((b c) (2 3) (y z))
scheme@(guile-user)> (blue-walk fox cdr)
$5 = ((b c) (2 3) (y z))

Cheers,
David


pgpj47BxMMxuy.pgp
Description: OpenPGP digital signature
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: scheme-question about accumulating lists of lists

2019-04-19 Thread David Pirotte
Hi again,

> Note that the above will only work if the last 'blue item' has 3 elements, 
> you'd
> need to adapt for other use case (which also 'speak' in favor of the cleaner
> approach.

Actually, I didn't like what I wrote, here is a slightly better code:

(use-modules (ice-9 match))

(define (blue-walk blue proc)
  (let loop ((blue blue)
 (result '()))
(match blue
  ((a . rest)
   (if (pair? a)
   (loop rest
 (cons (proc a) result))
   (reverse! (cons a result
  (()
   (reverse! result)

It solves the above note (it avoids to have to know how many elements the last 
pair
has), and also let you process both 'your' structure and  the 'cleaner' one:

(define blue
  (cons '(a b c) (cons '(1 2 3) '(x y z

(define fox
  (cons '(a b c) (cons '(1 2 3) (cons '(x y z) '()

scheme@(guile-user)> (load "blue.scm")
;;; note: source file /usr/alto/projects/guile/blue.scm
;;;   newer than ...
scheme@(guile-user)> (blue-walk fox car)
$2 = (a 1 x)
scheme@(guile-user)> (blue-walk blue car)
$3 = (a 1 x)


Cheers,
David


pgpq3Krn_OVTN.pgp
Description: OpenPGP digital signature
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: scheme-question about accumulating lists of lists

2019-04-19 Thread David Pirotte
Hi Thomas,

> Failing example:
> (map
>   car
>   (cons '(a b c) (cons '(1 2 3) '(x y z

> One way to make it work is to convert the initial pair (cons '(1 2 3)
> '(x y z)) to a list of lists, i.e (cons '(1 2 3) (list '(x y z)))
> The question is: is it the only and/or best way?

It sounds a lot cleaner to me, because, in the end, it is as if:

(cons '(a b c) (cons '(1 2 3) (cons '(x y z) '(

which is 'consistent all the way down, so to speak, and will let you use 
build-in
scheme ops like map, fold, ...

If you want to keep the original structure though, I'd use (ice-9 match) and
recurse:

(use-modules (ice-9 match))

(define blue
  (cons '(a b c) (cons '(1 2 3) '(x y z

(define (blue-walk blue proc)
  (let loop
  ((blue blue)
   (result '()))
(match blue
  ((x y z)
   (reverse! (cons x
   result)))
  ((a . rest)
   (loop rest
 (cons (proc a) result))

scheme@(guile-user)> (load "blue.scm")
;;; compiling /usr/alto/projects/guile/blue.scm
;;; compiled 
/home/david/.cache/guile/ccache/2.2-LE-8-3.A/usr/alto/projects/guile/blue.scm.go
scheme@(guile-user)> (blue-walk blue car)
$8 = (a 1 x)

Note that the above will only work if the last 'blue item' has 3 elements, 
you'd need
to adapt for other use case (which also 'speak' in favor of the cleaner 
approach.

David


pgpE8DMTMeHFF.pgp
Description: OpenPGP digital signature
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: scheme-question about accumulating lists of lists

2019-04-19 Thread Thomas Morley
Am Fr., 19. Apr. 2019 um 17:09 Uhr schrieb Malte Meyn :
>
>
>
> Am 19.04.19 um 16:35 schrieb Thomas Morley:
> > I could do
> > (cons '(a b c) (list (car (list-pair)) (cdr (list-pair
> > and to get the last list: (last ...)
> > Looksy clumsy, though.
> >
> > Any better method?
>
> I’m not sure what you want to do here. But maybe it would be easier to
> convert the pair of lists to a lists of lists first?

I want to run procedures over constructed lists of lists, while the
initial first entry is a pair.
Failing example:
(map
  car
  (cons '(a b c) (cons '(1 2 3) '(x y z

One way to make it work is to convert the initial pair (cons '(1 2 3)
'(x y z)) to a list of lists, i.e (cons '(1 2 3) (list '(x y z)))
The question is: is it the only and/or best way?

Thanks,
  Harm

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


Re: scheme-question about accumulating lists of lists

2019-04-19 Thread Malte Meyn



Am 19.04.19 um 16:35 schrieb Thomas Morley:

I could do
(cons '(a b c) (list (car (list-pair)) (cdr (list-pair
and to get the last list: (last ...)
Looksy clumsy, though.

Any better method?


I’m not sure what you want to do here. But maybe it would be easier to 
convert the pair of lists to a lists of lists first?


\version "2.21.0"

#(begin
  (define (list-pair->list-list the-list-pair)
(list (car the-list-pair) (cdr the-list-pair)))
  (define foo '((a b c) . (d e f)))
  (display foo)
  (newline)
  (display (list-pair->list-list foo)))

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


scheme-question about accumulating lists of lists

2019-04-19 Thread Thomas Morley
Hi all,

let's say I've a procedure building a pair of lists. Actually it's a
built-in procedure, so I can't change it.
For the sake of simplicity let's take:
(define (list-pair) (cons '(1 2 3) '(x y z)))
(list-pair) returns ((1 2 3) x y z)
(cdr (list-pair)) returns the second list, i.e. (x y z)
All fine so far.

Now I add another list
(cons '(a b c) (list-pair))  => ((a b c) (1 2 3) x y z)
Now it's starts getting inconveniant to get the last list, i.e. (x y z)
(and I may add an arbitrary number of lists this way)

I could do
(cons '(a b c) (list (car (list-pair)) (cdr (list-pair
and to get the last list: (last ...)
Looksy clumsy, though.

Any better method?

Thanks,
  Harm

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