... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   ["$" documentation]
   [data
    ["[0]" text (.only \n)
     ["%" \\injection]]]]]
 [\\library
  ["[0]" /]])

(the .public documentation
  (List $.Documentation)
  (list ($.module /._
                  "")

        ($.definition /.infix
          (%.message "Infix math syntax."
                     \n "The rules for infix syntax are simple."
                     \n "If you want your binary function to work well with it."
                     \n "Then take the argument to the right (y) as your first argument,"
                     \n "and take the argument to the left (x) as your second argument.")

          ($.comment "Binary functions")
          ($.example (' (infix [x * +10])))
          ($.comment "=>")
          ($.example (' (* +10 x)))
          
          ($.comment "Nested infix")
          ($.example (' (infix [[x + y] * [x - y]])))
          ($.comment "=>")
          ($.example (' (* (- y x) (+ y x))))
          
          ($.comment "Unary functions")
          ($.example (' (infix [sin [x + y]])))
          ($.comment "=>")
          ($.example (' (sin (+ y x))))
          
          ($.comment "Also works with logic")
          ($.example (' (infix [[x < y] and [y < z]])))
          ($.comment "=>")
          ($.example (' (and (< z y)
                             (< y x))))
          
          ($.comment "Forms are left as-is")
          ($.example (' (infix [(* 3 9) gcd 450])))
          ($.comment "=>")
          ($.example (' (gcd 450 (* 3 9)))))
        ))
