[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: syntax helper for ly:music-property
From: |
Nicolas Sceaux |
Subject: |
Re: syntax helper for ly:music-property |
Date: |
Sat, 19 Jun 2004 12:09:17 +0200 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) |
Jan Nieuwenhuizen <address@hidden> writes:
> Han-Wen Nienhuys writes:
>
>>> >> guile> (set! address@hidden (ly:make-pitch -1 4 0))
>
>> No. Do you have a more elaborate example?
>
> Hmm. I just thought that #@ .. elements.0.elements.2
>
> looked vagely like a class initilizer
>
> (make <foe> #elements 0 #elements 2
>
> but then I realized that all names were the same (elements) so I kept
> it extra vague. I'll have to look into the example again.
>
> Jan.
My first idea was to create a syntactic construct similar to Common
Lisp's WITH-SLOTS, e.g:
(with-properties (pitch duration) my-music
(set! pitch (ly:make-pitch ...))
(display duration)
...)
but I was not able to make it work (I'm no guru at define-syntax,
syntax-case and friends, I didn't manage to create symbol-macros in
guile scheme). I came to a second idea (which worked) :
(with-properties (my-music #{ ... #})
(display my-music.origin)
(set-my-music.elements! ...))
but it was horribly slow, and when toying with a more elaborate
example, I find out that it was not a good solution, as music
expressions are often very nested, hence too many with-properties.
Finally, I remembered a post on comp.lang.lisp which introduced a '@'
reader character, used to access class slots, symbol properties,
structure fields, etc, in a fashion similar to
C++/Java/Python/etc. That's what I proposed here. Thus:
(set! address@hidden (ly:make-pitch -1 4 0))
could have been wrote in, say, Python:
titi.elements[0].elements[2].elements[0].pitch = ...
or in regular scheme (I may make a mistake):
(set! (ly:music-property
(car (ly:music-property
(caddr (ly:music-property
(car (ly:music-property titi 'elements))
'elements))
'elements))
'pitch)
(ly:make-pitch -1 4 0)) ;; ouf
nicolas