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

GITFNS gets prc information in JSON form #1689

Closed
wants to merge 1 commit into from

Conversation

rmkaplan
Copy link
Contributor

prc uses the simple JSON parser in the new lispusers file JSON to convert the json string into a lisp data structure. Maybe the commonlisp package YASON that Matt looked at would be more general, but perhaps also requires more understanding.

With this change, drafts should be marked with D, approves should be marked with A.

prc uses the simple JSON parser in the new lispusers file JSON to convert the json string into a lisp data structure.  Maybe the commonlisp package YASON that Matt looked at would be more general, but perhaps also requires more understanding.

With this change, drafts should be marked with D, approves should be marked with A.
Copy link
Member

@masinter masinter left a comment

Choose a reason for hiding this comment

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

I'm delighted to see an attempt at a JSON parser but uncomfortable with the chosen representation in Lisp of the JSON results.

In Lisp, JSON values can be represented as Lisp objects. Here's a brief overview of how JSON is represented in Lisp:
I asked "how do people represent JSON in LIsp" and got:

  • Keywords: JSON uses three keywords: true, null, false. In Lisp, true is represented by the symbol t. By default, the remaining two are represented, respectively, by the symbols :null and :false¹.
  • Numbers: JSON only has floating-point numbers. They can represent both Lisp integers and Lisp floating-point numbers¹.
  • Strings: JSON strings are always Unicode strings encoded in UTF-8. Lisp strings can contain non-Unicode characters¹.
  • Arrays: JSON has only one sequence type, the array. JSON arrays are represented using Lisp vectors¹.
  • Objects: JSON has only one map type, the object. JSON objects are represented using Lisp hashtables, alists or plists¹.

Please note that while any JSON value can be converted to a Lisp object, the reverse is not always true¹. If some Lisp object can't be represented in JSON, the serialization functions will signal an error of type wrong-type-argument¹.

There are libraries like YASON for Common Lisp and GNU Emacs Lisp Reference Manual for Emacs Lisp that provide functions to convert between Lisp objects and JSON values¹². These libraries also handle parsing and generating JSON values¹².

Source: Conversation with Bing, 4/30/2024
(1) Parsing JSON (GNU Emacs Lisp Reference Manual). https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-JSON.html.
(2) YASON - A JSON encoder/decoder for Common Lisp - GitHub Pages. http://phmarek.github.io/yason/.
(3) Parsing and Generating JSON Values - Elisp - W3cubDocs. https://docs.w3cub.com/elisp/parsing-json.html.
(4) JSON and Lisp-Like Queries | Skirtle's Den. https://www.skirtlesden.com/articles/json-lisp-queries.

@MattHeffron
Copy link
Contributor

Just to be clear... In the Pull Request 1638, my commit c3b77a1 does not use YASON. I use the jq "GO template" method to convert the JSON array of PR info, to a string of a lisp list of p-lists, one per PR, and then used READSTRING to convert it to actual lisp data structures.

@rmkaplan
Copy link
Contributor Author

rmkaplan commented May 1, 2024 via email

@rmkaplan
Copy link
Contributor Author

rmkaplan commented May 1, 2024

The UTF-8 encoding comes for free with our Unicode mappings and UTF-8 external format. The externalformat of the GITFNS command stream is provided by (SYSTEM-EXTERNALFORMAT), which has some UNIX-GETENV heuristics to guess whether UTF-8 is correct. If UTF-8 is specified in the JSON standard, then the low-level GITFNS functions should just assert it, at least when --json is specified in the call. Should that be done?

  • Strings: JSON strings are always Unicode strings encoded in UTF-8. Lisp strings can contain non-Unicode characters¹.

@masinter
Copy link
Member

masinter commented May 1, 2024

I'm tempted to approve #1638 rather than bake in the design choices in JSON (because I think we need JSON to do modern APIs).

I think property lists are marginally better than alists for representing JSON objects.

We may find sooner than expected the results of queries needing Emoji support.
I was thinking about mapping unicode characters that have no XCCS equivalent into the private use area, and then replacing the character with a "Unicode image object" which would display properly and might also map back to the original unicode when exporting.

@rmkaplan
Copy link
Contributor Author

rmkaplan commented May 1, 2024 via email

@MattHeffron
Copy link
Contributor

MattHeffron commented May 2, 2024 via email

@rmkaplan
Copy link
Contributor Author

rmkaplan commented May 2, 2024

If this works for other people (prc menu's have a D for drafts, A for approved), then let's approve this even with my simple seems-to-work-at-least-in-this-case JSON parser. We can easily switch over later if we settle on one of the commonlisp packages.

I want to get this out of the way, so I can push some other changes I have been making to the GITFNS prc interface, with better management of the prc menu.

@masinter
Copy link
Member

masinter commented May 2, 2024

keyword plists are better because
*cdr-coding makes rplacd more complicated,

  • fewer odd error cases
  • are everywhere in CL for keyword arguments
  • can be copied with APPEND

@rmkaplan
Copy link
Contributor Author

rmkaplan commented May 2, 2024 via email

@nbriggs
Copy link
Contributor

nbriggs commented May 2, 2024

I'd hope that the RPLACD opcode does not have implementation errors - yes, it's "more complicated", but are we worrying about the complexity of the implementation that is now complete?

@rmkaplan
Copy link
Contributor Author

rmkaplan commented May 2, 2024 via email

@rmkaplan
Copy link
Contributor Author

rmkaplan commented May 2, 2024

@MattHeffron , I've lost track of where you put your double-quote updates to GITFNS. If you point me to it, I'll merge those changes into my current version.

@MattHeffron
Copy link
Contributor

@MattHeffron
Copy link
Contributor

Superseded by #1695

@MattHeffron MattHeffron closed this May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants