[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: scheme: working in guile but not in lilypond?
From: |
Gilles |
Subject: |
Re: scheme: working in guile but not in lilypond? |
Date: |
Sun, 22 Apr 2012 01:21:16 +0200 |
User-agent: |
Opera Mail/11.62 (Win32) |
\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