Handling quoted lists

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Handling quoted lists

Urs Liska-3
I'm feeling totally stupid, but after hours of nightly poking and
ly:message "debugging" around I'm at least at a point where I can ask
concrete questions instead of an MWE.

In
https://github.com/openlilylib/oll-core/blob/master/internal/properties.scm#L566-L611
 (may not be the latest state!) I'm trying to create a macro and get
messed up with quoting etc.

In
https://github.com/openlilylib/oll-core/blob/master/usage-examples/properties.ly#L10
 a symbol list demo.props is created and properly handled.

But in
https://github.com/openlilylib/oll-core/blob/master/usage-examples/properties.ly#L50-L51
 a (quasi)quoted list isn't managed correctly. I would now use
  '(demo props)
here to create a regular symbol list, but this ends up as
  (quote (demo props))
in the macro. When used later in
https://github.com/openlilylib/oll-core/blob/master/internal/properties.scm#L20
  (append '(_propsets) propset-path))
will result in
  (list (quote _propsets) (quote quote) (list (quote demo) (quote
props)))

Spo the question must be simple and me stupid, but how can I add the
symbol list as an argument in Scheme (in the macro invication) so the
last  call will result in a flat symbol list?

Thanks for any pointer, hint or solution!
Urs


Reply | Threaded
Open this post in threaded view
|

Re: Handling quoted lists

David Kastrup
Urs Liska <[hidden email]> writes:

> I'm feeling totally stupid, but after hours of nightly poking and
> ly:message "debugging" around I'm at least at a point where I can ask
> concrete questions instead of an MWE.
>
> In
> https://github.com/openlilylib/oll-core/blob/master/internal/properties.scm#L566-L611
>  (may not be the latest state!) I'm trying to create a macro and get
> messed up with quoting etc.

Let me be very clear here: the _sole_ difference between a macro and a
function is that when evaluating a function call, the function's
arguments are read, then every argument is evaluated, the function is
called with the evaluated arguments and the resulting value is returned.

In contrast, a macro's arguments are read, then the macro is called with
unevaluated arguments and the resulting value is evaluated afterwards to
make up the resulting value.

In either case, the arguments are read before any evaluation happens.
And in either way, there is exactly one level of evaluation happening,
for functions before they get called, and for macros after they get
called.

If you have something like

bla = #(define-music-function (blub) (symbol-list?)
         (my-macro blub))

Then my-macro will receive a single symbol as argument, and that symbol
is blub .  Assigning any meaning to blub will happen if the symbol blub
appears in the return value from my-macro, in which case it will get
replaced by the value received from calling bla.

That makes macros be of very limited usefulness for processing
expressions specified as music function arguments.

--
David Kastrup