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

Port of clojure.pprint to Basilisp #895

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ikappaki
Copy link
Contributor

@ikappaki ikappaki commented Mar 18, 2024

Hi,

can you please review patch to port clojure.pprint to Basilisp. It addresses #513

The approach taken aimed at minimizing modifications to the original code. There are two commits in this PR, the first is the original code taken from clojure.pprint, the second has all the necessary changes I've made to make it work in Basilisp.

The code spans across seven files loaded into the pprint namespace. I've organized them under basilisp.contrib.pprint to denote that this is a contributed package, rather than something we've implemented from scratch. However, I don't have a specific preference for the location of these files.

Since these files are load'ed at runtime rather than being required or imported, they inevitably cause noticeable delays when the namespace is initially imported, in line with the constraints outlined by #878. Two potential solutions come to mind to necessitate these files at compile time:

  1. Transform them into regular namespaces that are required by the primary pprint namespace, as suggested. However, I would then need to figure out a way to integrate these variables into the top-level pprint namespace. I'm not sure there is a super use like form that will not only bring them into the basilisp.pprint namespace but also export them as public variables from there?

  2. Merge the files into a single extensive pprint.lpy file.

What do you think?

The pprint tests follow the same approach and also need to be reorganized as above.

The list of changes over the original implementations are

pprint.lpy

utilities.lpy

column-writer.lpy

  • Changes are mostly around updating Clojure types to basilisp (e.g. String to py/str).

pprint_base

  • Introduce new *print-sort-unordered-colls* var, to order keys in
    map, useful for the testing phase.

cl_format.lpy

dispatch.lpy

  • implement support for the new *print-sort-unordered-colls* var, so that prinout map output is predictable for testing
  • Commented out agent print out support, Agents #413
  • Commented out clojure.lang.IPending print out support (not sure what that is)
  • Commented out .isArray support (not sure if this is relevant/supported?)
  • Commented out basilisp.lang.interfaces/PersistentQueue dispatch method, since it is not available

print_table.lpy

tests

`test_helper.lpy

  • introduce platform-newlines

test_cl_format.lpy

  • ~C use pr to print out characters and thus are output as strings rather than characters.
  • Commented out Decimal128 tests since they are not support in Python

Thanks

@ikappaki ikappaki marked this pull request as draft March 18, 2024 22:21
@ikappaki
Copy link
Contributor Author

I put temporary hack in the pprint tests (test_pprint.lpy, contrib/pprint/test_pretty.lpy and contrib/test_cl_format.lpy) because they may be called individually with coverage run (and as such break), instead of loaded by test_pprint.lpy as a whole. It should be resolved once we decide what to do with the `load'ed files.

@ikappaki ikappaki marked this pull request as ready for review April 7, 2024 13:35
@ikappaki
Copy link
Contributor Author

ikappaki commented Apr 7, 2024

Hi, I've taken the liberty to concatenate the loaded files in contrib.pprint under pprint.clj and test_pprint.clj. This significantly boost loading performance, and shouldn't affect maintainability because no significant changes are expected, the clj code is quite stable and battle tested for many years now.

It is prime for review.

Thanks

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

1 participant