-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Comments
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. |
Any suggestions on places to start looking for existing (and simple) pretty-print implementations? |
@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 Thanks! |
@kanaka I tried running your example. Where is 'seq' implemented? |
@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. |
Answering kanaka#165.
Answering kanaka#165.
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
The text was updated successfully, but these errors were encountered: