Skip to content

Commit c775048

Browse files
committed
website/ref/language: add hints for list operations
This commit modifies the language reference section on lists and provides hints how a user can emulate concatenating or prepending to a list. The goal is to surface what is to be answers to common usage needs, especially for users coming to Elvish from other language ecosystems.
1 parent 26a8bd5 commit c775048

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

website/ref/language.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,24 @@ Examples:
383383
▶ [lorem ipsum]
384384
```
385385

386+
Common operations with lists can be achieved using the patterns below:
387+
388+
```elvish-transcript
389+
~> var li = [lorem ipsum]
390+
~> var new-li = (conj $li foo bar) # This emulates concatenating or appending.
391+
~> put $new-li
392+
▶ [lorem ipsum foo bar]
393+
~> var newer-li = [foo bar $@li] # This emulates prepending.
394+
~> put $newer-li
395+
▶ [foo bar lorem ipsum]
396+
```
397+
398+
See also:
399+
400+
- [`conj`](builtin.html#conj) builtin
401+
402+
- [`$@`](#variable-use) for variable exploding
403+
386404
## Map
387405

388406
A map is a value containing unordered key-value pairs.

0 commit comments

Comments
 (0)