Skip to content

Commit bc6ac1d

Browse files
committed
Revamp try page
1 parent 0222c98 commit bc6ac1d

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

pages/docs/manual/latest/try.mdx

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
---
22
title: "Try"
3-
description: "Try ReScript via CLI"
3+
description: "Try ReScript via Command Line"
44
canonical: "/docs/manual/latest/try"
55
---
66

7-
<!-- TODO: rename to Command Line, document options like -format -->
7+
## Quickly Evaluate Code
88

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
1033

1134
You can compile a file directly via `bsc MyFile.res`:
1235

@@ -23,52 +46,44 @@ Js.log(fib(0))
2346

2447
```sh
2548
❯ bsc MyFile.res
26-
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
49+
// Generated by ReScript, PLEASE EDIT WITH CARE
2750
'use strict';
51+
52+
2853
function fib(n) {
2954
if (n === 0 || n === 1) {
3055
return n;
3156
} else {
3257
return fib(n - 1 | 0) + fib(n - 2 | 0) | 0;
3358
}
3459
}
60+
3561
console.log(fib(0));
62+
3663
exports.fib = fib;
3764
/* Not a pure module */
3865
```
3966
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`
4168
42-
```res sig
69+
```sh
70+
❯ bsc -i MyFile.res
4371
let fib: int => int
4472
```
4573
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).
4775
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
6377
6478
```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))
6787
```
6888
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

Comments
 (0)