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

Add formatted string output #154

merged 11 commits into from Dec 31, 2017


None yet
2 participants

hellerve commented Dec 30, 2017

This PR fixes #108 and adds formatted strings. It is fairly big and introduces a breaking change, so review with caution!

It adds the dynamic functions +, -, *, and / and the dynamic module String containing the functions char-at, index-of, substring, and count. I refrained from making count generic, but that could be discussed as well.

I also made registering new commands more convenient, with an arity that then gets checked at dispatch time, which is a little more convenient than writing an error branch for every function. Multi-arity commands are TBD.

I also added the interface format, which takes a string and a thing and returns the string representation of that thing (so its sprintf with one argument). This is used in the fmt macro, which splits sprintf-like strings at compile time and transforms it into a concatenation. NOTE: This is possibly expensive!

There are also a few minor things, like making = for macros work on Chars and such.



This comment has been minimized.


eriksvedang commented Dec 30, 2017

This is so cool! From reading the code briefly it seems like the fmt functions implemented in core.h will leak, since they take a non-ref String and don't do anything with it, right? They should probably take refs if there is no good reason not to.

I like the changes to addCommand, much cleaner!


This comment has been minimized.


hellerve commented Dec 30, 2017

Ah yes, that’s true. I hadn’t realized that that’s what’s going to happen, but it makes sense. I’ll fix it tomorrow.

@eriksvedang eriksvedang merged commit 288369b into carp-lang:master Dec 31, 2017

@hellerve hellerve deleted the hellerve:format branch Jan 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment