Skip to content

Commit

Permalink
add section about scheme-report-environment
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Mar 23, 2024
1 parent f3a1e5e commit d4918a8
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion docs/docs/lips/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,41 @@ In LIPS you can change the environment with `let-env` syntax:
;; ==> 30
```

## Scheme Report Environments
Scheme standard provide environments for given version of the [R<sup>n</sup>RS
specification](/docs/scheme-intro/what-is-lisp#standards) in a form of a function
`scheme-report-environment`.

You can use this function in LIPS with version 5 and 7 to get R<sup>5</sup>RS or R<sup>7</sup>RS.

**NOTE**: that some of the functions from R<sup>5</sup>RS may have features of R<sup>7</sup>RS since
some of them got additional arguments. R<sup>n</sup>RS is backward compatible.

You can use this function with `eval` or `let-env`:

```scheme
(let ((env (scheme-report-environment 7)))
(let-env env
(display (+ 1 2))))
;; ==> 3
(let-env (scheme-report-environment 7)
(display (--> "string" (toUpperCase))))
;; ==> Unbound variable `-->'
(let-env (scheme-report-environment 7)
(write (vector-map + #(1 2 3) #(4 5 6 7))))
;; ==> #(5 7 9)
(let-env (scheme-report-environment 5)
(write (vector-map + #(1 2 3) #(4 5 6 7))))
;; ==> Unbound variable `vector-map'
```

R<sup>5</sup>RS doesn't support `vector-map` that was added in version R<sup>7</sup>RS. The same
both Scheme versions doesn't support LIPS extensions like [`-->`
macro](/docs/lips/intro#helper-macros-and-functions).

## Introspection

Since environments are JavaScript objects you can access it's properties like `__name__` or `__env__`.
Since environments are JavaScript objects you can access its properties like `__name__` or `__env__`.

```scheme
(let ((x 10) (y 20))
Expand Down

0 comments on commit d4918a8

Please sign in to comment.