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

namespaced map output support #882

Closed
ikappaki opened this issue Feb 18, 2024 · 0 comments · Fixed by #883
Closed

namespaced map output support #882

ikappaki opened this issue Feb 18, 2024 · 0 comments · Fixed by #883
Labels
issue-type:enhancement New feature or request lang Issue pertaining to Basilisp language modules

Comments

@ikappaki
Copy link
Contributor

ikappaki commented Feb 18, 2024

Hi,

Basilisp does not have an option to print maps as namespaced maps, as in clojure with *print-namespace-maps*

e.g. in Basilisp always output the standard map format

basilisp.user=> #:x {:f 1 :y 2}
{:x/y 2 :x/f 1}

basilisp.user=> (prn #:x{:f 1, :y 2})
{:x/y 2 :x/f 1}

while Clojure can be controlled with *print-namespace-maps* (the namespace can come at the front of the map if all key entries belong to the same namespace)

user> #:x {:f 1 :y 2}
#:x{:f 1, :y 2}
user> (prn #:x{:f 1, :y 2})
#:x{:f 1, :y 2}
nil
user> (binding [*print-namespace-maps* false] (prn #:x{:f 1, :y 2}))
{:x/f 1, :x/y 2}
nil
user> (binding [*print-namespace-maps* true] (prn #:x{:f 1, :y 2}))
#:x{:f 1, :y 2}
nil
user> (binding [*print-namespace-maps* false] (prn {:x/f 1, :x/y 2}))
{:x/f 1, :x/y 2}
nil
user> (binding [*print-namespace-maps* true] (prn {:x/f 1, :x/y 2}))
#:x{:f 1, :y 2}
nil

This probably requires some work at obj.py:map_lrepr() that I plan to have a look at.

thanks

chrisrink10 added a commit that referenced this issue Feb 21, 2024
This PR introduces the `INamed` interface (similar to Clojure's `Named`)
which is applied to the Keyword and Symbol classes. Having an interface
for this allows us to perform type checking for relevant features (in
particular, the existence of a name or namespace) without needing the
import either class directly (thus avoiding circular dependencies).

I also added type annotations for the Lisp representation keyword
arguments (which is a useful addition ahead of #882 merging).

Fixes #884

Co-authored-by: Christopher Rink <christopher@ChristophersMBP.cjlocal>
@chrisrink10 chrisrink10 added this to the Release v0.1.0 milestone Feb 22, 2024
@chrisrink10 chrisrink10 added issue-type:enhancement New feature or request lang Issue pertaining to Basilisp language modules labels Feb 22, 2024
chrisrink10 pushed a commit that referenced this issue Mar 13, 2024
Hi,

could you please review draft support for the *print-namespace-maps*
dynamic variable. It resolves #882.

I implemented the support at the lowest `obj.py` level, though this
required to bring in the `keyword.py` and `symbol.py` modules resulting
to cyclic dependencies. Not sure how else to implement it, so any other
suggestions are most welcome.

I've also blindly followed the example of *print-dup* on how I ended
setup the variable in the cli/runtime/object .py files.

In addition, I've used a set to compare the printed output of the map
result with multiple k/v, exhaustively covering the possible orderings,
is there perhaps a better simpler way to do this? This currently is
prune to user errors.

Thanks

---------

Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue-type:enhancement New feature or request lang Issue pertaining to Basilisp language modules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants