Skip to content

Commit

Permalink
add call/cc example
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Feb 26, 2024
1 parent 07040f5 commit 30219e6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/docs/scheme-intro/continuations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,18 @@ description: Powerful feature of Scheme that allow to add new control flows
---

# Continuations

## Early exit

Scheme doesn't have a return expression, but with continuations you can add one.

```scheme
(define (find item lst)
(call/cc (lambda (return)
(let loop ((lst lst))
(if (null? lst)
(return #f)
(if (equal? item (car lst))
(return lst)
(loop (cdr lst))))))))
```

0 comments on commit 30219e6

Please sign in to comment.