git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update syntax.rst
commitcd287bd3b8ae7eb628c93d8347e4eaa7d9113e17 authorPhil Freeman <paf31@cantab.net> dateThu 23 Jan 2014, 14:03 (13 years ago) parentde7cd27
1 file changed+88−3
docs/source/syntax.rst+88−3
docs/source/syntax.rst+88−3
@@ -74,22 +74,107 @@ String literals are enclosed in double-quotes and may extend over multiple lines
7474 "Hello \
7575 \World"
7676
77−The two boolean literals are `true` and `false`.
77+The two boolean literals are ``true`` and ``false``.
78+
79+Array Literals
80+--------------
7881
7982Array literals are surrounded by square brackets, as in Javascript::
8083
8184 []
8285 [1, 2, 3]
8386
84−Object literals are surrounded by braces, as in Javascript::
87+Record Literals
88+---------------
89+
90+Record literals are surrounded by braces, as in Javascript::
8591
8692 {}
8793 { foo: "Foo", bar: 1 }
94+
95+Array Indexing
96+--------------
97+
98+To retrieve the element of an array at an index, use the ``!!`` operator::
99+
100+ arr !! 0
101+
102+This example corresponds to the Javascript ``arr[0]``.
103+
104+Property Accessors
105+------------------
106+
107+To access a property of a record, use a dot, followed by the property name, as in Javascript::
108+
109+ rec.propertyName
110+
111+Functions
112+---------
113+
114+Functions are introduced by using a backslash followed by a list of argument names::
115+
116+ example1 = \a b -> a + b
117+
118+which would correspond to the following Javascript::
119+
120+ function example1(a) {
121+ return function (b) {
122+ return a + b;
123+ }
124+ }
125+
126+Multiple argument functions can be introduced by wrapping the arguments in parentheses, and separating them with commas::
127+
128+ example2 = \(a, b) -> a + b
129+
130+which generates::
131+
132+ function example2(a, b) {
133+ return a + b;
134+ }
135+
136+There is a special case for functions with no arguments, where the parentheses may be omitted, as follows::
137+
138+ example3 = \ -> 100
139+
140+which would correspond to the Javascript::
141+
142+ function example3() {
143+ return 100;
144+ }
145+
146+Multiple-argument and single-argument syntax can be mixed, as follows::
147+
148+ example4 = \a (b, c) d -> a + b + c + d
149+
150+which generates::
151+
152+ function example4(a) {
153+ return function (b, c) {
154+ return function (d) {
155+ return a + b + c + d;
156+ }
157+ }
158+ }
159+
160+Functions are applied by providing their arguments inside parentheses::
161+
162+ test1(1, 2, 3)
163+ test2()
164+
165+A special case is made in the case of functions with one argument. These functions can be applied without parentheses, and function application associates to the left::
166+
167+ addThree :: Number -> Number -> Number -> Number
168+ addThree a b c = a + b + c
169+
170+ addThree 1 :: Number -> Number -> Number
171+ addThree 1 2 :: Number -> Number
172+ addThree 1 2 3 :: Number
88173
89174If-Then-Else Expressions
90175------------------------
91176
92−The `if`, `then` and `else` keywords can be used to create conditional expressions. In this case, the `else` block is always required.
177+The ``if``, ``then`` and ``else`` keywords can be used to create conditional expressions. In this case, the ``else`` block is always required.
93178
94179For example::
95180