[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Better method for inputting alists?
From: |
Aaron Hill |
Subject: |
Better method for inputting alists? |
Date: |
Thu, 30 Sep 2021 01:17:24 -0700 |
User-agent: |
Roundcube Webmail/1.4.9 |
LilyPond makes it easy to define a top-level alist and extend it with
new keys:
%%%%
\version "2.22.0"
foo.one = 1
foo.two = "2"
foo.nested.red = 3,4
foo.nested.blue = ##t
\void \displayScheme \foo.nested.red
%%%%
This pattern works well enough. However, especially when nested more
deeply, it does result in redundant and error-prone typing as each new
entry must specify the full path of keys.
Borrowing syntax for context mods, one can get an improved approach:
%%%%
\version "2.22.0"
alist =
#(define-scheme-function (with) (ly:context-mod?)
(define (assign? mod) (eq? 'assign (car mod)))
(define (assign->pair mod) (cons (cadr mod) (caddr mod)))
(map assign->pair (filter assign? (ly:get-context-mods with))))
foo = \alist \with {
one = 1
two = "2"
nested = \alist \with {
red = 3,4
blue = ##t
}
}
\void \displayScheme \foo.nested.red
%%%%
The above technique admittedly abuses the \with construct, so would it
make sense for the parser to support alists directly? Not sure what the
syntax should be; but here's a possibility prepending a colon to the
brace:
%%%%
foo = :{ one = 1 two = "2" nested = :{ red = 3,4 blue = ##t } }
%%%%
Functions could take advantage of such abbreviated syntax to support
named arguments without having to resort to the same \with hack. The
\override markup command in particular would become nicer-looking:
%%%%
\markup \override :{ offset = 15 thickness = 3 } \undertie "lorem ipsum"
%%%%
-- Aaron Hill
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Better method for inputting alists?,
Aaron Hill <=