1
1
---
2
2
title : " Try"
3
- description : " Try ReScript via CLI "
3
+ description : " Try ReScript via Command Line "
4
4
canonical : " /docs/manual/latest/try"
5
5
---
6
6
7
- < !-- TODO: rename to Command Line, document options like -format -->
7
+ ## Quickly Evaluate Code
8
8
9
- # Try via CLI
9
+ Use ` bsc -e ` :
10
+
11
+ ``` sh
12
+ ❯ bsc -e ' let add = (x, y) => x + y'
13
+ // Generated by ReScript, PLEASE EDIT WITH CARE
14
+ ' use strict' ;
15
+
16
+
17
+ function add(x, y) {
18
+ return x + y | 0;
19
+ }
20
+
21
+ exports.add = add;
22
+ /* No side effect * /
23
+ ```
24
+
25
+ You can pipe the output to Node to run it:
26
+
27
+ ``` sh
28
+ ❯ bsc -e ' let add = (x, y) => x + y; Js.log(add(1, 2))' | node
29
+ 3
30
+ ```
31
+
32
+ ## Quickly Compile A Single File
10
33
11
34
You can compile a file directly via ` bsc MyFile.res ` :
12
35
@@ -23,52 +46,44 @@ Js.log(fib(0))
23
46
24
47
``` sh
25
48
❯ bsc MyFile.res
26
- // Generated by BUCKLESCRIPT , PLEASE EDIT WITH CARE
49
+ // Generated by ReScript , PLEASE EDIT WITH CARE
27
50
' use strict' ;
51
+
52
+
28
53
function fib(n) {
29
54
if (n === 0 || n === 1) {
30
55
return n;
31
56
} else {
32
57
return fib(n - 1 | 0) + fib(n - 2 | 0) | 0;
33
58
}
34
59
}
60
+
35
61
console.log(fib(0));
62
+
36
63
exports.fib = fib;
37
64
/* Not a pure module * /
38
65
` ` `
39
66
40
- You can also get the inferred signature directly via `bsc -i MyFile.res`
67
+ You can also get the inferred type signatures directly via ` bsc -i MyFile.res`
41
68
42
- ```res sig
69
+ ` ` ` sh
70
+ ❯ bsc -i MyFile.res
43
71
let fib: int => int
44
72
` ` `
45
73
46
- You can quickly test code snippets in the console:
74
+ ** Note ** that this is for quick tests. For real projects, use our [build system](build-overview.md).
47
75
48
- ```sh
49
- ❯ bsc -e ' let add = (x, y) => x + y'
50
- // Generated by ReScript, PLEASE EDIT WITH CARE
51
- ' use strict' ;
52
-
53
-
54
- function add(x, y) {
55
- return x + y | 0 ;
56
- }
57
-
58
- exports.add = add;
59
- /* No side effect */
60
- ```
61
-
62
- Pass the `-i` flag to infer the signature:
76
+ # # Format Code
63
77
64
78
` ` ` sh
65
- ❯ bsc -i -e ' let id = x => x'
66
- let id: ' a => ' a
79
+ ❯ bsc -format MyFile.res
80
+ let rec fib = n => {
81
+ switch n {
82
+ | 0 | 1 => n
83
+ | n => fib(n - 1) + fib(n - 2)
84
+ }
85
+ }
86
+ Js.log(fib(0))
67
87
` ` `
68
88
69
- **To evaluate a script quickly, pipe the output to Node**:
70
-
71
- ```sh
72
- ❯ bsc -e ' let add = (x, y) => x + y; Js.log(add(1, 2))' | node
73
- 3
74
- ```
89
+ Our [editor plugins](editor-plugins.md) come with formatting by default.
0 commit comments