Skip to content

Commit

Permalink
add docs about global env
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Mar 24, 2024
1 parent 07803a2 commit fa34d1a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions docs/docs/lips/environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,42 @@ You can mix lexical scope chain with frames:
;; ==> let ==> #(y)
;; ==> lambda ==> #(arguments parent.frame x)
```

## Global environment

in `lips.env` is user global environment but real global environment where all functions and macros that are
located (it's also a place where names from bootstraping are saved) is `lips.env.__parent__`.

If you want to really overwrite builtin function.

```scheme
(define-macro (define x)
`(print ,x))
(define 10)
;; ==> 10
(unset! define)
(define foo 10)
(print foo)
;; ==> 10
```

If you execute this code in REPL or in a script it will only add `define` into `interaction-environment`.
If you really want to overwrite `define` you can (not that you should):

```scheme
(let-env lips.env.__parent__
(define-macro (define x)
`(print ,x)))
(unset! define)
(define foo 10)
;; ==> Unbound variable `define'
```

The only time you may want to use `lips.env.__parent__` when you bootstrap the LIPS Scheme system.

```scheme
(let-env lips.env.__parent__
(load "<path or URL>/dist/std.xcb"))
```

0 comments on commit fa34d1a

Please sign in to comment.