Daniel Holden
Daniel Holden

Reputation: 88

Does Clojure have an operator similar to Haskell's Dollar Symbol?

Maybe I should just embrace the brackets but I can't help but feel an operator such as the dollar sign which exists in Haskell would really clean up code and increase readability.

I'm looking for Something that gives precedence / binds to to all the symbols following it.

putStrLn (show $ 1 + 1)
putStrLn $ show (1 + 1)
putStrLn $ show $ 1 + 1

I know about the threading operators. Those are very useful and certainly increase readability but they don't actually reduce bracket count. In most cases as they appear more similar to function composition (Which would be the Haskell . operator).

Upvotes: 2

Views: 925

Answers (2)

ideally_world
ideally_world

Reputation: 436

I don't think such a function exists, but with macros, you could probably create one. You'll never get rid of the outer most pair of parentheses without a reader macro (which doesn't exist in Clojure), but you could eliminate all of the inner ones. I've only just learned how to create macros, so if I get brave enough later, I'll give that a go. :)

Readability is greatly increased with an editor that supports Clojure syntax. I personally use emacs, SLIME, etc. and I don't even really see the parenthesis much anymore (especially with Paredit).

Upvotes: 3

Don Stewart
Don Stewart

Reputation: 137947

The $ operator relies on low binding precedence, in fact, the lowest.

Since Clojure, Scheme and Lisp don't support user-defined precedence or fixity, it isn't possible to define these syntactic constructs in the way Haskell does.

Upvotes: 9

Related Questions