-
Notifications
You must be signed in to change notification settings - Fork 139
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
Term and LeafAnswer serde serialization #2707
base: master
Are you sure you want to change the base?
Conversation
My 2c having hacked out a similar thing for trealla-js12: I ended up with pretty much the same structure as #2493 (comment), which I'm pretty happy with. For integers, I serialize directly to Footnotes |
trealla fam! ❤️ I didn't even know trealla-js existed, so cool! Love the TS bindings. Great work and thanks for the information! 👀 |
Thanks @jjtolton! One of my goals is to eventually provide a Typescript library where the backend implementation can be swapped between Trealla/Scryer, and I'd be happy to change my JSON internals to match what Scryer decides to make things easier to do that in the future. Just wanted to chime in that the path Scryer is taking looks good to me. |
That's great! I'm working on a similar thing with libscryer-clj. @bakaq is doing some phenomenal work with WASM right now, he even "beat me to the punch"! After that I'd like to add ClojureScript support for But ultimately I'd like to support Trealla as well! I'm working on embedding Prolog into video games, and if I ever make a console port, I think I will need to use Trealla! I hope we get to chat more about it. |
In #2825 I just made everything into { "type": "integer", "value": 100 }
{ "type": "integer", "value": "100000000000000000000000000000" } |
I agree. I’ve seen such an encoding scheme used in JSON-based document databases (DynamoDB) for the same reason. |
Well, serializing small ints as just |
I think it’s nice, the only potential issue is some ambiguity with floats if they also get serialized as non-wrapped numbers. JS treats them the same of course so it’s no problem there. Tagging them can provide a hint to typed languages to avoid having to do heuristics (“does it have a dot?”). This is basically ambiguity built into JSON so I don’t think there’s a right or wrong answer. |
As a lot of things moved around, I thought making a new PR would be easier than rebasing #2493. This also gives us a clean slate to discuss. The old PR was getting a bit too big, and Github is notoriously bad for big threads of discussions in issues/PRs.
This basically gets to the same point that #2493 was, but with a change to rationals following #2505 (comment) (basically now they are serialized as
{"rational": {"numerator": ..., "denominator": ...}}
), and also without migrating the integration tests. I believe this will still change a bunch so I defer migrating the integration tests (which depend on serialization) to after this gets merged. This also doesn't have the deserialization from #2505.@jjtolton, if you really want to continue the JSON API route in #2465 you should rebase onto this. I feel maybe just doing C APIs for dealing with
Term
(and with that wrapping libraries can do JSON themselves in whatever way they want) will be a faster path to merging than waiting to reach consensus on the serialization format here.Most relevant points in the discussion until now, to recap:
f64
for all numbers), maybe it makes sense to always encode numbers as strings, tough it seems kinda unfortunate to force users to parse numbers even for small integers: Value and QueryResolution serialization with serde #2493 (comment) Value and QueryResolution serialization with serde #2493 (comment)Also, tip when writing JSON on Github: use json5 in codeblocks. It allows things like comments without freaking out. Compare: