Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KvpValue::Type::LIST and KvpFrame <-> SCM #1311

Merged
merged 2 commits into from Apr 10, 2022

Conversation

christopherlam
Copy link
Contributor

@christopherlam christopherlam commented Apr 5, 2022

  (let ((book (gnc-get-current-book)))
    (define (try path)
      (format #t "retrieve ~s ~s\n"
              path (qof-book-get-option book path)))
    (qof-book-set-option book "bla" '("top" "lvl1a"))
    (qof-book-set-option book "arg" '("top" "lvl1b"))
    (qof-book-set-option book "baf" '("top" "lvl1c" "lvl2" "lvl3"))
    (qof-book-set-option book '"baf" '("top" "lvl1c" "lvl2" "lvl3"))
    (qof-book-set-option book #("arg" "1" "2" 3) '("top" "lvl1d"))
    (qof-book-set-option book
                         '(("a" . "alpha")
                           ("b" . "beta")
                           ("c" . "charlie"))
                         '("top" "lvl1e"))
    (try '("top"))
    (try '("top" "lvl1a"))
    (try '("top" "lvl1b"))
    (try '("top" "lvl1c"))
    (try '("top" "lvl1c" "lvl2"))
    (try '("top" "lvl1c" "lvl2" "lvl3"))
    (try '("top" "lvl1c" "lvl2" "error"))
    (try '("top" "lvl1d"))
    (try '("top" "lvl1e"))
    (try '("top" "lvl1e" "a"))
    (try '("top" "error")))

outputs

retrieve ("top") (("lvl1a" . "bla") ("lvl1b" . "arg") ("lvl1c" ("lvl2" ("lvl3" . "baf"))) ("lvl1d" . #("arg" "1" "2" 3)) ("lvl1e" ("a" . "alpha") ("b" . "beta") ("c" . "charlie")))
retrieve ("top" "lvl1a") "bla"
retrieve ("top" "lvl1b") "arg"
retrieve ("top" "lvl1c") (("lvl2" ("lvl3" . "baf")))
retrieve ("top" "lvl1c" "lvl2") (("lvl3" . "baf"))
retrieve ("top" "lvl1c" "lvl2" "lvl3") "baf"
retrieve ("top" "lvl1c" "lvl2" "error") #f
retrieve ("top" "lvl1d") #("arg" "1" "2" 3)
retrieve ("top" "lvl1e") (("a" . "alpha") ("b" . "beta") ("c" . "charlie"))
retrieve ("top" "lvl1e" "a") "alpha"
retrieve ("top" "error") #f

@christopherlam christopherlam force-pushed the maint-progress2 branch 2 times, most recently from 2420b6e to ef0a718 Compare April 6, 2022 13:03
@christopherlam
Copy link
Contributor Author

christopherlam commented Apr 6, 2022

  • more capable kvp<->SCM conversion, can convert KvpFrame into a nested assoc-list
  • can also convert KvpValue::Type:GLIST into an SCM vector

An alternate mapping would be: scheme hash table to/from KVP frames, and scheme lists to/from GNC_TYPE_LIST. The main disadvantage in this case is that hash tables are less readable in scheme. Otherwise it's a better mapping.

@christopherlam christopherlam force-pushed the maint-progress2 branch 7 times, most recently from c5025fa to 9304afe Compare April 7, 2022 14:27
@christopherlam
Copy link
Contributor Author

So we have two options:

  • KvpFrame == SCM list-of-pairs; KvpValue::Type::GLIST == SCM list
  • KvpFrame == SCM hash-table; KvpValue::Type::GLIST == SCM vector

There's potentially a third option which offers the readability of lists in guile:

  • KvpFrame == SCM list-of-pairs; KvpValue::Type::GLIST == SCM list of non-pairs

This is possible because there's no direct mapping of SCM pair onto any KvpValue type. So, the scm_to_kvp_value_ptr test will be if (scm_is_list (val) && scm_is_true (scm_map (scm_c_eval_string ("pair?"), val))) convert into a KvpFrame.

@christopherlam christopherlam force-pushed the maint-progress2 branch 2 times, most recently from 3a9b5b7 to ce9cfca Compare April 8, 2022 09:51
@christopherlam christopherlam changed the title kvp-frame->SCM and gncEntry kvp-frame<->SCM Apr 8, 2022
@christopherlam christopherlam changed the title kvp-frame<->SCM KvpValue::Type::LIST and KvpFrame <-> SCM Apr 8, 2022
Copy link
Member

@jralls jralls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start.

bindings/guile/gnc-kvp-guile.cpp Outdated Show resolved Hide resolved
bindings/guile/test/test-scm-apputils.scm Outdated Show resolved Hide resolved
bindings/guile/test/test-scm-apputils.scm Outdated Show resolved Hide resolved
bindings/guile/gnc-kvp-guile.cpp Outdated Show resolved Hide resolved
bindings/guile/gnc-kvp-guile.cpp Outdated Show resolved Hide resolved
@christopherlam christopherlam force-pushed the maint-progress2 branch 2 times, most recently from d26c0ad to 6d77c3c Compare April 8, 2022 23:24
… frame

returns a KvpFrame into a nested list of pairs
returns a KvpValue GLIST into a list
@code-gnucash-org code-gnucash-org merged commit d022651 into Gnucash:maint Apr 10, 2022
@christopherlam christopherlam deleted the maint-progress2 branch April 10, 2022 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants