2022-08-15 21:58:48 +03:00
|
|
|
# add.run
|
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
## Basic usage
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-15 21:58:48 +03:00
|
|
|
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)
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-15 21:58:48 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-15 21:58:48 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
|
|
|
even : Nat -> Boolean
|
|
|
|
is2even : 'Boolean
|
|
|
|
odd : Nat -> Boolean
|
|
|
|
|
|
|
|
```
|
2022-08-17 23:50:15 +03:00
|
|
|
it errors if there isn't a previous run
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add.run foo
|
2022-08-15 21:58:48 +03:00
|
|
|
|
|
|
|
⚠️
|
|
|
|
|
|
|
|
There is no previous evaluation to save. Use `run` to evaluate
|
|
|
|
something before attempting to save it.
|
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run is2even
|
2022-08-15 21:58:48 +03:00
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
```
|
2022-08-17 23:50:15 +03:00
|
|
|
it errors if the desired result name conflicts with a name in the
|
|
|
|
unison file
|
2024-07-10 17:46:18 +03:00
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add.run is2even
|
2022-08-15 21:58:48 +03:00
|
|
|
|
|
|
|
⚠️
|
|
|
|
|
|
|
|
Cannot save the last run result into `is2even` because that
|
|
|
|
name conflicts with a name in the scratch file.
|
|
|
|
|
|
|
|
```
|
2022-08-17 23:50:15 +03:00
|
|
|
otherwise, the result is successfully persisted
|
2024-07-10 17:46:18 +03:00
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add.run foo.bar.baz
|
2022-08-15 21:58:48 +03:00
|
|
|
|
2022-08-22 21:17:48 +03:00
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
foo.bar.baz : Boolean
|
|
|
|
|
2022-08-15 21:58:48 +03:00
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view foo.bar.baz
|
2022-08-15 21:58:48 +03:00
|
|
|
|
|
|
|
foo.bar.baz : Boolean
|
|
|
|
foo.bar.baz = true
|
|
|
|
|
|
|
|
```
|
2022-08-17 23:50:15 +03:00
|
|
|
## It resolves references within the unison file
|
2022-08-15 22:46:55 +03:00
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-17 23:50:15 +03:00
|
|
|
z b = b Nat.+ 12
|
|
|
|
y a b = a Nat.+ b Nat.+ z 10
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
main : '{IO, Exception} (Nat -> Nat -> Nat)
|
|
|
|
main _ = y
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-17 23:50:15 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
|
|
|
main : '{IO, Exception} (Nat -> Nat -> Nat)
|
|
|
|
y : Nat -> Nat -> Nat
|
|
|
|
z : Nat -> Nat
|
2022-08-15 22:46:55 +03:00
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main
|
2022-08-17 23:50:15 +03:00
|
|
|
|
|
|
|
a b -> a Nat.+ b Nat.+ z 10
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add.run result
|
2022-08-17 23:50:15 +03:00
|
|
|
|
2022-08-22 21:17:48 +03:00
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
result : Nat -> Nat -> Nat
|
|
|
|
z : Nat -> Nat
|
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
```
|
|
|
|
## It resolves references within the codebase
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-17 23:50:15 +03:00
|
|
|
inc : Nat -> Nat
|
|
|
|
inc x = x + 1
|
2022-08-15 22:46:55 +03:00
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-15 22:46:55 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-15 22:46:55 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
inc : Nat -> Nat
|
2022-08-15 22:46:55 +03:00
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add inc
|
2022-08-15 22:46:55 +03:00
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
inc : Nat -> Nat
|
2022-08-15 22:46:55 +03:00
|
|
|
|
|
|
|
```
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-17 23:50:15 +03:00
|
|
|
main : '(Nat -> Nat)
|
|
|
|
main _ x = inc x
|
2022-08-15 22:46:55 +03:00
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-15 22:46:55 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-15 22:46:55 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
main : '(Nat -> Nat)
|
2022-08-15 22:46:55 +03:00
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main
|
2022-08-17 23:50:15 +03:00
|
|
|
|
|
|
|
inc
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add.run natfoo
|
2022-08-17 23:50:15 +03:00
|
|
|
|
2022-08-22 21:17:48 +03:00
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
natfoo : Nat -> Nat
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view natfoo
|
2022-08-17 23:50:15 +03:00
|
|
|
|
|
|
|
natfoo : Nat -> Nat
|
|
|
|
natfoo = inc
|
|
|
|
|
|
|
|
```
|
|
|
|
## It captures scratch file dependencies at run time
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-17 23:50:15 +03:00
|
|
|
x = 1
|
|
|
|
y = x + x
|
|
|
|
main = 'y
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-17 23:50:15 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
|
|
|
main : 'Nat
|
|
|
|
x : Nat
|
|
|
|
y : Nat
|
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main
|
2022-08-17 23:50:15 +03:00
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
```
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-17 23:50:15 +03:00
|
|
|
x = 50
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-17 23:50:15 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
|
|
|
x : Nat
|
|
|
|
|
|
|
|
```
|
2022-08-18 02:12:46 +03:00
|
|
|
this saves 2 to xres, rather than 100
|
2024-07-10 17:46:18 +03:00
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add.run xres
|
2022-08-17 23:50:15 +03:00
|
|
|
|
2022-08-22 21:17:48 +03:00
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
xres : Nat
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view xres
|
2022-08-15 22:46:55 +03:00
|
|
|
|
2022-08-17 23:50:15 +03:00
|
|
|
xres : Nat
|
|
|
|
xres = 2
|
2022-08-15 22:46:55 +03:00
|
|
|
|
|
|
|
```
|
2022-08-22 17:44:58 +03:00
|
|
|
## It fails with a message if add cannot complete cleanly
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-22 17:44:58 +03:00
|
|
|
main = '5
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-22 17:44:58 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-22 17:44:58 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
|
|
|
main : 'Nat
|
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> run main
|
2022-08-22 17:44:58 +03:00
|
|
|
|
|
|
|
5
|
|
|
|
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add.run xres
|
2022-08-22 17:44:58 +03:00
|
|
|
|
2022-08-22 17:50:13 +03:00
|
|
|
x These definitions failed:
|
2022-08-22 17:44:58 +03:00
|
|
|
|
|
|
|
Reason
|
|
|
|
needs update xres : Nat
|
|
|
|
|
|
|
|
Tip: Use `help filestatus` to learn more.
|
|
|
|
|
|
|
|
```
|
2022-08-22 18:26:40 +03:00
|
|
|
## It works with absolute names
|
|
|
|
|
2024-07-10 17:46:18 +03:00
|
|
|
``` unison
|
2022-08-22 18:26:40 +03:00
|
|
|
main = '5
|
|
|
|
```
|
|
|
|
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2022-08-22 18:26:40 +03:00
|
|
|
|
2023-12-22 14:55:24 +03:00
|
|
|
Loading changes detected in scratch.u.
|
|
|
|
|
2022-08-22 18:26:40 +03:00
|
|
|
I found and typechecked these definitions in scratch.u. If you
|
|
|
|
do an `add` or `update`, here's how your codebase would
|
|
|
|
change:
|
|
|
|
|
|
|
|
⍟ These new definitions are ok to `add`:
|
|
|
|
|
|
|
|
main : 'Nat
|
|
|
|
|
|
|
|
```
|
2024-07-10 19:17:15 +03:00
|
|
|
``` ucm
|
2024-07-01 23:27:40 +03:00
|
|
|
scratch/main> run main
|
2022-08-22 18:26:40 +03:00
|
|
|
|
|
|
|
5
|
|
|
|
|
2024-07-01 23:27:40 +03:00
|
|
|
scratch/main> add.run .an.absolute.name
|
2022-08-22 18:26:40 +03:00
|
|
|
|
2022-08-22 21:17:48 +03:00
|
|
|
⍟ I've added these definitions:
|
|
|
|
|
|
|
|
.an.absolute.name : Nat
|
|
|
|
|
2024-07-01 23:27:40 +03:00
|
|
|
scratch/main> view .an.absolute.name
|
2022-08-22 18:26:40 +03:00
|
|
|
|
2024-06-26 22:42:58 +03:00
|
|
|
.an.absolute.name : Nat
|
|
|
|
.an.absolute.name = 5
|
2022-08-22 18:26:40 +03:00
|
|
|
|
|
|
|
```
|