Skip to content

Commit

Permalink
Add doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Nov 13, 2022
1 parent 1372091 commit 3d99a00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ New:
- `file.replaygain` to compute the replaygain of a file
- Added support for ImageLib to decode images.
- Added support for completion in emacs based on company (#2652).
- Added syntactic sugar for record spread: `let {foo, gni, ..y} = x`
and `y = { foo = 123, gni = "aabb", ...x}` (#2737)

Changed:

Expand Down
22 changes: 22 additions & 0 deletions doc/content/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,24 @@ the duration with
print("The duration of the song is #{song.duration} seconds")
```

Records can be re-used using _spreads_:

```liquidsoap
song = { filename = "song.mp3", duration = 257., bpm = 132. }
# This is a fresh value with all the fields from `song` and
# a new `id` field:
song_with_id = { id = 1234, ...song }
```

Alternatively, you can also add method with the explicit `v.{...}` syntax:

```liquidsoap
song = { filename = "song.mp3", duration = 257., bpm = 132. }
song_with_id = song.{id = 1234}
```

### Modules

Records are heavily used in Liquidsoap in order to structure the functions of
Expand Down Expand Up @@ -1072,6 +1090,10 @@ Here are some examples:
let {foo, bar} = {foo = 123, bar = "baz", gni = true}
# foo = 123, bar = "baz"
# Record capture with spread
let {foo, bar, ...x} = {foo = 123, bar = "baz", gni = true}
# foo = 123, bar = "baz", x = {gni = true}
# Module capture
let v.{foo, bar} = "aabbcc".{foo = 123, bar = "baz", gni = true}
# v = "aabbcc", foo = 123, bar = "baz"
Expand Down

0 comments on commit 3d99a00

Please sign in to comment.