From 86f476e5248ce60d139a85936d2200e244c5f840 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Fri, 1 Mar 2024 22:21:24 +0100 Subject: [PATCH] more grammar fixes --- docs/docs/scheme-intro/macros.md | 44 +++++++++++++++-------------- docs/docs/scheme-intro/next-step.md | 22 ++++++++------- docs/docs/scheme-intro/streams.md | 4 +-- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/docs/docs/scheme-intro/macros.md b/docs/docs/scheme-intro/macros.md index 8e97329c7..948078888 100644 --- a/docs/docs/scheme-intro/macros.md +++ b/docs/docs/scheme-intro/macros.md @@ -6,12 +6,12 @@ description: Macros are the most powerful feature of Lisp and Scheme # Macros Macros are the most powerful feature of the language (both lisp and Scheme). Macros allows you to add -new syntax to the language, it also alows to make code simpler and reduce +new syntax to the language, it also allows making simpler code and reduce [boilerplate](https://en.wikipedia.org/wiki/Boilerplate_code). Macros works like a function, but the arguments of the macro are not evaluated before passing the value to the function. But instead the code of the arguments are passed to the macro, the macro then -can manipulate the code and return new code that is then evaluated. This happens during expantion +can manipulate the code and return new code that is then evaluated. This happens during expansion time before evaluation even happen. ## Lisp Macros @@ -53,7 +53,7 @@ if you use minus symbol it will add up the numbers: ;; ==> 3 ``` -Instead of modification of existin code you can also create new list: +Instead of modification of existing code you can also create new list: ```scheme (define-macro (foo expr) @@ -87,8 +87,8 @@ expand just your macro. ### New Control Follow Constructs -With macros, you can define new control flow (e.g. like `if` statements). Here is example of `when` -macro that is part of R7RS standard. +With macros, you can define new control flow (e.g. like `if` statements). Here is an example of +`when` macro that is part of R7RS standard. ```scheme (define-macro (when test . body) @@ -162,7 +162,7 @@ of symbols called `gensyms`. Each gensym is a unique symbol. Notice that let that call `gensym` is outside quasiquote so it will be evaluated when macro is executed by the output code will have a unique symbol instead of hard coded symbol `tmp`. -If you try to evaluate the macro you will get proper results: +If you try to evaluate the macro, you will get proper results: ```scheme (let ((tmp 1000)) @@ -174,8 +174,8 @@ If you try to evaluate the macro you will get proper results: ### Anaphoric Macros -Anaphoric macros are special kind of macros that leverage the leaking if internal data outside of -macro. This is called intentional capture of identifiers. They often expose one or more variable +Anaphoric macros are special kind of macros that leverage the leaking of internal data outside +the macro. This is called intentional capture of identifiers. They often expose one or more variable that can be used by the users of the macro. Example of such macro is `aif`: @@ -188,7 +188,7 @@ Example of such macro is `aif`: ,false))) ``` -This macro uses `it` variable to hold the testing value that can be used sindie user code: +This macro uses `it` variable to hold the testing value that can be used inside user code: ```scheme (let ((alist '((a . 10) (b . 20) (c . 30)))) @@ -221,14 +221,14 @@ The problem with Lisp macros is that they are not hygienic. But what it means? ### Hygiene -If macro is hygienic, it means that it guaranty no leaking of internal code outside of macro. In other -words guaranteed not to cause the accidental capture of identifiers. Scheme standard define new macro -system called `syntax-rules` that is hygienic. +If macro is hygienic, it means that it guaranty no leaking of internal code outside of macro. In +other words guaranteed not to cause the accidental capture of identifiers. Scheme standard define +new macro system called `syntax-rules` that is hygienic. But we have `gensym` is this not enough to make the macros safe? No -Here is example implementation of `unless` macro that is part of Scheme that fails because it's not -hygienic. +Here is an example implementation of `unless` macro that is part of Scheme that fails because it's +not hygienic. ```scheme (define-macro (unless test . body) @@ -252,10 +252,10 @@ user code. Hygiene of macros means that something like this can't happen. ### Syntax-rules -The `syntax-rules` in Scheme is different type of macros than lisp macros. It uses special pattern +The `syntax-rules` in Scheme is different type of macros than lisp macros. It uses a special pattern matching language. Syntax-rules is guarantee by the sec to be hygienic. -Here is simple definition of a hygienic macro in Scheme: +Here is the simple definition of a hygienic macro in Scheme: ```scheme (define-syntax unless @@ -331,10 +331,11 @@ the first element of the pattern is often `_` it matches against the name of the ### Elipsis -In lisp macros if you wanted to define a list of any values (including no values) you use [improper -list](/docs/scheme-intro/data-types#improper-list) (list with dot). In syntax-rules pattern you use elipsis to indicate list of items. The elipsis is afte the symbol. +In lisp macros if you wanted to define a list of any values (including no values) you use +[improper list](/docs/scheme-intro/data-types#improper-list) (list with dot). In syntax-rules +pattern you use an ellipsis to indicate a list of items. The ellipsis is after the symbol. -Example of usage of elipsis: +Example of usage of ellipsis: ```scheme (define-syntax values @@ -343,7 +344,8 @@ Example of usage of elipsis: '(a ...)))) ``` -This macro use Alist as a pattern and only return the values. Note that it doesn't work on varaible that hold the alist only for alist defined inside the code: +This macro use an alist as a pattern and only return the values. Note that it doesn't work on a +variable that hold the alist only for alist defined inside the code: ```scheme (values ((foo . "lorem") (bar . "ipsum") (baz . "dolor"))) @@ -375,7 +377,7 @@ Implementation">SRFI: body ...))))))) ``` -`syntax-paremetirize` works similar to +The `syntax-paremetirize` works similar to [parameters from R7RS](/docs/scheme-intro/core#dynamic-variables). You can use this macro like this: diff --git a/docs/docs/scheme-intro/next-step.md b/docs/docs/scheme-intro/next-step.md index 9c6e36044..87c967140 100644 --- a/docs/docs/scheme-intro/next-step.md +++ b/docs/docs/scheme-intro/next-step.md @@ -13,7 +13,7 @@ If you want to learn more about Scheme, these are the resources I recommend: ![Sketchy Scheme Book Cover](./img/sketchy-scheme.png) -There is free version in Archive.org called [Sketchy Lisp](https://archive.org/details/sketchy-lisp) but I recommend latest version. +There is a free version in Archive.org called [Sketchy Lisp](https://archive.org/details/sketchy-lisp) but I recommend latest version. * [Structure and Interpretation of Computer Programs](https://web.mit.edu/6.001/6.037/sicp.pdf) @@ -26,22 +26,24 @@ I also recommend video lectures. There are two versions. I recommend orignal by [![SICP MIT Lectures](./img/SICP-lectures.jpg)](https://www.youtube.com/playlist?list=PLB63C06FAF154F047) -This is [offical website of the lectures](https://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/). +This is an [official website of the lectures](https://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/). -They are not very good quality, but they are great and you should have no problems in seeing the code on the blackboard. +They are not very good quality, but they are great, and you should have no problems in seeing the +code on the blackboard. -There are also more recent lectures from 2010 at [Berkley](https://www.berkeley.edu/) by [Brian Harvey](https://people.eecs.berkeley.edu/~bh/). -Only a little bit better quality. +There are also more recent lectures from 2010 at [Berkley](https://www.berkeley.edu/) by +[Brian Harvey](https://people.eecs.berkeley.edu/~bh/). Only a little bit better quality. [![UC Berkeley CS 61A The Structure and Interpretation of Computer Programs, Spring 2010](./img/SCIP-lectures-berkley.jpg)](https://www.youtube.com/playlist?list=PLhMnuBfGeCDNgVzLPxF9o5UNKG1b-LFY9) ## Lisp Macros -If you want to learn more about lisp macros there are two great books: +If you want to learn more about lisp macros, there are two great books: * [On Lisp](https://www.paulgraham.com/onlisp.html) by [Paul Graham](https://www.paulgraham.com) - The book is out of print and you can download it for free. But if you prefer printed books you can get it printed on Lulu Express. + The book is out of print, and you can download it for free. But if you prefer printed books, you + can get it printed on Lulu Express. Here is article that explain how to do this: @@ -49,11 +51,11 @@ If you want to learn more about lisp macros there are two great books: You can also read this [discussion on Reddit](https://www.reddit.com/r/lisp/comments/l71amc/on_lisp_paperback_replica/). -* Antoher great book about advanced lisp macros is [Let over Lambda](https://letoverlambda.com/) by [Doug Hoyte](https://hoytech.com/). +* Another great book about advanced lisp macros is [Let over Lambda](https://letoverlambda.com/) by [Doug Hoyte](https://hoytech.com/). -**NOTE**: Unfortunetelly there are no good books about Scheme hygienic macros. +**NOTE**: Unfortunately, there are no good books about Scheme hygienic macros. ## More Resources -You can find common recipes inside [Scheme Cookbook](https://cookbook.scheme.org/) and [more Books +You can find common recipes inside [Scheme Cookbook](https://cookbook.scheme.org/) and [more books about Scheme](https://books.scheme.org/) on [official Scheme website](https://www.scheme.org/). diff --git a/docs/docs/scheme-intro/streams.md b/docs/docs/scheme-intro/streams.md index 59f63949e..f582014fc 100644 --- a/docs/docs/scheme-intro/streams.md +++ b/docs/docs/scheme-intro/streams.md @@ -27,7 +27,7 @@ If you print this expression, you will get something like this (it depends on Sc ;; ==> (1 . #) ``` -The cdr is a promise that needs to be forced to get evaluated. +The `cdr` is a promise that needs to be forced to get evaluated. ```scheme (let ((x (cons 1 (delay 2)))) @@ -111,7 +111,7 @@ You can sue this function to create stream of integers: (define integers (stream-cons 1 (stream-add integers ones))) ``` -To prove that it works you can get first 10 elements with `stream-take`: +To prove that it works, you can get first 10 elements with `stream-take`: ```scheme (display (stream-take 10 integers))