July 29, 2018 stri: string format/interpolation library for D. how to embed variables into string like shell scripts | ||||
---|---|---|---|---|
| ||||
This library is very similar to Scala or shell scripts. - https://github.com/ShigekiKarita/stri/tree/master - https://docs.scala-lang.org/overviews/core/string-interpolation.html ## example import stri : s; // runtime/compile-time variables auto a = 1; enum _a0 = "D-lang"; struct A { static a = 0.123; } // you can use the default %s and custom ones e.g., %.3f mixin s!"${a} is one. ${_a0} is nice. ${A.a%.3f}" i; assert(i.str == "1 is one. D-lang is nice. 0.123"); |
July 29, 2018 Re: stri: string format/interpolation library for D. how to embed variables into string like shell scripts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Shigeki Karita | On Sunday, 29 July 2018 at 14:55:46 UTC, Shigeki Karita wrote: > This library is very similar to Scala or shell scripts. > > - https://github.com/ShigekiKarita/stri/tree/master > - https://docs.scala-lang.org/overviews/core/string-interpolation.html > > > ## example > > import stri : s; > > // runtime/compile-time variables > auto a = 1; > enum _a0 = "D-lang"; > struct A { > static a = 0.123; > } > > // you can use the default %s and custom ones e.g., %.3f > mixin s!"${a} is one. ${_a0} is nice. ${A.a%.3f}" i; > assert(i.str == "1 is one. D-lang is nice. 0.123"); Seems fairly similar to `interp` in scriptlike: https://github.com/Abscissa/scriptlike BTW it wouldn't be so hard to add string interpolation to the language and compiler, there have been two PRs now. This was the latest: https://github.com/dlang/dmd/pull/7988 I think someone just needs to take a bit of time and write a DIP, so that A&W can't say no ;-) |
Copyright © 1999-2021 by the D Language Foundation