Why Phobos is cool

Bastiaan Veelo Bastiaan at Veelo.net
Fri Jun 26 09:04:00 UTC 2020


On Friday, 26 June 2020 at 05:39:59 UTC, H. S. Teoh wrote:
> 	# Why go through the trouble of creating an entire project just
> 	# to print Hello World? Just do it in a single line:
> 	echo 'import std;void main(){writeln("Hello world");}' | dmd 
> -run -
>
> 	# What's the value of PI again? Easy:
> 	echo 'import std;pragma(msg, PI);' | dmd -o- -
>
> 	# Test a single line of code to see if it works
> 	echo 'import std;void main(){writeln([1,2,3].canFind(1));}' | 
> dmd -run -
>
> And also, one-line tests of code in the current directory tree:
>
> 	# What's the type of that obscure symbol in module 'mymod'
> 	# again?
> 	echo 'import mymod;pragma(msg, typeof(mymod.someSymbol));' | 
> dmd -i -o- -
>
> 	# Does function myFun actually work with float arguments??
> 	echo 'import mymod;pragma(msg, is(typeof(myFun(3.14f))));' | 
> dmd -i -o- -
>
> 	# What does function myFun return in this case?
> 	echo 'import mymod;void main(){writeln(myFun(3.14f));}' | dmd 
> -i -run -
>
> Or generate complex output for other programs using the 
> expressive power of D code:
>
> 	# Generate test data for some external program
> 	echo 'import std;void main(){writeln(iota(0.0, 
> 100.0).map!(x=>sin(x)).filter!(x=>x > 0.5));}' |  dmd -run - | 
> sort
>
>
> Maybe we should have a Most Useful One-Line D Program contest. 
> :-P
>
>
> T

I’ll make a mental bookmark of this, thanks!

— Bastiaan.


More information about the Digitalmars-d mailing list