\version "2.15.36"

#(define-public lst `())
#(define (set-new-alist! ls-1 ls-2 proc)
  (for-each (lambda (x) (set! ls-1 (acons x proc ls-1))) ls-2)
  ls-1)
#(set-new-alist! lst '(1 2 3) "X")
#(display lst)

returns: ()
What am I missing?


%%
Well, if you change
#(set-new-alist! lst '(1 2 3) "X")
by
#(set! lst (set-new-alist! lst '(1 2 3) "X"))
It works.
Seems that scheme works with a copy of the list lst.
So you have to re-assign lst to the return of the function.
If i have well understood how scheme works, the only way to avoid the set! is to use a function + a MACRO,
Perhaps something like that :

%%%%%%%%%%%%%%%%%%%

#(define-public lst `())#(define-public lst `())
#(define (fill-list ls proc)
  (map
    (lambda (x) (cons x proc))
    ls))
#(define-macro (set-new-alist! ls-1 ls-2 proc)
  `(set! ,ls-1 (fill-list ,ls-2 ,proc)))

#(set-new-alist! lst '(1 2 3) "X")
#(display lst)

%%%%%%%%%%%%%%%%%%%%%

Gilles

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

Reply via email to