* Modifying nested dictionary/alist type data
@ 2016-04-14 23:44 Paul Morris
2016-04-15 14:00 ` Wette, Matthew R (3441)
2016-04-15 17:20 ` Andreas Rottmann
0 siblings, 2 replies; 4+ messages in thread
From: Paul Morris @ 2016-04-14 23:44 UTC (permalink / raw)
To: guile-user
Hi, I’m rewriting one of LilyPond's C++ routines in Guile/Scheme in order to customize it for my own use, and it uses some nested dictionary/map/alist-style data structures that you can modify using something like this in C++:
mydata[aaa][bbb].ccc = 10;
Ok, maybe use alists, but how to modify the nested values? ...given that you need an extra “set!” operation to do this reliably, as shown in the documentation:
(set! address-list
(assoc-set! address-list "bob" "11 Newington Avenue"))
But if you have nested alists like this
(define my-alist ‘((aaa . ((bbb . ((ccc . 10)))))))
and you want to change ccc, then the “set!” trick doesn’t help. (...what would you “set!”?) So what’s the best approach here for such nested data structures? Maybe I should just use nested hash maps instead? Sorry if I’m missing something obvious.
Thanks,
-Paul
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Modifying nested dictionary/alist type data
2016-04-14 23:44 Modifying nested dictionary/alist type data Paul Morris
@ 2016-04-15 14:00 ` Wette, Matthew R (3441)
2016-04-15 17:20 ` Andreas Rottmann
1 sibling, 0 replies; 4+ messages in thread
From: Wette, Matthew R (3441) @ 2016-04-15 14:00 UTC (permalink / raw)
To: guile-user@gnu.org
> On Apr 14, 2016, at 4:44 PM, Paul Morris <paul@paulwmorris.com> wrote:
> But if you have nested alists like this
>
> (define my-alist ‘((aaa . ((bbb . ((ccc . 10)))))))
>
> and you want to change ccc, then the “set!” trick doesn’t help. (...what would you “set!”?) So what’s the best approach here for such nested data structures? Maybe I should just use nested hash maps instead? Sorry if I’m missing something obvious.
Not sure I understand this entirely, but have you looked at boxes? Look at SRFI-111 in the Guile Reference.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Modifying nested dictionary/alist type data
2016-04-14 23:44 Modifying nested dictionary/alist type data Paul Morris
2016-04-15 14:00 ` Wette, Matthew R (3441)
@ 2016-04-15 17:20 ` Andreas Rottmann
2016-04-16 14:37 ` Paul Morris
1 sibling, 1 reply; 4+ messages in thread
From: Andreas Rottmann @ 2016-04-15 17:20 UTC (permalink / raw)
To: Paul Morris; +Cc: guile-user
Paul Morris <paul@paulwmorris.com> writes:
> Hi, I’m rewriting one of LilyPond's C++ routines in Guile/Scheme in
> order to customize it for my own use, and it uses some nested
> dictionary/map/alist-style data structures that you can modify using
> something like this in C++:
>
> mydata[aaa][bbb].ccc = 10;
>
Depending on the number of entries in each nesting level, and other
(performance/space) tradeoffs, hash tables might be a good fit as an
associative array data structure:
https://www.gnu.org/software/guile/manual/html_node/Hash-Tables.html
http://srfi.schemers.org/srfi-69/srfi-69.html
http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-14.html
Guile 2.0 supports all three of these APIs -- choosing between them is
mostly important if you care about portability to different Scheme
implementations (which I'd guess is not high priority in the context of
lilypond).
HTH, Rotty
--
Andreas Rottmann -- <http://rotty.xx.vu/>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-04-16 14:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-14 23:44 Modifying nested dictionary/alist type data Paul Morris
2016-04-15 14:00 ` Wette, Matthew R (3441)
2016-04-15 17:20 ` Andreas Rottmann
2016-04-16 14:37 ` Paul Morris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).