[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme: Syntax for storing a variable in an alist
From: |
Jean Abou Samra |
Subject: |
Re: Scheme: Syntax for storing a variable in an alist |
Date: |
Sun, 18 Oct 2020 21:51:06 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
Le 18/10/2020 à 21:42, Matthew Fong a écrit :
Hello everyone,
I am having a bit of an issue storing a variable in an alist, and I
was wondering if you all could point out what I am doing wrong. If I
write the string directly, there's no issue retrieving it ...
my-alist = #'((1 . "A") (2 . "B") (3 . "C"))
value = #(ly:assoc-get 2 my-alist " error")
\markup \value
hymnID = "210"
hymnMeter = "8.8.8.8"
hymnAlist = #'(("ID" . \hymnID ) ("Meter" . \hymnMeter ))
hymnValue = #(ly:assoc-get "ID" hymnAlist "error")
\markup \hymnValue
Many thanks,
mattfong
Hello,
Take a look at the output of:
hymnID = "210"
hymnMeter = "8.8.8.8"
hymnAlist = #'(("ID" . \hymnID ) ("Meter" . \hymnMeter ))
#(display (ly:assoc-get "ID" hymnAlist "error"))
This prints
\hymnID
The reason is that you created the alist using quoting, and a piece of
text that you quote is a symbol. Note that prefixing something with a
backslash is not the way to use a LilyPond variable from Scheme; you
just need the naked name. Here, the values (as opposed to keys) in
hymnAlist are symbolic values representing the identifiers “\hymnID” and
“\hymnMeter” (backslashes are valid in Scheme identifiers!).
You can read more about quoting here:
https://scheme-book.ursliska.de/scheme/quoting/README.html
The correct way to go about it is to use quasi-quoting:
hymnID = "210"
hymnMeter = "8.8.8.8"
hymnAlist = #`(("ID" . ,hymnID ) ("Meter" . ,hymnMeter ))
\markup #(ly:assoc-get "ID" hymnAlist)
(note ` instead of ' and the commas).
Alternatively,
hymnAlist = #(list (cons "ID" hymnID ) (cons "Meter" hymnMeter ))
has the same effect.
Best,
Jean
- Scheme: Syntax for storing a variable in an alist, Matthew Fong, 2020/10/18
- Re: Scheme: Syntax for storing a variable in an alist,
Jean Abou Samra <=
- Re: Scheme: Syntax for storing a variable in an alist, Aaron Hill, 2020/10/18
- Re: Scheme: Syntax for storing a variable in an alist, Matthew Fong, 2020/10/18
- Re: Scheme: Syntax for storing a variable in an alist, Jean Abou Samra, 2020/10/18
- Re: Scheme: Syntax for storing a variable in an alist, David Kastrup, 2020/10/18
- Re: Scheme: Syntax for storing a variable in an alist, Matthew Fong, 2020/10/18
- Re: Scheme: Syntax for storing a variable in an alist, Matthew Fong, 2020/10/19
- Re: Scheme: Syntax for storing a variable in an alist, Aaron Hill, 2020/10/19
- Re: Scheme: Syntax for storing a variable in an alist, Matthew Fong, 2020/10/19