Skip to content

Commit

Permalink
(docs) add usage of alist with cond
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jun 1, 2024
1 parent 2647edd commit 6007212
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/docs/scheme-intro/core.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,16 @@ argument. They use `eq?`, `eqv?`, and `equal?` respectively.
First call will return pair `(bar . 20)` because its `bar` symbol is present in the alist. And the
second call will print `#f`.

You can use `cond` expression with `=>` syntax to get the value of alist:

```scheme
(let* ((alist '((foo . 10) (bar . 20) (baz . 30)))
(result (cond ((assoc 'bar alist) => cdr)
(else '()))))
(if result
(print result)))
```

## Finding element in the list

Similar to operation on alist there are 3 functions that find if the element is present in the normal list
Expand Down

0 comments on commit 6007212

Please sign in to comment.