| Name | basilisp-pprint JSON |
| Version |
0.1.0
JSON |
| download |
| home_page | None |
| Summary | None |
| upload_time | 2024-09-25 20:57:04 |
| maintainer | None |
| docs_url | None |
| author | ikappaki |
| requires_python | <4.0,>=3.8 |
| license | None |
| keywords |
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
[](https://pypi.org/project/basilisp-pprint/) [](https://github.com/ikappaki/basilisp-pprint/actions/workflows/tests-run.yml)
# A Port of the Clojure Pretty Print Library to Basilisp
[Basilisp](https://github.com/basilisp-lang/basilisp) is a Python-based Lisp implementation that offers broad compatibility with Clojure. For more details, check out the [documentation](https://basilisp.readthedocs.io/en/latest/index.html).
## Overview
`basilisp-pprint` is a source code port of the `clojure.pprint` core library to [Basilisp](https://github.com/basilisp-lang/basilisp).
The `clojure.pprint` library provides pretty formatting capabilities for common Clojure data structures such as lists, maps, sets, vectors, as well as Clojure code. The library allows for customizable printing through various options and parameters.
`basilisp-pprint` provides these capabilities to Basilisp as an external library, allowing you to use it while the native `basilisp.pprint` support (note the dot in the name) is [still in development](https://basilisp.readthedocs.io/en/latest/api/pprint.html). This includes enhanced API features, such as the [cl-format](https://clojure.github.io/clojure/clojure.pprint-api.html#clojure.pprint/cl-format) function.
## Installation
To install `basilisp-pprint`, run:
```shell
pip install basilisp-pprint
```
## Usage
To use the library, require it as `basilisp-pprint.pprint` in your Basilisp code.
For general usage instructions, refer to the [`clojure.pprint documentation`](https://clojure.github.io/clojure/clojure.pprint-api.html).
## Examples
### Pretty Printing a Nested Map
```clojure
;; https://clojuredocs.org/clojure.pprint/pprint#example-542692d0c026201cdc326ec5
(require '[basilisp-pprint.pprint :as p])
(def big-map (zipmap
[:a :b :c :d :e]
(repeat
(zipmap [:a :b :c :d :e]
(take 5 (range))))))
;; => #'user/big-map
big-map
;; => {:e {:e 4 :a 0 :c 2 :d 3 :b 1} :a {:e 4 :a 0 :c 2 :d 3 :b 1} :c {:e 4 :a 0 :c 2 :d 3 :b 1} :d {:e 4 :a 0 :c 2 :d 3 :b 1} :b {:e 4 :a 0 :c 2 :d 3 :b 1}}
(p/pprint big-map)
;; {:e {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :a {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :c {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :d {:e 4, :a 0, :c 2, :d 3, :b 1},
;; :b {:e 4, :a 0, :c 2, :d 3, :b 1}}
```
### Pretty Printing Clojure Code
```clojure
;; https://clojuredocs.org/clojure.pprint/pprint#example-5b950e6ce4b00ac801ed9e8a
;;
;; get Clojure snippets to print nicely
(require '[basilisp-pprint.pprint :as p]
'basilisp.edn)
(def lost-formatting
"(defn op [sel] (condp = sel :plus + :minus - :mult *
:div / :rem rem :quot quot :mod mod))")
;; => #'user/lost-formatting
(p/with-pprint-dispatch
p/code-dispatch
(p/pprint
(basilisp.edn/read-string lost-formatting)))
;; (defn op [sel]
;; (condp = sel
;; :plus +
;; :minus -
;; :mult *
;; :div /
;; :rem rem
;; :quot quot
;; :mod mod))
```
### Pretty Printing with Metadata
```clojure
;; https://clojuredocs.org/clojure.pprint/pprint#example-6318f958e4b0b1e3652d765f
;;
;; pprint with metadata
(require '[basilisp-pprint.pprint :as p])
(binding [*print-meta* true]
(p/pprint ^{:hello :world} {}))
;; ^{:hello :world} {}
```
### Pretty Printing Tables
```clojure
;; https://clojuredocs.org/clojure.pprint/print-table#example-542692d6c026201cdc3270f1
;;
;; If there are keys not in the first row, and/or you want to specify only
;; some, or in a particular order, give the desired keys as the first arg.
(require '[basilisp-pprint.pprint :as p])
(p/print-table [:b :a] [{:a 1 :b 2 :c 3} {:b 5 :a 7 :c "dog"}])
;; | :b | :a |
;; |----+----|
;; | 2 | 1 |
;; | 5 | 7 |
```
### Using `cl-format`
```clojure
;; cl-format example
(require '[basilisp-pprint.pprint :as p])
(let [name "Alice"
born 1999
hobbies ["reading" "hiking" "hacking"]]
(-> (p/cl-format nil "Name: ~A~%Born: ~@R~%Hobbies: ~{~A~^, ~}~%"
name
born
hobbies)
print))
;; Name: Alice
;; Born: MCMXCIX
;; Hobbies: reading, hiking, hacking
```
## Development and Testing
The approach taken for this port was to make as few changes as possible to the original `clojure.pprint` source code in order to maintain consistency. While the current implementations is feature-complete and works quite well, it has not yet been fully optimized for Python.
To run the test suite, use the following command:
```shell
basilsp test
```
## License
This project is licensed under the Eclipse Public License 1.0. See the [LICENSE](LICENSE) file for details.
## Acknowledgments
@chrisrink10, for developing [Basilisp](https://github.com/basilisp-lang/basilisp) and ensuring API compatibility with Clojure, enabling smooth ports of Clojure source code to Python.
```
;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;; Author: Tom Faulhaber
;; April 3, 2009
;;
;; Porting to Basilisp initiated from Clojure,
;; based on the code available at
;; https://github.com/clojure/clojure/blob/08a2d9bdd013143a87e50fa82e9740e2ab4ee2c2/src/clj/clojure/pprint.clj
```
Raw data
{
"_id": null,
"home_page": null,
"name": "basilisp-pprint",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "ikappaki",
"author_email": "ikappaki@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/22/11/6a2d8d6845e96228b10e1b3a9b50dae5ce069f26639d075007ca817c4990/basilisp_pprint-0.1.0.tar.gz",
"platform": null,
"description": "[](https://pypi.org/project/basilisp-pprint/) [](https://github.com/ikappaki/basilisp-pprint/actions/workflows/tests-run.yml)\n\n# A Port of the Clojure Pretty Print Library to Basilisp\n\n[Basilisp](https://github.com/basilisp-lang/basilisp) is a Python-based Lisp implementation that offers broad compatibility with Clojure. For more details, check out the [documentation](https://basilisp.readthedocs.io/en/latest/index.html).\n\n## Overview\n`basilisp-pprint` is a source code port of the `clojure.pprint` core library to [Basilisp](https://github.com/basilisp-lang/basilisp).\n\nThe `clojure.pprint` library provides pretty formatting capabilities for common Clojure data structures such as lists, maps, sets, vectors, as well as Clojure code. The library allows for customizable printing through various options and parameters.\n\n`basilisp-pprint` provides these capabilities to Basilisp as an external library, allowing you to use it while the native `basilisp.pprint` support (note the dot in the name) is [still in development](https://basilisp.readthedocs.io/en/latest/api/pprint.html). This includes enhanced API features, such as the [cl-format](https://clojure.github.io/clojure/clojure.pprint-api.html#clojure.pprint/cl-format) function.\n\n## Installation\n\nTo install `basilisp-pprint`, run:\n\n```shell\npip install basilisp-pprint\n```\n\n## Usage\n\nTo use the library, require it as `basilisp-pprint.pprint` in your Basilisp code.\n\nFor general usage instructions, refer to the [`clojure.pprint documentation`](https://clojure.github.io/clojure/clojure.pprint-api.html).\n\n## Examples\n\n### Pretty Printing a Nested Map\n\n```clojure\n;; https://clojuredocs.org/clojure.pprint/pprint#example-542692d0c026201cdc326ec5\n(require '[basilisp-pprint.pprint :as p])\n\n(def big-map (zipmap\n [:a :b :c :d :e]\n (repeat\n (zipmap [:a :b :c :d :e]\n (take 5 (range))))))\n;; => #'user/big-map\n\nbig-map\n;; => {:e {:e 4 :a 0 :c 2 :d 3 :b 1} :a {:e 4 :a 0 :c 2 :d 3 :b 1} :c {:e 4 :a 0 :c 2 :d 3 :b 1} :d {:e 4 :a 0 :c 2 :d 3 :b 1} :b {:e 4 :a 0 :c 2 :d 3 :b 1}}\n\n(p/pprint big-map)\n;; {:e {:e 4, :a 0, :c 2, :d 3, :b 1},\n;; :a {:e 4, :a 0, :c 2, :d 3, :b 1},\n;; :c {:e 4, :a 0, :c 2, :d 3, :b 1},\n;; :d {:e 4, :a 0, :c 2, :d 3, :b 1},\n;; :b {:e 4, :a 0, :c 2, :d 3, :b 1}}\n```\n\n### Pretty Printing Clojure Code\n\n```clojure\n;; https://clojuredocs.org/clojure.pprint/pprint#example-5b950e6ce4b00ac801ed9e8a\n;;\n;; get Clojure snippets to print nicely\n(require '[basilisp-pprint.pprint :as p]\n 'basilisp.edn)\n\n(def lost-formatting\n \"(defn op [sel] (condp = sel :plus + :minus - :mult *\n :div / :rem rem :quot quot :mod mod))\")\n;; => #'user/lost-formatting\n\n(p/with-pprint-dispatch\n p/code-dispatch\n (p/pprint\n (basilisp.edn/read-string lost-formatting)))\n;; (defn op [sel]\n;; (condp = sel\n;; :plus +\n;; :minus -\n;; :mult *\n;; :div /\n;; :rem rem\n;; :quot quot\n;; :mod mod))\n```\n\n### Pretty Printing with Metadata\n\n```clojure\n;; https://clojuredocs.org/clojure.pprint/pprint#example-6318f958e4b0b1e3652d765f\n;;\n;; pprint with metadata\n(require '[basilisp-pprint.pprint :as p])\n\n(binding [*print-meta* true]\n (p/pprint ^{:hello :world} {}))\n;; ^{:hello :world} {}\n```\n\n### Pretty Printing Tables\n\n```clojure\n;; https://clojuredocs.org/clojure.pprint/print-table#example-542692d6c026201cdc3270f1\n;;\n;; If there are keys not in the first row, and/or you want to specify only\n;; some, or in a particular order, give the desired keys as the first arg.\n(require '[basilisp-pprint.pprint :as p])\n\n(p/print-table [:b :a] [{:a 1 :b 2 :c 3} {:b 5 :a 7 :c \"dog\"}])\n;; | :b | :a |\n;; |----+----|\n;; | 2 | 1 |\n;; | 5 | 7 |\n```\n\n### Using `cl-format`\n\n```clojure\n;; cl-format example\n(require '[basilisp-pprint.pprint :as p])\n\n(let [name \"Alice\"\n born 1999\n hobbies [\"reading\" \"hiking\" \"hacking\"]]\n (-> (p/cl-format nil \"Name: ~A~%Born: ~@R~%Hobbies: ~{~A~^, ~}~%\"\n name\n born\n hobbies)\n print))\n;; Name: Alice\n;; Born: MCMXCIX\n;; Hobbies: reading, hiking, hacking\n```\n## Development and Testing\n\nThe approach taken for this port was to make as few changes as possible to the original `clojure.pprint` source code in order to maintain consistency. While the current implementations is feature-complete and works quite well, it has not yet been fully optimized for Python.\n\nTo run the test suite, use the following command:\n\n```shell\nbasilsp test\n```\n\n## License\n\nThis project is licensed under the Eclipse Public License 1.0. See the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n@chrisrink10, for developing [Basilisp](https://github.com/basilisp-lang/basilisp) and ensuring API compatibility with Clojure, enabling smooth ports of Clojure source code to Python.\n\n```\n;;; pprint.clj -- Pretty printer and Common Lisp compatible format function (cl-format) for Clojure\n\n; Copyright (c) Rich Hickey. All rights reserved.\n; The use and distribution terms for this software are covered by the\n; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)\n; which can be found in the file epl-v10.html at the root of this distribution.\n; By using this software in any fashion, you are agreeing to be bound by\n; the terms of this license.\n; You must not remove this notice, or any other, from this software.\n\n;; Author: Tom Faulhaber\n;; April 3, 2009\n;;\n;; Porting to Basilisp initiated from Clojure,\n;; based on the code available at\n;; https://github.com/clojure/clojure/blob/08a2d9bdd013143a87e50fa82e9740e2ab4ee2c2/src/clj/clojure/pprint.clj\n```\n\n",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.1.0",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d12770f9600d854f696e01b04e799ac61ff07ddbb2ab7663c2b12c62e6c1c577",
"md5": "7e0a7d2b43dc8c2d3f787e77d8047cdc",
"sha256": "dc3f348cfd3d9dbc5994ef4b4a34c3333ace0e54b8afa3cf43b04d155c4f083a"
},
"downloads": -1,
"filename": "basilisp_pprint-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7e0a7d2b43dc8c2d3f787e77d8047cdc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 43939,
"upload_time": "2024-09-25T20:57:03",
"upload_time_iso_8601": "2024-09-25T20:57:03.350251Z",
"url": "https://files.pythonhosted.org/packages/d1/27/70f9600d854f696e01b04e799ac61ff07ddbb2ab7663c2b12c62e6c1c577/basilisp_pprint-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "22116a2d8d6845e96228b10e1b3a9b50dae5ce069f26639d075007ca817c4990",
"md5": "c548962ae599f4da59b8e8fa3a0efa34",
"sha256": "60776f130bf3a4dbe1adccdf3e3896f07cfa5316d4d3b81fd374a6ede2921d3b"
},
"downloads": -1,
"filename": "basilisp_pprint-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "c548962ae599f4da59b8e8fa3a0efa34",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 44355,
"upload_time": "2024-09-25T20:57:04",
"upload_time_iso_8601": "2024-09-25T20:57:04.716333Z",
"url": "https://files.pythonhosted.org/packages/22/11/6a2d8d6845e96228b10e1b3a9b50dae5ce069f26639d075007ca817c4990/basilisp_pprint-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-25 20:57:04",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "basilisp-pprint"
}