View Single Post
Old 09-29-2018, 01:44 PM   #1
sweth
Connoisseur
sweth began at the beginning.
 
Posts: 68
Karma: 10
Join Date: May 2015
Device: Kindle Fire 7 (7G), Kindle PW (2G), Kindle Scribe
Arrays, capturing parens in GPM?

Is there any support for arrays in general program mode, to allow for doing things like summing multiple values without having the chain together a bunch of add()s (especially if the total number of values to add isn't known)? And, related, is there any way to use capturing parens in regexes (to populate an array)?

For a specific use case: whenever someone recommends a book to me, I create a stub entry in Calibre and tag it "recommended.persons-name.N" where N is a number reflecting how enthusiastic the recommendation was. Rather than having to periodically look through those formatless records periodically to see which ones were highly recommended, and go get those books, I'd love to have a custom column that could just show the sum of all of the Ns for that book. The closest I've been able to come up with, though, is

Code:
                        re(
                            list_re(
                                tags,
                                ',',
                                'recommended\..*\.[\d.]+',
                                ''
                            ),
                            'recommended\..*\.', ''
                        ),
which extracts the N from the first tag of that sort, but completely ignores subsequent ones. From the descriptions of re_group and list_re_group, I think those *might* allow some type of use of capturing parens that might obviate that re(list_re()) ugliness, but I can't for the life of me figure either of those functions out, and in either case it seems like they would only return one value.

Is what I'm trying to do possible?
sweth is offline   Reply With Quote