Hello Michael, > how can I access an array (well I think in Scheme that's no real arrays): > > #(define myArr '#(10 20 30))
in scheme lingo this is a vector, which is essentially a pointer array. > in such an element in the paper section? > > > top-markup-spacing = #'((basic-distance . #f) (minimum-distance . #f) > > (padding . #f) (stretchability . #f)) > > I want to set minimum-distance using the first array element, 10. See > attached code, for an unknown reason all my testing does not produce > errors, but does not apply the minimum distance. You probably want to read up on quoting in scheme https://doc.guix.gnu.org/guile/3.0.11/en/html_node/Expression-Syntax.html[1] Starting a scheme expression by ' is a shorthand for `(quote ...)`, which will parse the argument as literal. So `'a` (or `(quote a)`) will not lookup a as variable, but parse this as the literal symbol a, `'(a b c)` will not be interpreted as a function call `(a b c)`, but as the literal list of literal symbols a, b, c, `'#(a b c)` as literal vector. So when you do '((basic-distance . #f) (minimum-distance . (vector-ref myArr 0)) (padding . #f) (stretchability . #f)) this is parsed as the list of the pairs (basic-distance . #f), (padding . #f), (stretchability . #f) and the pair of the symbol minimum-distance and the literal list (vector-ref myArr 0). So this parses just fine, and Lilypond silently discards this value (the relevant section here is in page-layout-problem.cc in the function alter_spring_from_spacing_spec the line 1349: if (read_spacing_spec (spec, &min_dist, ly_symbol2scm ("minimum-distance"))) spring->set_min_distance (min_dist); where read_spacing_spec bool Page_layout_problem::read_spacing_spec (SCM spec, Real *dest, SCM sym) { SCM pair = scm_sloppy_assq (sym, spec); if (scm_is_pair (pair) && scm_is_number (scm_cdr (pair))) { *dest = from_scm<double> (scm_cdr (pair)); return true; } return false; } silently gobbles up everything that is not a pair of cdr-type number. What you actually want to do is to have a list where some parts are to be interpreted as literals, but some are to be evaluated. Of course it would be possible to just generated this list in unquoted form: (list '(basic-distance . #f) (cons 'minimum-distance (vector-ref myArr 0)) ...) But since this is rather high effort scheme has nice concept that is called *quasiquoting* (in the guile doc link directly after quoting). If you do `(quasiquote ...)` the expression will be parsed as literal, but whenever the parser encounters an expression in `(unquote ...)` it is instead evaluated. The shorthand for this is to use ` (backtick) instead of ' for quasiquote, and , (comma) for unquote. So you can do `((basic-distance . #f) (minimum-distance . ,(vector-ref myArr 0)) (padding . #f) (stretchability . #f)) Cheers, Tina -------- [1] https://doc.guix.gnu.org/guile/3.0.11/en/html_node/Expression-Syntax.html
signature.asc
Description: This is a digitally signed message part.
