git @ Cat's Eye Technologies Pixley / 53fa818
Simpler. But also broken! I can feel the abyss peering back... Cat's Eye Technologies 11 years ago
4 changed file(s) with 42 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
00 #!/bin/sh
11
2 # A wrapper script around miniscm (my fork) to get it to behave more or less
3 # how we want.
2 # Support the miniscm-0.85p1 Scheme implementation as if it behaved like
3 # plt-r5rs behaves, i.e.:
4
5 # % echo '(+ 1 2)' > program.scm
6 # % miniscm.sh program.scm
7 # 3
8 # %
9
10 # Some caveats apply (Protip: some caveats *always* apply.)
411
512 cat >init.scm <<EOF
613 (define (equal? x y)
1320 (define (list? x) (or (eq? x '()) (and (pair? x) (list? (cdr x)))))
1421 EOF
1522
16 miniscm -q -e <$1
23 echo "(display" >tmpprog.scm
24 cat $1 >>tmpprog.scm
25 echo ") (newline)" >>tmpprog.scm
26
27 miniscm -q -e <tmpprog.scm
28
29 rm -f tmpprog.scm
00 #!/bin/sh
11
2 # A wrapper script around tinyscheme to get it to behave more or less
3 # how we want.
2 # Support the tinyscheme Scheme implementation as if it behaved like
3 # plt-r5rs behaves, i.e.:
44
5 cat >init.scm <<EOF
6 (define (equal? x y)
7 (if (pair? x)
8 (and (pair? y)
9 (equal? (car x) (car y))
10 (equal? (cdr x) (cdr y)))
11 (and (not (pair? y))
12 (eqv? x y))))
13 (define (list? x) (or (eq? x '()) (and (pair? x) (list? (cdr x)))))
14 EOF
5 # % echo '(+ 1 2)' > program.scm
6 # % tinyscheme.sh program.scm
7 # 3
8 # %
159
16 tinyscheme $1
10 # Note: if tinyscheme is installed from source, the executable's name
11 # will be 'scheme' and it will require 'init.scm' in the current
12 # directory. However, if it is installed from a package (using apt-get,) the
13 # executable's name will be 'tinyscheme' and it will not require 'init.scm'
14 # in the current directory. Just one of those cases where the package
15 # managers decide to try to make your life easier by making things obstensibly
16 # saner while at the same time introducing an incompatibility.
17 #
18 # This wrapper assumes you have installed it from a package.
19
20 echo "(display" >tmpprog.scm
21 cat $1 >>tmpprog.scm
22 echo ") (newline)" >>tmpprog.scm
23
24 tinyscheme tmpprog.scm
25
26 rm -f tmpprog.scm
3535 ### Initialization ###
3636
3737 SCHEME_CMD=$SCHEME_IMPL # command to run for impl
38 CAN_EVAL=yes # impl can eval s-exprs as Scheme progs?
39 EXPLICIT_QUIT=no # impl needs explicit (quit) to stop?
40 NEED_EQUAL_P=no # impl lacks `equal?`
41 NEED_LIST_P=no # impl lacks `list?`
4238 NEED_DUMP_SEXP=no # impl needs extra support to write s-exp?
4339
4440 if [ "${SCHEME_IMPL}x" = "plt-r5rsx" ]; then
5147 # don't expect. To work around this, this script prepends a
5248 # definition of a function "dump-sexp" which explicitly formats
5349 # the resulting S-expression in the way the tests do expect.
54 SCHEME_CMD='script/tinyscheme.sh'
50 #
5551 NEED_DUMP_SEXP=yes
5652 elif [ "${SCHEME_IMPL}x" = "miniscmx" ]; then
5753 # Mini-Scheme is supported, but version 0.85p1 (a fork available
6157 # miniscm's core lacks "equal?" and "list?", so definitions for
6258 # those are also prepended to the source we want to run.
6359 SCHEME_CMD='script/miniscm.sh'
64 NEED_DUMP_SEXP=yes
6560 else
6661 echo "Please set SCHEME_IMPL to one of the following:"
6762 echo "plt-r5rs, tinyscheme, miniscm"
7671 ### Generate prelude ###
7772
7873 echo -n '' >prelude.scm
79
80 if [ "$NEED_EQUAL_P" = "yes" ]; then
81 # define `equal?` in Scheme. written by a.k.
82 cat >>prelude.scm <<EOF
83 (define (equal? x y)
84 (if (pair? x)
85 (and (pair? y)
86 (equal? (car x) (car y))
87 (equal? (cdr x) (cdr y)))
88 (and (not (pair? y))
89 (eqv? x y))))
90 EOF
91 fi
92
93 if [ "$NEED_LIST_P" = "yes" ]; then
94 # define `list?` in Scheme. written by c.p.
95 cat >>prelude.scm <<EOF
96 (define (list? x) (or (eq? x '()) (and (pair? x) (list? (cdr x)))))
97 EOF
98 fi
9974
10075 if [ "$NEED_DUMP_SEXP" = "yes" ]; then
10176 # extra support to dump a sexp (without abbreviating stuff)
143118 cat >>program.scm <<EOF
144119 (display tower)
145120 EOF
146 if [ "${EXPLICIT_QUIT}" = "yes" ]; then
147 echo '(quit)' >>program.scm
148 fi
149121
150122 if [ ! "${DEBUG}x" = "x" ]; then
151123 less program.scm
162134 ${SCHEME_CMD} program.scm >>next.scm
163135 echo ') (newline)' >>next.scm
164136 fi
165 if [ "${EXPLICIT_QUIT}" = "yes" ]; then
166 echo '(quit)' >>next.scm
167 fi
168137
169138 mv next.scm program.scm
170139 ${SCHEME_CMD} program.scm
1111 | (quote hello)
1212 = hello
1313
14 | (quote (foo bar))
15 = (foo bar)
14 | (quote (quote quote))
15 = (quote quote)
1616
1717 `cons` lets you create a list from some thing and another list.
1818