Thread overview | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 22, 2015 Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Big update to Scriptlike, v0.9.4: https://github.com/Abscissa/scriptlike Scriptlike is a library to help you write script-like programs in D. The two highlights in this release are string interpolation and a full set of examples in the documentation. Also of note are the new functions removePath and tryRemovePath which can be used to delete files (like remove) *or* directories (like rmdirRecurse). Full changelog: http://semitwist.com/scriptlike/changelog.html ===================== String Interpolation: ===================== https://github.com/Abscissa/scriptlike#string-interpolation AFAICT, a string mixin is necessary to accomplish this in D, but otherwise it works much like other languages: -------------------------------------------- // Output: The number 21 doubled is 42! int num = 21; writeln( mixin(interp!"The number ${num} doubled is ${num * 2}!") ); -------------------------------------------- The interpolated sections are handled via std.conv.text(), so they accept any type. Bikeshedding requested! I'm not 100% sold on the name "interp" for this long-term. Suggestions welcome. ========= Examples: ========= https://github.com/Abscissa/scriptlike https://github.com/Abscissa/scriptlike/blob/master/USAGE.md https://github.com/Abscissa/scriptlike/tree/master/examples The homepage/readme now provides sample code demonstrating all of Scriptlike's various features. The second link above demonstrates suggested practices for how to use Scriptlike in a D-based script. And finally, all examples are included as actual runnable programs (all automatically tested by "dub test", to ensure continued freshness). ====================== All changes in v0.9.4: ====================== - Fixed: Previous release broke the unittest script when dub test support was added. - Fixed: In echo mode, several functions would echo the wrong "try*" or non-"try*" version. Ex: run echoed tryRun, and tryRename echoed rename. - Fixed: Path and buildNormalizedPathFixed now convert back/forward slashes to native on BOTH Windows and Posix, not just on Windows. - Fixed: Some links within changelog and API reference were pointing to the reference docs for Scriptlike's latest version, instead of staying within the same documentation version. This made archived docs for previous versions difficult to navigate. - Enhancement: #17,#20: Added usage examples to readme. - Enhancement: Add interp for interpolated strings: string s = mixin( interp!"Value is ${variableOrExpression}" ) - Enhancement: Add removePath/tryRemovePath for deleting a path regardless of whether it's a file or directory. (Calls remove for files and rmdirRecurse for directories.) - Enhancement: Add a Path-accepting overload of escapeShellArg for the sake of generic code. - Enhancement: When runCollect throws, the ErrorLevelException now includes and displays the command's output (otherwise there'd be no way to inspect the command's output for diagnostic purposes). - Enhancement: Greatly extended and improved set of tests. |
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Tuesday, 22 September 2015 at 20:18:48 UTC, Nick Sabalausky wrote:
> --------------------------------------------
> // Output: The number 21 doubled is 42!
> int num = 21;
> writeln(
> mixin(interp!"The number ${num} doubled is ${num * 2}!")
> );
> --------------------------------------------
What about:
void echo(T)()
{
writeln(mixin(interp!T));
}
At least it saves some typing.
|
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sebastiaan Koppe | On Wednesday, 23 September 2015 at 01:24:54 UTC, Sebastiaan Koppe wrote:
> What about:
>
> void echo(T)()
> {
> writeln(mixin(interp!T));
Won't work because it won't be able to see the local variables you want to interpolate.
|
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Wednesday, 23 September 2015 at 01:45:03 UTC, Adam D. Ruppe wrote:
> On Wednesday, 23 September 2015 at 01:24:54 UTC, Sebastiaan Koppe wrote:
>> What about:
>>
>> void echo(T)()
>> {
>> writeln(mixin(interp!T));
>
> Won't work because it won't be able to see the local variables you want to interpolate.
facepalm... ofcourse...
Well, you could still get rid of the writeln.
|
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | Am 22.09.2015 um 22:18 schrieb Nick Sabalausky:
> =====================
> String Interpolation:
> =====================
> https://github.com/Abscissa/scriptlike#string-interpolation
>
> AFAICT, a string mixin is necessary to accomplish this in D, but
> otherwise it works much like other languages:
>
> --------------------------------------------
> // Output: The number 21 doubled is 42!
> int num = 21;
> writeln(
> mixin(interp!"The number ${num} doubled is ${num * 2}!")
> );
> --------------------------------------------
>
> The interpolated sections are handled via std.conv.text(), so they
> accept any type.
>
> Bikeshedding requested! I'm not 100% sold on the name "interp" for this
> long-term. Suggestions welcome.
>
An alternative idea would be to mix in a local "writeln" function, which can then be used multiple times without syntax overhead:
mixin template interp()
{
void iwriteln(string str)()
{
// pretend that we actually parse the string ;)
write("This is ");
write(somevar);
writeln(".");
}
}
void main()
{
int somevar = 42;
mixin interp;
iwriteln!("This is ${somevar}.");
}
|
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On 2015-09-22 22:18, Nick Sabalausky wrote: > ===================== > String Interpolation: > ===================== > https://github.com/Abscissa/scriptlike#string-interpolation > > AFAICT, a string mixin is necessary to accomplish this in D, but > otherwise it works much like other languages: > > -------------------------------------------- > // Output: The number 21 doubled is 42! > int num = 21; > writeln( > mixin(interp!"The number ${num} doubled is ${num * 2}!") > ); > -------------------------------------------- > > The interpolated sections are handled via std.conv.text(), so they > accept any type. > > Bikeshedding requested! I'm not 100% sold on the name "interp" for this > long-term. Suggestions welcome. Different bikeshedding: I would prefer to make the curly braces optional if it only contains a symbol. -- /Jacob Carlborg |
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On 2015-09-22 22:18, Nick Sabalausky wrote: > Big update to Scriptlike, v0.9.4: > https://github.com/Abscissa/scriptlike > > Scriptlike is a library to help you write script-like programs in D. One thing that really bugs me in Phobos, Scriptlike seems to have the same problem, is that there are three (!!!) different functions to remove something from the file system. Give me just one function that removes everything, regardless if it's a file, directory and if it's empty or not. -- /Jacob Carlborg |
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 23-Sep-2015 09:30, Jacob Carlborg wrote: > On 2015-09-22 22:18, Nick Sabalausky wrote: >> Big update to Scriptlike, v0.9.4: >> https://github.com/Abscissa/scriptlike >> >> Scriptlike is a library to help you write script-like programs in D. > > One thing that really bugs me in Phobos, Scriptlike seems to have the > same problem, is that there are three (!!!) different functions to > remove something from the file system. Give me just one function that > removes everything, regardless if it's a file, directory and if it's > empty or not. > Bugzilla issue with this enhancement would help a lot with this ;) And a PR would make it happen... -- Dmitry Olshansky |
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dmitry Olshansky | On 2015-09-23 08:32, Dmitry Olshansky wrote: > Bugzilla issue with this enhancement would help a lot with this ;) > > And a PR would make it happen... https://issues.dlang.org/show_bug.cgi?id=15102 I'm too lazy for a PR. -- /Jacob Carlborg |
September 23, 2015 Re: Scriptlike v0.9.4 - Perl-like interpolated strings, full examples and more. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Wed, Sep 23, 2015 at 08:30:18 +0200, Jacob Carlborg via Digitalmars-d-announce wrote:
> One thing that really bugs me in Phobos, Scriptlike seems to have the same problem, is that there are three (!!!) different functions to remove something from the file system. Give me just one function that removes everything, regardless if it's a file, directory and if it's empty or not.
Be aware that you will have to pay an extra lstat call for such a function so that *it* can call the right function. It certainly shouldn't replace the existing functions.
--Ben
|
Copyright © 1999-2021 by the D Language Foundation