To give you a better idea of what I'm envisioning, my language would make liberal use of the "|" character as a pipe operator, which would work much like it's used in bash. Almost every line of code would start with one or more pieces of data, which is then piped from left to right through one or more functions to obtain a result, which you would then (at the end of the line) assign to a variable, print, or do some other I/O action with it.
Code: Select all
3, 4 | + => x
# in most languages this would be written as "x = 3 + 4"
5 => x
# variable assignment
3, 4 | + | *3 | print
# equivalent to "print (3 + 4) * 3"
# à la Haskell, (*3) is used as a partially applied function that takes
# one argument and multiplies it by 3
"hello world" | capitalize | reverse | print
# prints "dlrow olleH"
In thinking about this, I've encountered a number of interesting syntax problems, some of which I'm still toying with. For instance, what if you have one piece of data that you want to pipe to a function that takes two arguments? I came up with the idea of using the comma as an operator to do "branching" within one line of code. I used it above in the "3, 4 | +" example. The line starts as two "branches," one containing 3 and the other containing 4, which are piped to the function "+", which takes 2 arguments so it uses both 3 and 4. I've even developed a syntax for working on multiple branches separately, all in the same line of code! It's surprisingly readable.
I haven't actually tried creating a parser for this conceptual language yet, but I've done a lot of work in figuring out how the syntax might work, and in doing so I've found that it's quite easy to express things more concisely using this kind of "everything is left-applicative" syntax, and the code reads more intuitively (at least to my eyes). You can accomplish a lot more tasks in a single line of code, whereas in other C-like languages you would have to store data intermediately in "throw-away variables" and keep working on said data on the next line. I'm surprised that I haven't heard of any other languages out there that do this kind of thing. Have any of you guys?