aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/math/infix.lux
blob: 9f6f7f8edfefc5b2128eef661a3fb3d15881faa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(.using
  [library
   [lux {"-" private}
    ["$" documentation {"+" documentation:}]
    [data
     ["[0]" text {"+" \n}
      ["%" format {"+" format}]]]
    [macro
     ["[0]" template]]]]
  [\\library
   ["[0]" /]])

(documentation: /.infix
  (format "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.")
  ["Binary functions"
   (infix [x * +10])
   "=>"
   (* +10 x)]
  ["Nested infix"
   (infix [[x + y] * [x - y]])
   "=>"
   (* (- y x) (+ y x))]
  ["Unary functions"
   (infix [sin [x + y]])
   "=>"
   (sin (+ y x))]
  ["Also works with logic"
   (infix [[x < y] and [y < z]])
   "=>"
   (and (< z y)
        (< y x))]
  ["Forms are left as-is"
   (infix [(* 3 9) gcd 450])
   "=>"
   (gcd 450 (* 3 9))])

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..infix]
            []))