On Sat, 6 Apr 2019 at 16:30, Thomas Morley <[email protected]> wrote:

> Am Sa., 6. Apr. 2019 um 16:11 Uhr schrieb Gianmaria Lari
> <[email protected]>:
> >
> > I wrote this function
> >
> > #(define (resetList l) (set! l '()))
> >
> >
> > that I would like to set a list to an empty list. This is an example of
> use:
> >
> > \version "2.21.0"
> > #(define mylist '(1 2 3))
> > \markup #(object->string mylist) %this prints (1 2 3)
> >
> > #(define (resetList l) (set! l '()))
> > #(resetList mylist)
> > \markup #(object->string mylist) % this I would like it prints () but it
> prints (1 2 3)
> >
> > I think the problem is related to the fact resetList changes mylist
> locally (sort of) but I have no idea how I can fix it. Any help?
> >
> > Thank you, g.
>
> One possibility is to use a macro:
>
> #(define-macro (reset-list l) `(set! ,l '()))
>

Thank you, it works.

 I tried to make the same with the second of these functions:

#(define (allButLast l) (reverse (cdr (reverse l))))
#(define (numberInc l) (append (allButLast l) (list (1+ (last l)))))

 (it simply increments the last integer element of a list). Here it is a
code that use it:

\version "2.21.0"
#(define (allButLast l) (reverse (cdr (reverse l))))
#(define (numberInc l) (append (allButLast l) (list (1+ (last l)))))

#(define mylist '(1 2 3))
\markup #(object->string mylist)
#(set! mylist (numberInc mylist))
\markup #(object->string mylist)


And here my try with macro:

#(define-macro (numberInc l) `(set! ,l (append (allButLast l) (list (1+
(last l))))))


and this is a complete code that does not work:

\version "2.21.0"
#(define (allButLast l) (reverse (cdr (reverse l))))
#(define-macro (numberInc l) `(set! ,l (append (allButLast l) (list (1+
(last l))))))


#(define mylist '(1 2 3))
\markup #(object->string mylist)
#(numberInc mylist)
\markup #(object->string mylist)


Does it make sense?
Thank you Harm
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to