unison/unison-src/transcripts/add-run.md

130 lines
1.5 KiB
Markdown
Raw Normal View History

2022-08-15 21:58:48 +03:00
# add.run
2022-08-17 23:50:15 +03:00
## Basic usage
2022-08-15 21:58:48 +03:00
```ucm:hide
.> builtins.merge
```
```unison
even : Nat -> Boolean
even x = if x == 0 then true else odd (drop x 1)
odd : Nat -> Boolean
odd x = if x == 0 then false else even (drop x 1)
is2even : 'Boolean
is2even = '(even 2)
```
2022-08-17 23:50:15 +03:00
it errors if there isn't a previous run
2022-08-15 21:58:48 +03:00
```ucm:error
.> add.run foo
```
```ucm
.> run is2even
```
2022-08-17 23:50:15 +03:00
it errors if the desired result name conflicts with a name in the
unison file
2022-08-15 21:58:48 +03:00
```ucm:error
.> add.run is2even
```
2022-08-17 23:50:15 +03:00
otherwise, the result is successfully persisted
2022-08-15 21:58:48 +03:00
```ucm
.> add.run foo.bar.baz
```
```ucm
.> view foo.bar.baz
```
2022-08-17 23:50:15 +03:00
## It resolves references within the unison file
```unison
z b = b Nat.+ 12
y a b = a Nat.+ b Nat.+ z 10
main : '{IO, Exception} (Nat -> Nat -> Nat)
main _ = y
```
```ucm
.> run main
.> add.run result
```
## It resolves references within the codebase
```unison
2022-08-17 23:50:15 +03:00
inc : Nat -> Nat
inc x = x + 1
```
2022-08-17 23:50:15 +03:00
```ucm
.> add inc
```
```unison
main : '(Nat -> Nat)
main _ x = inc x
```
```ucm
2022-08-17 23:50:15 +03:00
.> run main
.> add.run natfoo
.> view natfoo
```
2022-08-17 23:50:15 +03:00
## It captures scratch file dependencies at run time
```unison
x = 1
y = x + x
main = 'y
```
```ucm
.> run main
```
```unison
2022-08-17 23:50:15 +03:00
x = 50
```
2022-08-17 23:50:15 +03:00
this saves 2 to xres, rather than 100
```ucm
2022-08-17 23:50:15 +03:00
.> add.run xres
.> view xres
```
## It fails with a message if add cannot complete cleanly
```unison
main = '5
```
```ucm:error
.> run main
.> add.run xres
```
2022-08-22 18:26:40 +03:00
## It works with absolute names
```unison
main = '5
```
```ucm
.> run main
.> add.run .an.absolute.name
.> view .an.absolute.name
```