Remix.run Logo
the_gipsy a day ago

When everything is an expression, like rust (I think), that's enough. Most of the control flow are used as statements, but if needed, they can be used directly as expression, and you get basically all the advantages. After seeing how effective this is, using a language that doesn't have this feature can be really annoying.

On the other hand, I would like to explore "when arithmetics is just a function". I think Elm does this well: operators are just functions with two arguments that can be written as "1 + 2", the familiar way, or "(+) 1 2". Then you can compose it like "map ((+) 2)" (currying) so you get a function that adds 2 to every item of a list, and so on.

middayc 20 hours ago | parent [-]

This is another subject but mathematical operators are and behave (for better and worse - there are also negative consequences of this consistency) like all other op-words, they just don't need . in front and correct, non-op-word is prepended by _.

    12 + 23    ; is technically
    12 ._+ 23  ; or not using op-word is
    _+ 12 23   ; or if we bind function _+ to add
    add: ?_+   ; we get
    12 .add 23 ; and
    add 12 23
It has downside because op-words don't behave exactly as math expressions would, but you can use parenthesis and we have a math dialect which includes full math precedence rules.

    math { 12 * 2 + 23 * 3 }