-
-
Notifications
You must be signed in to change notification settings - Fork 12
Cheat Sheet: Scheme (r7rs)
This is a cheat sheet, not a tutorial. It's meant to refresh your memory or help you find search terms for the docs, for those familiar with Scheme. Not all alternatives are macros. Not all macros are listed, only those that correspond to selected Scheme features.
Scheme Primitive | Alternatives |
---|---|
lambda |
lambda |
if |
if-else , when
|
set! |
set! , set@ , define , my# . |
include /include-ci
|
define on a fully qualified name. |
Scheme Derived Conditional | Alternatives |
---|---|
cond |
cond |
case |
case |
and |
ands |
or |
ors |
when |
when |
unless |
unless |
cond-expand |
.#(cond -, probably with information from sys. or os.
|
Scheme Derived Binding | Alternatives |
---|---|
let |
let |
let* |
let*from . Maybe my# . |
letrec /letrec*
|
my# . Possibly type . |
let-values |
let-from . (Python lacks multiple returns and conventionally returns a tuple instead.) |
let*-values |
let*from |
Scheme Derived Iterating | Alternatives |
---|---|
do |
any-map with range
|
named let
|
loop-from |
Other Constructs | Alternatives |
---|---|
parameterize |
defvar /binding , mk#patch
|
guard |
engarde (prelude ) |
begin |
progn |
case-lambda |
lambda with a case inside |
Templates are pretty similar to Scheme's quasiquotation: `
, ,
, ,@
. Beware that Lissp automatically qualifies symbols (like Clojure). We can still interpolate unqualified symbols though. $#
does gensyms. Scheme's hygienic macros are not implemented, but we do have defmacro
.
What looks like linked-list notation in Lissp makes tuples instead, so many linked-list operations are not applicable. (Tuples are more like vectors, but immutable.)
Python has no dedicated character type and instead uses length-1 strings.
Python doesn't have the tail recursion optimization. You can use loop-from
/recur-from
for direct recursion without using up the call stack. Python can do coroutines via two-way generators. We have Ensue
(from the prelude
) for that.
We don't have delay
, force
, or delay-force
either. Python 3 uses lazy mutable iterators pervasively. They can be split with tee
, but the results are still mutable iterators. ft#cache
applied to an O#
expression might be similar to a delay
, which we can force by calling it. We needn't bother with the cache bit when the expression is pure (and fast).
Even for the R7RS-small base library, there are too many procedures to list for a cheat sheet. The hissp
package bundles some metaprograms, but has no standard library of functions (or classes) and instead relies on Python's. For operator functions, see the operator
module (these are all imported by the prelude
. It also imports itertools
.) /#
makes a binary operator variadic via a reduce (E.g., (/#add 1 2 3) ; 6
). For the rest, you need a Python reference.