14 ms·
> One of them is that, each time you read a new program, you have to learn a new language Which is not bad at all. You still have to do it with the programs wr
by sklogic 11y ago
> One of them is that, each time you read a new program, you have to learn a new language
Which is not bad at all. You still have to do it with the programs written in the same language built with different libraries and targeting the different problem domains. In the latter case the language is obscuring the essence of the code.
And if you're using a well designed DSL, and you're familiar with the problem domain, it will be readable naturally, just like a pseudocode.
- lmm 11y agoA lot of domain languages need infix operators though. And even if you understand the domain, it's hard to read and refactor code in the presence of unrestricted macros, whereas in a language where such DSLs are implemented via the type system the tooling will understand that.
- Jtsummers 11y agoWhy do they need infix operators? Most programmers already use prefix notation with function calls. Infix is primarily restricted to mathematical and logical operations, but the prefix (lisp style, taking an arbitrary number of arguments) is pretty clear when written neatly: (and cond1 cond2 cond3) (NB: multiple lines like this would really only be used for a lot of conditions or longer expressions.) We already do something similar with our algol-like languages: if((cond1 || cond2) && (cond3 || cond4) && (cond5 || cond6) && (cond7 || cond8)) In lisp, CL at least, would look like: (if (and (or cond1 cond2) (or cond3 cond4) (or cond5 cond6) (or cond7 cond8))
- lmm 11y agoBut at that point it's no longer the language of the domain. If you're going to support writing mathematics that looks like the mathematics that mathematicians write then you need infix operators, because mathematics is written with infix operators. Similarly for many other domains.
- Jtsummers 11y agoEven still, mathematics isn't entirely infix. And outside computer algebra systems, you'll be hard pressed to find examples of the postfix operations expressed as postfix in programming environments. !, for example. What language allows you to express: n P k = n! / (n - k)! as the above? `n P k` will become something like `nperms n k`, factorial will be moved to prefix as `fact n / fact (n - k)`. We're already diverging from the domain language, there's no reason to consider a more logically consistent framework in this case than one that seems to have arbitrarily moved some things from infix to prefix, postfix almost universally to prefix, and left some infix as infix.
- xrange 11y ago>What language allows you... SML allows you to have an infix function named "P", and Haskell allows something similar, although you have to quote it with backticks and can't use a capital letter to start a function name... https://en.wikibooks.org/wiki/Standard_ML_Programming/Expressions#Infix_function_calls https://en.wikibooks.org/wiki/Standard_ML_Programming/Expres... https://wiki.haskell.org/Infix_operator#Using_prefix_functions_with_infix_notation https://wiki.haskell.org/Infix_operator#Using_prefix_functio...
- Jtsummers 11y agoI did mean to mention that, but how about creating postfix operators?
- xrange 11y agoIn Prolog you have the ability to create new postfix operators. Of course Prolog being a logic language and not a functional language, along with '!' being used for 'cut' opens up another can of worms. http://www.swi-prolog.org/pldoc/man?predicate=op/3 http://www.swi-prolog.org/pldoc/man?predicate=op/3
- lmm 11y agoYou're right as far as you go, but it's not an all-or-nothing thing. Most languages won't let you write mathematics exactly like mathematicians do, but the closer you can get the better. For many cases avoiding infix entirely would be a big cost. (FWIW Scala allows postfix operators, though you'd have to put the n! in brackets)
- sklogic 11y agoAnd? DSLs can have any syntax you like. And any type system you want. And DSLs done the right way, via macros, are much better in integrating with tools than any ad hoc interpreted DSLs would ever be able to. You can easily have syntax and semantic highlighting infered, with auto indentation, intellisense and all the bells and whistles. For no extra cost.
- lmm 11y ago> And DSLs done the right way, via macros, are much better in integrating with tools than any ad hoc interpreted DSLs would ever be able to. You can easily have syntax and semantic highlighting infered, with auto indentation, intellisense and all the bells and whistles. For no extra cost. No you can't. If the macro is arbitrary code then no tool can offer those things - there's no way to offer intellisense if you don't know what strings are meaningful in the language, and an unconstrained macro could use anything to mean anything.
- sklogic 11y agoYes you can - as soon as you start wrapping your arbitrarily complex macros into a custom syntax. I am easily doing this stuff with any language I am adding macros and extensible syntax to.
- lomnakkus 11y ago> Yes you can - as soon as you start wrapping your arbitrarily complex macros into a custom syntax. Well, by that definition you get exactly the same if the host language of your DSL is statically typed and doesn't use macros. Custom syntax is custom syntax and whether tools/IDEs understand it has nothing to do with the host language.
- sklogic 11y agoSorry, I did not quite get what you mean. Of course macro+syntax extension got absolutely nothing to do with what you can achieve in a language without macros. And, no, you did not understand. Any custom syntax you're adding (if the right tools are used, like mine, for example) would automatically become available for your IDE and all the other tools, because they're reusing the same compiler front-end.
- AKrumbach 11y agoAll compilers translate a text stream into a tree structure during parsing, so arguing that some language "needs" infix is saying that there is some tree structure out there that can't be traversed depth-first rather than breadth-first. That can only be true if your supposed "tree" actually contains loops. What language do you know of that generates cyclical parse structures?