-
Notifications
You must be signed in to change notification settings - Fork 23
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
standardize all stringification API's around allocation-free binary $ operator + variadic strAppend #191
Comments
Yes, I agree. I want this. And we almost already have it. Please take a look at |
Super nice RFC, one minor correction, |
@disruptek had the awesome idea to transform |
I generally agree with this. I'm a bit hesitant about the new usage of the |
It was noticed on IRC that we already have the binary append operator and it's written as |
Perhaps "write" or "writeString" would be better? The problem with using |
Well, what I have in mind for quite some time now is the ability to forward varargs in a template without importing macros. That would also be really helpful to implement
That is not correct. There is still one temporary per call to echo. |
This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 30 days. |
API's like
$(a: MyType)
(which are what we almost exclusively use in stdlib, nimble etc) do not compose efficiently because they create temporaries, allocate etc.instead, we should build API's around appending. This gives best of both worlds:
$a
wherever it's convenient, thanks a single unary$
overload:note
outplace
operator is not relevant to this discussion, we don't want to use outplace operator for something so common like stringificationproposal part 1: binary $ operator
the API to stringify
MyType
shall be:example
proposal part 2: variadic strAppend
the following variadic
strAppend
is always preferable to&
+$
, and often preferable tovarargs[string,$]
following macro
strAppend
advantageously replaces many patterns, yet is as efficient as can be.In particular, it allows writing a more efficient
echo(a: varargs[string, $])
andwrite(a: File, args: varargs[string, $])
, without introducing a bunch of temporaries.these advantageously replace varargs[string,$] versions of system.echo, system.write:
usage
note
I have a WIP that would allow writing
strAppend
as a template instead of a macro, to avoid depending on macros.nim; in particular that means thatstrAppend
andecho
thus defined could be in system.nim (or alternatively for system.nim minimalists, hiding strAppend there, using it to redefine echo, and redefining strAppend in some other module, but IMO it just belongs in system since its ubiquitous, replacing"foo" & $bar
both performance wise and syntactically, using less operator noise (unlike both using & and $)).the way it works is it allows templates to iterate over a varargs.
links
The text was updated successfully, but these errors were encountered: