# The Spritely Institute publishes A Scheme Primer

**URL:** https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129
**Category:** Architecture
**Created:** [July 6, 2022, 7:09pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129 "2022-07-06T19:09:09Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![cwebber](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/cwebber/32/9_2.png) [@cwebber](https://community.spritely.institute/u/cwebber)
#### Post date: [July 6, 2022, 7:09pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/1 "2022-07-06T19:09:09Z")

</div>

Hello all! I’m happy to announce that we’ve [announced](https://spritely.institute/news/the-spritely-institute-publishes-a-scheme-primer.html) a new document: [A Scheme Primer](https://spritely.institute/static/papers/scheme-primer.html)!

This grew out of requests from discussions around the whitepaper for an introduction to Scheme’s concepts, and was originally an appendix, but it grew enough that we decided it should be its own thing! (It’ll be removed from being an appendix when I publish the next release of the whitepaper now that we have the separate primer.)

Your feedback, as always, is welcome. This one’s fairly public already, so feel free to spread it around if you like!

---

<div class="post-metadata">

### Author: ![dale.schumacher](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dale.schumacher/32/86_2.png) [@dale.schumacher](https://community.spritely.institute/u/dale.schumacher)
#### Post date: [July 7, 2022, 5:46pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/2 "2022-07-07T17:46:21Z")

</div>

## 4. Basic types, a few small functions

Contains the following example:

```auto
(* (- 8 (/ 30 5)) 21) ; beginning expression
(* (- 8 6) 21) ; simplify: (/ 30 5) => 6
(* 2 21) ; simplify: (- 8 6) => 2
42 ; simplify: (* 2 21) => 42

```

We could take advantage of non-canonical whitespace to align the substitutions…

```auto
(* (- 8 (/ 30 5)) 21) ; beginning expression
(* (- 8 6 ) 21) ; simplify: (/ 30 5) => 6
(* 2 21) ; simplify: (- 8 6) => 2
42 ; simplify: (* 2 21) => 42

```

…and maybe make the example more clear to the novice reader.

This example appears again in:

## 10. Mutation, assignment, and other kinds of side effects

---

<div class="post-metadata">

### Author: ![dale.schumacher](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dale.schumacher/32/86_2.png) [@dale.schumacher](https://community.spritely.institute/u/dale.schumacher)
#### Post date: [July 7, 2022, 7:13pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/3 "2022-07-07T19:13:29Z")

</div>

## 9. Iteration and recursion

Contains the following example:

```auto
(define (build-tree depth)
  (if (= depth 0)
      '(0)
      (list depth
            (build-tree (- depth 1))
            (build-tree (- depth 1)))))

```

The subsequent explanation includes the phrase “more work needs to be done, as cons sits waiting for its results”, which should be “more work needs to be done, as `list` sits waiting for its results”.

In footnote **16** , the phrase “managing change such that the user need think of them;” should be “managing change such that the user need not think of them;”

---

<div class="post-metadata">

### Author: ![dale.schumacher](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dale.schumacher/32/86_2.png) [@dale.schumacher](https://community.spritely.institute/u/dale.schumacher)
#### Post date: [July 7, 2022, 7:24pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/4 "2022-07-07T19:24:08Z")

</div>

Apparently it is bad form to make multiple reply-posts, so I’ve consolidated my prior edits into the previous two posts, and will add any remaining edits to this one…

## 12. Scheme in Scheme

“Supplying only two operators, `+` and `-` , we are able to compute the Fibonacci sequence:” should be “Supplying only two operators, `+` and `=` , we are able to compute the Fibonacci sequence:”

In the section explaining the implementation of `lambda`, you say:

> the procedure we return recursively calls `evaluate` against the `body` expression of the lambda we are matching against, but with a newly extended environment

This is the point where a choice is made between lexical and dynamic scoping. I think it would be worth pointing out that the environment where `lambda` is evaluated is captured and used in place of the dynamic environment where the procedure is invoked. Perhaps with a corresponding back-reference in the discussion of procedure application, pointing out that the arguments are evaluated in a **different environment** than the body of the lambda.

---

<div class="post-metadata">

### Author: ![cwebber](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/cwebber/32/9_2.png) [@cwebber](https://community.spritely.institute/u/cwebber)
#### Post date: [July 8, 2022, 5:20pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/5 "2022-07-08T17:20:45Z")

</div>

Thanks for all the good catches! I’m on vacation so allegedly I’m not even reading this let alone replying to it or lord forbid fixing things 😉

> [@dale.schumacher](#):
>
> This is the point where a choice is made between lexical and dynamic scoping. I think it would be worth pointing out that the environment where is `lambda` is evaluated is captured and used in place of the dynamic environment where the procedure is invoked. Perhaps with a corresponding back-reference in the discussion of procedure application, pointing out that the arguments are evaluated in a **different environment** than the body of the lambda.

Yes that’s well put. I thought a fun follow-up document to this, some day, might be to show off (borrowing from SICP’s [Variations on a Scheme](https://mitpress.mit.edu/sites/default/files/sicp/full-text/sicp/book/node84.html)) how with just a couple of small tweaks one can switch to dynamic scope or make it prolog-like or etc. Maybe at some point in the future…

---

<div class="post-metadata">

### Author: ![cwebber](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/cwebber/32/9_2.png) [@cwebber](https://community.spritely.institute/u/cwebber)
#### Post date: [July 11, 2022, 7:38pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/6 "2022-07-11T19:38:22Z")

</div>

Thanks again @dale.schumacher ! I integrated _almost_ all of your suggestions, but I didn’t do the alignment on the substitution method one… it’s a sensible decision but aesthetically I liked the way it was, whether that’s a good choice or not.

Also you might like the new footnote I added:

```nohighlight
[fn:lexical-scope-happens-here] This is where the choice is made
between lexical and dynamic scoping. The environment which is
extended is not the environment of the caller, but the environment of
the previous expression in which this lambda was defined... this is is
how we achieve the functionality described in the =closures= section.

In a sense, "lexical scope" is "scope is defined by capturing where it
is written" and is capability secure, is explicit, and preserves the
"if you don't have it, you can't use it" property. "Dynamic scope" is
instead "scope is defined by the invoker" (and their parent invokers,
all the way up the stack of current invocations) and is implicit, but
also ambient including in the ambient authority sense, making dynamic
scope suffer more serious security issues (and not coincidentally,
more strongly resemble access control list systems).

```

---

<div class="post-metadata">

### Author: ![dale.schumacher](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/dale.schumacher/32/86_2.png) [@dale.schumacher](https://community.spritely.institute/u/dale.schumacher)
#### Post date: [July 11, 2022, 8:03pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/7 "2022-07-11T20:03:36Z")

</div>

Final editorial decisions are always the authors’. I’m glad the feedback was useful.

The footnote is helpful and, I think, informative. There is a small typo:

> [@cwebber](#):
>
> ```auto
> this is is
> how we achieve
> 
> ```

---

<div class="post-metadata">

### Author: ![cwebber](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/cwebber/32/9_2.png) [@cwebber](https://community.spritely.institute/u/cwebber)
#### Post date: [July 11, 2022, 9:56pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/8 "2022-07-11T21:56:57Z")

</div>

Oops! Thanks on that. Fixed in git… and I’ll fix in the next website export/push, probably tomorrow. Thanks!

---

<div class="post-metadata">

### Author: ![frandallfarmer](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/frandallfarmer/32/3_2.png) [@frandallfarmer](https://community.spritely.institute/u/frandallfarmer)
#### Post date: [July 12, 2022, 12:31am UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/9 "2022-07-12T00:31:45Z")

</div>

I pushed the head of main to the website.

---

<div class="post-metadata">

### Author: ![frandallfarmer](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.spritely.institute/frandallfarmer/32/3_2.png) [@frandallfarmer](https://community.spritely.institute/u/frandallfarmer)
#### Post date: [August 1, 2022, 5:36pm UTC](https://community.spritely.institute/t/the-spritely-institute-publishes-a-scheme-primer/129/10 "2022-08-01T17:36:17Z")

</div>

Thanks to [Florian Pelz](https://pelzflorian.de/), Our Scheme Primer is now available in German! ([HTML](https://spritely.institute/static/papers/scheme-primer.de.html)) ([PDF](https://spritely.institute/static/papers/scheme-primer.de.pdf)) ([ODT](https://spritely.institute/static/papers/scheme-primer.de.odt)) ([ORG](https://spritely.institute/static/papers/scheme-primer.de.org)) ([TEXI](https://spritely.institute/static/papers/scheme-primer.de.texi)) ([EPUB](https://spritely.institute/static/papers/scheme-primer.de.epub)) ([source](https://gitlab.com/spritely/scheme-primer))
