OILS / doc / pure-mode.md View on Github | oils.pub

88 lines, 56 significant
1---
2default_highlighter: oils-sh
3in_progress: true
4---
5
6Oils Pure Mode: For Config Files and Functions
7=========================================
8
9The interpreter can run in pure mode
10
11
12<div id="toc">
13</div>
14
15## Why does Oils have Pure Mode?
16
17- config files should be isolated to git
18- **data** versus **code**
19
20---
21
22- JSON is data.
23 - TSV, HTML is data
24 - J8 Notation is data.
25- Hay is programmable data.
26 - it doesn't format your hard drive.
27
28### WebAssembly Analogy
29
30WebAssembly is also pure computation, and can be used in a variety of contexts.
31
32It has `io` too.
33
34## When is it active?
35
36### `--eval-pure`
37
38vs `--eval`
39
40TODO: link to doc/reef
41
42### `eval()` and `evalExpr()`
43
44vs. `io->eval()` and `io->evalExpr()`
45
46TODO: link to doc/reef
47
48### Pure Functions
49
50- TODO: `func`
51
52## What's allowed in Pure Mode? Not allowed?
53
54What's not allowed:
55
56- external commands
57- any process construct
58 - pipelines
59 - subshell
60 - command sub and process sub
61 - background jobs with `&`
62- many builtins
63 - most of these do I/O
64- globbing - touches the file system
65- time and randomness
66 - $SECONDS and $RANDOM
67
68---
69
70- [`shell-flags`](chap-front-end.html#shell-flags) for `--eval-pure`
71- [`func/eval`](chap-builtin-func.html#func/eval) and
72 [`func/evalExpr`](chap-builtin-func.html#func/evalExpr)
73- [`func`](chap-ysh-cmd.html#func) - functions are pure
74- [`io`](chap-type-method.html#io) and [`vm`](chap-type-method.html#vm) - impure
75 behavior is attached to these objects
76
77## Notes
78
79Pure mode is a bit like functional programming, but the style **inside** a
80function is not functional.
81
82In YSH, it's natural to write pure functions in an imperative style. Just like
83you can do this in Python or JavaScript (although there is no enforcement,
84unlike Oils)
85
86
87
88