Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
#######
#
# E-scripts on Clojure.
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/e/clojure.e>
#           or at <http://angg.twu.net/e/clojure.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######




# «.simple-forth»	(to "simple-forth")
# «.simple-graphics»	(to "simple-graphics")





#####
#
# A simple Forth interpreter
# 2011sep23
#
#####

# «simple-forth»  (to ".simple-forth")
# (find-es "java" "clojure")
# http://nakkaya.com/2010/12/02/a-simple-forth-interpreter-in-clojure/

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
clojure -r

(ns forth
  (:refer-clojure :exclude [pop!]))

(declare forth-eval)

(defn pop! [stack]
  (let [first (first @stack)]
    (swap! stack pop)
    first))

(defn push! [stack item]
  (swap! stack conj item))

(defn next-token [stream]
  (if (. stream hasNextBigInteger)
    (. stream nextBigInteger)
    (. stream next)))

(defn init-env []
  (let [stream (java.util.Scanner. System/in)
        stack (atom '())
        dict (atom {})
        prim (fn [id f] (swap! dict assoc id f))]
    (prim ".s" #(do (println "---")
                    (doseq [s @stack] (println s))
                    (println "---")))
    (prim "cr" #(println))
    (prim "+" #(push! stack (+ (pop! stack) (pop! stack))))
    (prim "*" #(push! stack (* (pop! stack) (pop! stack))))
    (prim "/" #(let [a (pop! stack)
                     b (pop! stack)]
                 (push! stack (/ b a))))
    (prim "-" #(let [a (pop! stack)
                     b (pop! stack)]
                 (push! stack (- b a))))
    (prim "dup" #(push! stack (first @stack)))
    (prim "." #(println (pop! stack)))
    (prim ":" #(let [name (next-token stream)
                     block (loop [b [] n (next-token stream)]
                             (if (= n ";")
                               b
                               (recur (conj b n) (next-token stream))))]
                 (prim name (fn [] (doseq [w block]
                                     (forth-eval dict stack w))))))
    [dict stack stream]))

(defn forth-eval [dict stack token]
  (cond (contains? @dict token) ((@dict token))
        (number? token) (push! stack token)
        :default (println token "??")))

(defn repl [env]
  (let [[dict stack stream] env
        token (next-token stream)]
    (when (not= token "bye")
      (forth-eval dict stack token)
      (repl env))))

(repl (init-env))

5 6 + 7 8 + *
.
cr

3 2 1 + *
. cr

: sq dup * ;
2 sq
.

bye




#####
#
# Simple graphics
# 2011sep24
#
#####

# «simple-graphics»  (to ".simple-graphics")
# (find-books "__comp/__comp.el" "clojure")
# (find-joyofclojurepage (+ 33  52) "(def frame (java.awt.Frame.))")
# (find-joyofclojuretext            "(def frame (java.awt.Frame.))")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
clojure -r

(def frame (java.awt.Frame.))
(.setVisible frame true)
(.setSize frame (java.awt.Dimension. 200 200))

(defn xors [max-x max-y]
  (for [x (range max-x) y (range max-y)]
    [x y (bit-xor x y)]))
 
(doseq [[x y xor] (xors 200 200)]
  (.setColor gfx (java.awt.Color. xor xor xor))
  (.fillRect gfx x y 1 1))







http://www.infoq.com/presentations/Simple-Made-Easy




#  Local Variables:
#  coding:               raw-text-unix
#  ee-delimiter-hash:    "\n#*\n"
#  ee-delimiter-percent: "\n%*\n"
#  ee-anchor-format:     "«%s»"
#  End: