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

Pretty printing #165

Closed
ktodyruik opened this issue Feb 8, 2016 · 6 comments
Closed

Pretty printing #165

ktodyruik opened this issue Feb 8, 2016 · 6 comments

Comments

@ktodyruik
Copy link

Hi,

I just wrote some code in MAL and got back a pretty long s-expression. Has anybody looked at pretty printing in MAL? Would it be difficult to write a pprint function in MAL?

Kerry

@kanaka
Copy link
Owner

kanaka commented Feb 9, 2016

I'm not sure what you mean by "got back a pretty long s-expression". I haven't personally looked at pretty printing in mal. However, I don't think it should be too difficult. You can probably base it on another Lisp pretty printer. I think the main challenge you may run into is that mal currently is very limited in terms of string functions. So for example (count str) works in some implementations (e.g python and ruby at least) due to duck typing but will probably throw an exception in others. But if you get it working in those, then that will be good motivation to get better string support in other implementations. Also, the examples/ directory would be a good place for this once you have it working reasonably well.

@ktodyruik
Copy link
Author

Any suggestions on places to start looking for existing (and simple) pretty-print implementations?

kanaka added a commit that referenced this issue Feb 10, 2016
@kanaka
Copy link
Owner

kanaka commented Feb 10, 2016

@ktodyruik I added an rudimentary example pprint that support lists, vectors, and maps and scalar types: https://github.com/kanaka/mal/blob/master/examples/pprint.mal If you want to support functions, atoms, etc or intelligent line breaks you'll need to add that yourself but the example should help you get going. E.g. the example breaks every element of sequential data into it's own line. More sophisticated pprint implementations will try and fit sequential collections onto the same line unless their visual representation would be too wide (i.e. most pprint implementations have a max width settings that they try and stay under).

@kanaka kanaka closed this as completed Feb 10, 2016
@ktodyruik
Copy link
Author

@kanaka Thanks!

@ktodyruik
Copy link
Author

@kanaka I tried running your example. Where is 'seq' implemented?

@kanaka
Copy link
Owner

kanaka commented Feb 11, 2016

@ktodyruik seq/string? are new functionality that is currently in progress. The branch issue_166_string_ops has implementations of seq and string? for bash, c, clojure, coffeescript, ES6, JavaScript, Haxe, MATLAB, miniMAL, Python, and RPython. Try those. You can follow progress on implementation of seq/string? for other implementations in #166.

micfan pushed a commit to micfan/make-a-lisp that referenced this issue Nov 8, 2018
luelista pushed a commit to luelista/mal that referenced this issue Mar 10, 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

No branches or pull requests

2 participants