www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Pipe-Syntax?

reply Manfred Nowak <svv1999 hotmail.com> writes:
Just looked at index.html of D and got stuck on

    writeln("Hello World, Reloaded");

    // auto type inference and built-in foreach
    foreach (argc, argv; args)
    {
        // Object Oriented Programming
        auto cl = new CmdLin(argc, argv);
        // Improved typesafe printf
        writeln(cl.argnum, cl.suffix, " arg: ", cl.argv);
        // Automatic or explicit memory management
        delete cl;
    }

With the pipe-syntax of shells ( sh, bash, ...) this five lines could be
written as: 

    "Hello World, Piped" | writeln;
    args | CmdLin | {argnum, suffix, " arg: ", argv} | writeln;

Comments?

-manfred
Dec 20 2011
next sibling parent "Kagamin" <spam here.lot> writes:
Just use perl.
Dec 20 2011
prev sibling next sibling parent =?ISO-8859-1?Q?Alex_R=F8nne_Petersen?= <xtzgzorex gmail.com> writes:
On 21-12-2011 05:51, Manfred Nowak wrote:
 Just looked at index.html of D and got stuck on

      writeln("Hello World, Reloaded");

      // auto type inference and built-in foreach
      foreach (argc, argv; args)
      {
          // Object Oriented Programming
          auto cl = new CmdLin(argc, argv);
          // Improved typesafe printf
          writeln(cl.argnum, cl.suffix, " arg: ", cl.argv);
          // Automatic or explicit memory management
          delete cl;
      }

 With the pipe-syntax of shells ( sh, bash, ...) this five lines could be
 written as:

      "Hello World, Piped" | writeln;
      args | CmdLin | {argnum, suffix, " arg: ", argv} | writeln;

 Comments?

 -manfred
You could have a look at the pipe template in std.functional. But in general, I agree; a sort of piping operator would be very useful in - Alex
Dec 20 2011
prev sibling parent reply Dejan Lekic <dejan.lekic gmail.com> writes:
Perhaps I should think more about it, but right now I am 100% against it, as 
it makes the code extremely unreadable to an imperative programmer.

I will have to become a ~100% functional programmer to understand what all 
those overloaded operators do behind the scenes. To me | is a bitwise OR 
operator, end of story. When I see "|>" and similar in functional languages, 
I get a headache... 
My opinion - we should strive for a good ballance between imperative and 
declarative in D, not to include every possible feature a functional 
language might have.

If you really, really want something like that, then the D way would be to 
use the "~" operator perhaps...
Dec 21 2011
next sibling parent Somedude <lovelydear mailmetrash.com> writes:
Le 21/12/2011 13:54, Dejan Lekic a écrit :
 
 Perhaps I should think more about it, but right now I am 100% against it, as 
 it makes the code extremely unreadable to an imperative programmer.
 
 .... 
 My opinion - we should strive for a good ballance between imperative and 
 declarative in D, not to include every possible feature a functional 
 language might have.
 
I second this opinion. Multiplying different syntaxes just for the sake of "simplifying" code here and there is a good way to make the code unreadable. Even in Python, you can write unreadable code by abusing from functional syntax. Eventually, Guido van Rossum discourages this kind of writing.
Dec 21 2011
prev sibling parent Manfred Nowak <svv1999 hotmail.com> writes:
Dejan Lekic wrote:

 extremely unreadable to an imperative programmer.
I sort myself to the imperative programming league.
 not to include every possible feature a
 functional language might have.
Very well put.
 If you really, really want something like that, then the D way would
 be to use the "~" operator perhaps...
A "no" for both from me. Because it is a first thought only and `~' has the same "history" as `!' in D. As Alex points out, another D way seems to be to write something like: pipe!( echo!args, CmdLin, pipe!(argnum, suffix, " arg: ", argv), writeln ); But I do not see any sugar in this. -manfred
Dec 21 2011