From d1cf70012606f25bc1d2eddd7c0a17465dbb0994 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 20 Oct 2023 06:53:20 -0700 Subject: [PATCH] Updates and additions to 1989/jar.2 Add a hexa-layered chocolate fudge cake :-) (see below) Added try.me.sh script which will take a list of files (if no arg specified it has a default of files added, as described below) and feed each one to jar.2. The lisp files added are: fib.lisp from Yusuke Endoh; try.me.txt from the author; and chocolate_cake.lisp from me. The cake one uses '(quote ...)' that the program supports but the other files do not and plus who can't use a bit (or lot :-) ) of chocolate cake? Made the entry look slightly more like the original by adding back the macros that can't be used but still are part of the entry (#defines for define and include). --- 1989/jar.2/Makefile | 5 +-- 1989/jar.2/README.md | 58 ++++++++++++++++++++++------------ 1989/jar.2/chocolate_cake.lisp | 8 +++++ 1989/jar.2/fib.lisp | 5 +++ 1989/jar.2/jar.2.c | 2 ++ 1989/jar.2/try.me.sh | 17 ++++++++++ 1989/jar.2/try.me.txt | 18 +++++++++++ thanks-for-fixes.md | 8 +++++ 8 files changed, 99 insertions(+), 22 deletions(-) create mode 100644 1989/jar.2/chocolate_cake.lisp create mode 100644 1989/jar.2/fib.lisp create mode 100755 1989/jar.2/try.me.sh create mode 100644 1989/jar.2/try.me.txt diff --git a/1989/jar.2/Makefile b/1989/jar.2/Makefile index 7616924c6..97904685f 100644 --- a/1989/jar.2/Makefile +++ b/1989/jar.2/Makefile @@ -39,7 +39,7 @@ include ../../var.mk # Common C compiler warnings to silence # CSILENCE= -Wno-implicit-function-declaration -Wno-missing-braces -Wno-parentheses \ - -Wno-deprecated-non-prototype -Wno-pedantic -Wno-strict-prototypes + -Wno-deprecated-non-prototype -Wno-pedantic -Wno-strict-prototypes -Wno-implicit-int # Common C compiler warning flags # @@ -130,8 +130,9 @@ all: data ${TARGET} sandwich supernova deep_magic magic charon pluto ${PROG}: ${PROG}.c - @echo NOTE: invalid input will cause this entry to dump core. ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} + @echo + @echo NOTE: invalid input will cause this entry to dump core. See README.md for details. # alternative executable # diff --git a/1989/jar.2/README.md b/1989/jar.2/README.md index ce4d8a1ed..d12bb3830 100644 --- a/1989/jar.2/README.md +++ b/1989/jar.2/README.md @@ -19,13 +19,31 @@ make all ```sh ./jar.2 [enter some lisp] + +./jar.2 < some_lisp_file + ``` + NOTE: this entry will likely segfault on invalid input. +## Try: + +```sh +./try.me.sh + +cat chocolate_cake.lisp ; ./jar.2 < chocolate_cake.lisp + +./try.me.sh chocolate_cake.lisp + +./try.me.sh try.me.txt + +``` + + ## Judges' remarks: -This is the most useful program entered this year. It is a +This is the most useful program submitted this year. It is a rather large subset of lisp. It has no error recovery, and performs rather poorly in a number of cases. Even so, placing all this functionality in such a small, densely packed program, @@ -35,7 +53,7 @@ is impressive enough to win the Best of show award. ## Author's remarks: This program implements a Lisp interpreter in 1465 bytes of source. -Some sophisticated features supported, eg. functionals and recursion.\ +Some sophisticated features supported, e.g. functionals and recursion. The special-forms/functions/variables implemented are: - \+ @@ -61,24 +79,24 @@ prints out the return values. End execution by typing an end-of-file character. ```lisp - (+ 2.5 3.1) - (defun fib (n) - (if (< n 2) - 1 - (+ (fib (- n 2)) (fib (- n 1))))) - (fib 10) - (defun ! (x) (if (equal x 0) 1 (* x (! (- x 1))))) - (! 7) - (defun fn1 (fn) (+ (fn 1 2) (fn 3 4))) - (defun fn2 (a b) (+ a b)) - (fn1 (function +)) - (fn1 (function fn2)) - (fn1 (function (lambda (z1 z2) (+ z1 z2)))) - (quote a) - (cons (quote (a b)) (quote (c d e))) - (cons (quote (f)) ()) - (car (quote (a b c))) - (cdr (cdr (quote (g h i)))) +(+ 2.5 3.1) +(defun fib (n) + (if (< n 2) + 1 + (+ (fib (- n 2)) (fib (- n 1))))) +(fib 10) +(defun ! (x) (if (equal x 0) 1 (* x (! (- x 1))))) +(! 7) +(defun fn1 (fn) (+ (fn 1 2) (fn 3 4))) +(defun fn2 (a b) (+ a b)) +(fn1 (function +)) +(fn1 (function fn2)) +(fn1 (function (lambda (z1 z2) (+ z1 z2)))) +(quote a) +(cons (quote (a b)) (quote (c d e))) +(cons (quote (f)) ()) +(car (quote (a b c))) +(cdr (cdr (quote (g h i)))) ``` diff --git a/1989/jar.2/chocolate_cake.lisp b/1989/jar.2/chocolate_cake.lisp new file mode 100644 index 000000000..9cf38cbf4 --- /dev/null +++ b/1989/jar.2/chocolate_cake.lisp @@ -0,0 +1,8 @@ +(quote ......................) +(quote ||||||||||||||||||||||) +(quote [[[--hexa-layered--]]]) +(quote [[[----layered-----]]]) +(quote [[[---chocolate----]]]) +(quote [[[-----fudge------]]]) +(quote [[[-----cake-------]]]) +(quote [[[[[[[[[[]]]]]]]]]]]]) diff --git a/1989/jar.2/fib.lisp b/1989/jar.2/fib.lisp new file mode 100644 index 000000000..8c806114b --- /dev/null +++ b/1989/jar.2/fib.lisp @@ -0,0 +1,5 @@ +(defun fib (n) + (if (< n 2) + 1 + (+ (fib (- n 2)) (fib (- n 1))))) +(fib 10) diff --git a/1989/jar.2/jar.2.c b/1989/jar.2/jar.2.c index c53aa121e..88afe74db 100644 --- a/1989/jar.2/jar.2.c +++ b/1989/jar.2/jar.2.c @@ -1,4 +1,6 @@ #include +#define d define +#define a include #include #include #define p char* diff --git a/1989/jar.2/try.me.sh b/1989/jar.2/try.me.sh new file mode 100755 index 000000000..200dbac37 --- /dev/null +++ b/1989/jar.2/try.me.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# +# demo for 1989/jar.2 - run entry with one or more files + +make all || exit 1 + +if [[ "$#" -lt 1 ]]; then + FILES="try.me.txt fib.lisp chocolate_cake.lisp" +else + FILES="$*" +fi + +for f in $FILES; do + if [[ -e "$f" && -r "$f" ]]; then + ./jar.2 < "$f" + fi +done diff --git a/1989/jar.2/try.me.txt b/1989/jar.2/try.me.txt new file mode 100644 index 000000000..842935b6d --- /dev/null +++ b/1989/jar.2/try.me.txt @@ -0,0 +1,18 @@ +(+ 2.5 3.1) +(defun fib (n) + (if (< n 2) + 1 + (+ (fib (- n 2)) (fib (- n 1))))) +(fib 10) +(defun ! (x) (if (equal x 0) 1 (* x (! (- x 1))))) +(! 7) +(defun fn1 (fn) (+ (fn 1 2) (fn 3 4))) +(defun fn2 (a b) (+ a b)) +(fn1 (function +)) +(fn1 (function fn2)) +(fn1 (function (lambda (z1 z2) (+ z1 z2)))) +(quote a) +(cons (quote (a b)) (quote (c d e))) +(cons (quote (f)) ()) +(car (quote (a b c))) +(cdr (cdr (quote (g h i)))) diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index abaa951eb..bea1f23fb 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -538,6 +538,14 @@ code like: He notes that there _is_ a way to get it (or something close to it) to work. Do you know how? +Cody also provided the [try.me.sh](1989/jar.2/try.me.sh) script and the +supplementary files [try.me.txt](1989/jar.2/try.me.txt), +[fib.lisp](1989/jar.2/fib.lisp) and +[chocolate_cake.lisp](1989/jar.2/chocolate_cake.lisp). The `try.me.txt` comes +from the author and the `fib.lisp` comes from Yusuke. Cody wrote the script and +offered us some chocolate cake :-) See README.md for details on how to use the +script. + ## [1989/ovdluhe](1989/ovdluhe/ovdluhe.c) ([README.md](1989/ovdluhe/README.md]))