You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add examples for passing REPL options via using directive to the docs (#3975)
* Add examples for passing REPL options via using directive to the docs
* Apply suggestions from code review
Co-authored-by: Tomasz Godzik <tgodzik@users.noreply.github.com>
---------
Co-authored-by: Tomasz Godzik <tgodzik@users.noreply.github.com>
Welcome to Scala 3.3.1 (17, Java OpenJDK 64-Bit Server VM).
177
+
Welcome to Scala 3.7.4 (17, Java OpenJDK 64-Bit Server VM).
151
178
Type in expressions for evaluation. Or try :help.
152
179
153
-
scala> import os._
180
+
scala> import os.*
154
181
155
182
scala> os.pwd
156
-
val res0: os.Path = /Users/yadukrishnan/test
183
+
val res0: os.Path = /current/directory/path
157
184
scala> :quit
158
185
159
186
```
160
187
</ChainedSnippets>
161
188
162
189
Since we started the repl with toolkit enabled, we can use the libraries included in the toolkit directly. In the above example, the `os-lib` library from the toolkit is used to print the current path.
163
190
191
+
### Running snippets directly via the REPL
192
+
It is possible to run code snippets via the REPL, with all the internal quirks of the REPL, rather than using standard runner execution.
193
+
While the difference is subtle and should generally be invisible to users, it is useful for investigating REPL behavior.
194
+
The key to doing that is to use the both `--repl-init-script` and `--repl-quit-after-init` options together.
195
+
196
+
<ChainedSnippets>
197
+
198
+
199
+
```bash
200
+
scala repl --repl-init-script 'println(42)' --repl-quit-after-init # runs in the REPL and quits immediately
201
+
```
202
+
203
+
```
204
+
42
205
+
```
206
+
207
+
```bash
208
+
scala repl -e '//> using options --repl-init-script "println(42)" --repl-quit-after-init'# same, but via using directive
209
+
```
210
+
211
+
```
212
+
42
213
+
```
214
+
215
+
```bash
216
+
scala -e 'println(42)'# standard runner equivalent
217
+
```
218
+
219
+
```
220
+
42
221
+
```
222
+
223
+
</ChainedSnippets>
224
+
164
225
## Inject code as JAR file in class path
165
226
166
227
If your application inspects its class path, and requires only JAR files in it, use `--as-jar` to
0 commit comments