Browse Source

Removed toy language experiments

master
Stephen Starkey 2 years ago
parent
commit
00c4116137
  1. 102
      README.md
  2. 6
      build
  3. 2
      clean-scm
  4. 0
      lojong
  5. 3
      lojong-rkt
  6. 9
      lojong-scm
  7. 2
      publish
  8. 66
      src/lojong.rkt
  9. 62
      src/lojong.scm

102
README.md

@ -1,9 +1,6 @@
# lojong
Various transformations on the list of Atisha's lojong slogans.
Code written in Clojure (`src/lojong.clj`),
Racket (`src/lojong.rkt`), and Chicken Scheme (`src/lojong.scm`)
dialects.
Taken, with some modifications, from
<http://www.unfetteredmind.org/mindtraining/>
@ -18,111 +15,28 @@ These files are generated by this project:
## Preparing your development environment
### Clojure with Leiningen
Install Leiningen: <https://leiningen.org/>
If you want to compile the LaTeX contents, you'll need an installation
of LaTeX for your operating system. It should include the `pdflatex`
command.
### Racket
Install Racket:
<https://www.racket-lang.org/download/>
Run the following:
raco pkg install rackjure
raco pkg install yaml
### Chicken Scheme
Install Chicken Scheme:
<http://code.call-cc.org>
sudo apt install libyaml-dev ;; or equivalent for your platform
sudo chicken-install clojurian
sudo chicken-install json
sudo chicken-install random-bsd
sudo chicken-install yaml
## Program Usage
### Clojure
This program takes ~2 seconds to run AFTER it's been compiled for the first time.
Produce a single lojong slogan:
```./lojong-clj```
Produce the complete sequence as a fortune file and install it
(requires that you have installed the `fortune` program using your
package manager):
./lojong-clj fortune > lojong && \
strfile lojong && \
fortune lojong
Convert the complete sequence to a JSON vector:
./lojong-clj json > lojong.json
```./lojong```
Build a nice set of flash cards using LaTeX:
mkdir -p tex && \
./lojong-clj tex > tex/lojong.tex && \
pushd tex && \
pdflatex lojong.tex; \
popd
Or build a bunch of artifacts, including JSON, fortune, and PDF files,
using `./build`
Or do all these things at once using `./build-clj` (PDF and so forth
will be output to `target/documents`)
### Racket
This program takes 1 second to run.
Produce a single lojong slogan:
```./lojong-rkt```
Produce the complete sequence as a fortune file and install it
(requires that you have installed the `fortune` program using your
package manager):
./lojong-rkt fortune > lojong && \
strfile lojong && \
fortune lojong
### Chicken Scheme
This program takes less than 0.02 seconds to run AFTER first compile.
Produce a single lojong slogan:
```./lojong-scm```
Produce the complete sequence as a fortune file and install it
(requires that you have installed the `fortune` program using your
package manager):
./lojong-scm fortune > lojong && \
strfile lojong && \
fortune lojong
Convert the complete sequence to a JSON vector:
./lojong-scm json > lojong.json
They will show up in `target/documents`.
## Development
The `lojong-clj` script relies on the presence of an uberjar. It tries to build
it if it doesn't exist. Successive executions use that jar file. If you want to
change code and see how things are different, you'll need to `lein clean`
The `lojong-scm` script relies on the presence of the lojong binary. It
tries to build it if it doesn't exist. Successive executions use that binary.
If you want to change code and see how things are different, you'll need to
`./clean-scm`
The `lojong` script relies on the presence of an uberjar. It tries to
build one if it doesn't exist. Successive executions use that jar file.
If you want to change code and see how things are different, you'll need
to `lein clean`
## License

6
build-clj → build

@ -3,15 +3,15 @@
OUTDIR=target/documents
lein do clean, uberjar
mkdir -p $OUTDIR
./lojong-clj fortune >$OUTDIR/lojong
./lojong-clj json >$OUTDIR/lojong.json
./lojong fortune >$OUTDIR/lojong
./lojong json >$OUTDIR/lojong.json
TEX_CMD=$(which pdflatex)
if [ "$TEX_CMD" != "" ]; then
TEXDIR=target/tex
mkdir -p $TEXDIR
./lojong-clj tex >$TEXDIR/lojong.tex
./lojong tex >$TEXDIR/lojong.tex
pushd $TEXDIR
$TEX_CMD lojong.tex
popd

2
clean-scm

@ -1,2 +0,0 @@
#!/usr/bin/env bash
rm -f ./lojong

0
lojong-clj → lojong

3
lojong-rkt

@ -1,3 +0,0 @@
#!/usr/bin/env bash
racket src/lojong.rkt $*

9
lojong-scm

@ -1,9 +0,0 @@
#!/usr/bin/env bash
FILE=lojong
if [ ! -f $FILE ]; then
echo "Building lojong binary" 1>&2
csc src/lojong.scm
mv src/lojong .
fi
./lojong $*

2
publish-clj → publish

@ -1,4 +1,4 @@
#!/usr/bin/env bash
OUTDIR=target/documents
./build-clj
./build
aws s3 sync $OUTDIR/ s3://lojong.sstarkey/ --delete

66
src/lojong.rkt

@ -1,66 +0,0 @@
; This file is part of lojong.
;
; lojong is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; lojong is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with lojong. If not, see <https://www.gnu.org/licenses/>.
#lang racket
(require racket/runtime-path)
(require json)
(require rackjure/threading)
(require yaml)
;; # Lojong Slogan Formatter #
;;
;; Taken, with some modifications, from
;; <http://www.unfetteredmind.org/mindtraining/>
;;
;; When run without arguments, this program displays a single lojong slogan.
;; If you give it 'fortune' as an argument, it will render
;; the entire sequence of slogans as a fortune file to stdout.
(define-runtime-path slogans-file "../resources/slogans.yaml")
(define slogans (file->yaml slogans-file))
(define (format-description d)
(if (string? d) d (string-join d "\n ")))
(define (format-item category-name p)
(string-append (first p) "\n "
(~> p second format-description)
"\n\n"
"(" category-name ")"))
(define (format-category category)
(let ([category-name (first category)]
[category-items (rest category)])
(map ((curry format-item) category-name) category-items)))
(define (slogan-number slogan)
(~>> slogan (regexp-match #px"^\\d+") car string->number))
(define (slogan<? l r)
(< (slogan-number l) (slogan-number r)))
(define slogan-list
(~> (~>> slogans hash->list (map format-category) (apply append))
(sort slogan<?)))
(let ([args (current-command-line-arguments)])
(cond
[(and (= 1 (vector-length args)) (string=? "fortune" (sequence-ref args 0)))
(~> slogan-list (string-join "\n%\n") (string-append "\n%") display)]
[(and (= 1 (vector-length args)) (string=? "json" (sequence-ref args 0)))
(write-json slogan-list)]
[else (~> slogan-list shuffle first display)])
(display "\n"))

62
src/lojong.scm

@ -1,62 +0,0 @@
; This file is part of lojong.
;
; lojong is free software: you can redistribute it and/or modify
; it under the terms of the GNU Affero General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; lojong is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License
; along with lojong. If not, see <https://www.gnu.org/licenses/>.
(require-extension clojurian-syntax)
(require-extension json)
(require-extension random-bsd)
(require-extension yaml)
;; # Lojong Slogan Formatter #
;;
;; Taken, with some modifications, from
;; <http://www.unfetteredmind.org/mindtraining/>
;;
;; When run without arguments, this program displays a single lojong slogan.
;; If you give it 'fortune' as an argument, it will render
;; the entire sequence of slogans as a fortune file to stdout.
(define slogans-file "resources/slogans.yaml")
(define slogans (-> slogans-file read-all yaml-load))
(define (format-description d)
(if (string? d) d (string-intersperse d "\n ")))
(define (format-item category-name p)
(string-append
(car p) "\n "
(-> p cdr car format-description)
"\n\n"
"(" category-name ")"))
(define (format-category category)
(let ([category-name (car category)]
[category-items (cdr category)])
(map (lambda (p) (format-item category-name p)) category-items)))
(define slogan-list (->> slogans (map format-category) (apply append)))
(let ([args (command-line-arguments)])
(cond
[(and (= 1 (length args)) (string=? "fortune" (car args)))
(-> slogan-list
(string-intersperse "\n%\n")
(string-append "\n%")
display)]
[(and (= 1 (length args)) (string=? "json" (car args)))
(json-write slogan-list)]
[else
(->> slogan-list length random-integer (list-ref slogan-list) display)])
(display "\n"))
Loading…
Cancel
Save