lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scheme max/min in c++


From: David Kastrup
Subject: Re: scheme max/min in c++
Date: Fri, 19 Aug 2016 13:56:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Mark Knoop <address@hidden> writes:

> Just trying out some more ideas for the keep-alive-together-engraver.
> How do I use the Guile max/min functions on a scheme list in C++? I
> have tried this:
>
> SCM this_layer = group_spanners_[i]->get_property ("remove-layer");
> SCM this_max;
> if (scm_is_pair (this_layer))
>   {
>     this_max = scm_apply_0 (scm_max, this_layer);
>   }
>
> ...but the compiler returns:
>
>   error: cannot convert 'scm_unused_struct* (*)(SCM, SCM) {aka
>   scm_unused_struct* (*)(scm_unused_struct*, scm_unused_struct*)}' to
>   'SCM {aka scm_unused_struct*}' for argument '1' to 'scm_unused_struct*
>   scm_apply_0(SCM, SCM)'

Well...

    5.5.2.11 Arithmetic Functions
    .............................

    The C arithmetic functions below always takes two arguments, while the
    Scheme functions can take an arbitrary number.  When you need to invoke
    them with just one argument, for example to compute the equivalent od
    `(- x)', pass `SCM_UNDEFINED' as the second one: `scm_difference (x,
    SCM_UNDEFINED)'.

[...]

     -- Scheme Procedure: max x1 x2 ...
     -- C Function: scm_max (x1, x2)
         Return the maximum of all parameter values.

Most notable, scm_max is a C function, not a Scheme function (which
would be of type SCM itself).  You cannot pass it to scm_apply_0.

If you really, really want to use the Scheme function, however, you can
enter it into lily/lily-imports.cc and lily/include/lily-imports.hh and
then use (after including lily/include/lily-imports.hh of course)

    scm_apply_0 (Lily::max, this_layer);

Assuming that "max" is not a reserved word or macro in C++ (in which
case you just would import it under a slightly modified name).  I think
it isn't, and the existence of std::max or even ::max is not a problem.

-- 
David Kastrup



reply via email to

[Prev in Thread] Current Thread [Next in Thread]