-
Notifications
You must be signed in to change notification settings - Fork 135
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
Donating a library for reasoning about CBOR #2800
Comments
For point S4.ii, this was recently fixed in #2777, as I had also noticed this incorrect behavior while refactoring the code around arithmetic operators. The condition for the bug was that the lhs had to be represented as a S4.i should become an issue on its own. I don't have a say in these kinds of decisions, but I will point out that having more code in any project (and especially a programming language) usually comes at the cost of:
|
... et dona ferrentes. In any case it seems that some aspects would be best issued as separate items. |
Regarding this point: Indeed bytes and codes are both integers. More precisely, a byte is: 3.22 byte: An integer in the range [0..255] (see 7.1.2.1). For comparison, a code is an integer from the collating sequence: 3.34 collating sequence: An implementation defined ordering defined on the set C of characters (see 6.6). For instance, in Scryer Prolog, the code of 海 is 28023 (the character's Unicode code point), well outside the range of a byte: ?- char_code(海, Code). Code = 28023. The most compact way to represent sequences of bytes in Scryer Prolog is to use lists of characters with codes in the range 0..255. You can specify the option |
Very cool, thanks for sharing. Do you also plan to support CDDL and some special tags from https://www.iana.org/assignments/cbor-tags/cbor-tags.xml ? |
About the "gift may actually be a burden". (S4.i)
Thanks for the entire explanation. Unfortunately, there is no plan for CDDL support. If I were to add support to CDDL, I would add an extra argument to For tags and simple values, what I could do is to support a I intend it to be a simple library for quickly lifting one out of raw bytes without losing any possible representation. (Also, my vacation time is short and I am attempting to keep projects' scope small) I am happy enough for closing the issue, Another option is to wait for me to open an issue about (S4.i). |
The texts I quoted are from the Prolog ISO standard, and the numbers refer to sections in the standard, such as: 7.1.2.1 Bytes B, a set of bytes, is a subset of I where: B = {i ∈ I | 0 ≤ i ≤ 255}
Please do leave the issue open, since it is not yet resolved and may be interesting also for other contributors, to study and use the code and functionality. Please do consider adapting the tile to (for example): "Donating a library for reasoning about CBOR" so that it is easier to find in the future. @mthom: May I also suggest to tag this issue with a new tag that is adequate for issues like this one, for example |
I'm repeating myself, but I think it would be very beneficial if there would be a public repository of ISO Prolog modules compatible with Scryer Prolog, with relaxed submission quality requirements, so new libraries wouldn't stuck in never-ending reviews. And mature libraries can be promoted to Scryer's main repo. |
But be sure to shop around! |
See how to get it. |
I am trying out this idea:
It does not work for this library, because I believe that a declarative version of |
Please note that |
Sorry, I misused the word "declarative". I meant something like |
which also produces errors instead of failing, like
|
Yes, they may still produce errors. I like type errors. ?- char_code(X, Y).
error(instantiation_error,char_code/2).
?- X = a, char_code(X, Y).
X = a, Y = 97.
?- #X #= #Y + 1.
clpz:(Y+1#=X). |
You can use ?- [user].
:- use_module(library(freeze)).
char_code_(Char, Code) :-
freeze(Char, char_code(Char, Code)),
freeze(Code, char_code(Char, Code)).
?- char_code_(a, C).
C = 97.
?- char_code_(C, 97).
C = a.
?- char_code_(Char, Code).
freeze:freeze(Char,char_code(Char,Code)), freeze:freeze(Code,char_code(Char,Code)).
?- char_code_(Char, Code), Char = a.
Char = a, Code = 97.
?- char_code_(Char, Code), Code = 97.
Char = a, Code = 97. With Also, just so you know, we have a relatively active Github Discussions forum that may be more appropriate for questions like this. |
Thanks! |
Hi, I would like to donate a library for Scryer Prolog.
Namely, the library is Kiyoshi364/cbor-pl.
(Here is the fixed link for future preservation reasons: fixed link)
The library itself still needs some tweaks.
I will ask general questions about "donating libraries", then I will briefly talk about the library itself.
General Library Donation Questions
About cbor-pl
It is a library for reason about CBOR (RFC8949).
CBOR is a binary representation format for structured data, supporting "JSON-like" objects.
The library establishes a prolog "datastructure" for representing a CBOR Item (
cbor/1
) andprovides a DCG
cbor_item//1
for describing the binary representation for the CBOR Item.Specific notes and remarks about cbor-pl
(S1) It depends on
library(clpz)
to support reading/decoding and writing/encoding using the same DCG.Using the same DCG for reading and writing is good for many declarative reasons,
but I consider CLPZ a big dependency, so it is worth noting that.
(S2) It does not integrate well with
library(pio)
.The DGC
cbor_item//1
describes lists of bytes [1] (numbers in the range [0, 255] or [0x00, 0xFF]) andthe
library(pio)
works with lists of chars (single letter atoms).(S3) It does not have good support for floating point numbers.
I (the implementor) do not know how to reason about floating point numbers and their binary representation inside Prolog.
Currently, the library only supports the binary representation.
There is an easy patch (given that the reasoning is done): change the implementation for
size_value_float/3
.Its current implementation is similar to
size_value_float(S, V, F) :- S = _, V = F.
:S
is an atom to identity the float size (16, 32 or 64 bits)V
is the binary representation of the floatF
is the float represented in prolog form (examples:1.3
,0.123
)(S4) There are 2 "NOTE" comments in the implementation.
They may configure bugs on the interpreter or library (such as CLPZ). If so, I should make separate issues for them.
{ true }
I inserted inside a DCG clause. The{ true }
magically makes the test pass.I imagine it has something to do with tail-call/last-call optimization.
#R #= #X * (2 ^ #I)
instead of#R #= #X << #I
, because for big numbers the shift makesR
negative.It appears to work in some directions, but not in others.
(S5) Currently, I have only documented the prolog "datastructure", I still intend to add documentation for behavior of
cbor_item//1
.Scryer Prolog has some way of turning a prolog file into a html file (to make library pages for the website).
If my documentation does not work well with it, please let me know.
Footnotes:
[1]: I'm considering a byte is similar to a code (see
get_code/1
,put_code/1
, ...). Possibly they are the same, I'm not sure.The text was updated successfully, but these errors were encountered: