From 89b4bffa374210df5a117df1a773c795436f735f Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Mon, 6 Sep 2021 20:13:42 +0300 Subject: [PATCH] Add unicode-lambda recipe --- recipes/unicode-lambda.md | 55 +++++++++++++++++++++++++++++++++++++++ www-index.scm | 3 ++- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 recipes/unicode-lambda.md diff --git a/recipes/unicode-lambda.md b/recipes/unicode-lambda.md new file mode 100644 index 0000000..7c1bfe2 --- /dev/null +++ b/recipes/unicode-lambda.md @@ -0,0 +1,55 @@ +# Unicode lambda + +## Problem + +Instead of + +`(lambda (a b c) (* a (+ b c))` + +you'd like to type + +`(λ (a b c) (* a (+ b c)))` + +i.e. use the Unicode greek letter lambda in your Scheme code. + +## Solution + +### Using import renaming + +R6RS: + +```Scheme +(import (rename (only (rnrs base) lambda) (lambda λ))) +``` + +R7RS: + +```Scheme +(import (rename (only (scheme base) lambda) (lambda λ))) +``` + +### Using a macro + +```Scheme +(define-syntax λ (syntax-rules () ((λ . rest) (lambda . rest)))) +``` + +or the non-standard: + +```Scheme +(define-macro (λ . rest) `(lambda ,@rest)) +``` + +### Spelling out `lambda` in source files but displaying `λ` on screen + +See [Display Unicode symbols in Emacs](https://cookbook.scheme.org/display-unicode-symbols-in-emacs/). + +### Safely storing `λ` in text files + +`λ` is one Unicode codepoint, so changing the Unicode normalization +form does not change the way `λ` characters are encoded. In R7RS `λ` +can also be escaped using vertical bar syntax as `|\x3bb;|`. + +## See also + +[Unicode lambda at Scheme Surveys](https://doc.scheme.org/surveys/unicode-lambda/) diff --git a/www-index.scm b/www-index.scm index 128216d..582215c 100644 --- a/www-index.scm +++ b/www-index.scm @@ -48,7 +48,8 @@ ("Macros" "bind-optional-arguments" "check-for-symbol-in-syntax-rules" - "define-symbols") + "define-symbols" + "unicode-lambda") ("Tool integrations" "display-unicode-symbols-in-emacs"))