git/Forthe/commit/9c7443d01202ac7b38a75f00b073cdbeb0f77821.html (5334 bytes)
1 <!DOCTYPE html> 2 <html lang="en"><head><meta charset="UTF-8" /> 3 <meta name="viewport" content="width=device-width, initial-scale=1" /> 4 <title>Forthe 9c7443d0 - Recently Written</title> 5 <link rel="stylesheet" href="../../stagit.css" /> 6 </head><body> 7 <div id="top"><a href="../../../index.html">Recently Written</a> · <a href="../../index.html">git</a></div> 8 <h1>Forthe</h1><span class="desc">Forth-like DSL.</span><p class="url">git clone https://github.com/equwal/Forthe</p><p><a href="../../Forthe/index.html">Log</a> | <a href="../../Forthe/files.html">Files</a> | <a href="../../Forthe/refs.html">Refs</a></p><hr/> 9 <div id="content"> 10 <pre>commit 9c7443d01202ac7b38a75f00b073cdbeb0f77821 11 Spenser Truex <spensertruexonline@gmail.com> 12 2018-12-05 20:31:20 -0800 13 14 ENV vars supported. 15 16 </pre><pre> .gitignore | 1 + 17 README.md | 19 ++++++++++++------- 18 eforth.el | 12 ++++++------ 19 3 files changed, 19 insertions(+), 13 deletions(-) 20 </pre><pre>diff --git a/.gitignore b/.gitignore 21 new file mode 100644 22 index 0000000..e4e5f6c 23 --- /dev/null 24 +++ b/.gitignore 25 <span class="h">@@ -0,0 +1 @@</span> 26 <span class="a">+*~</span> 27 \ No newline at end of file 28 diff --git a/README.md b/README.md 29 index f0e0a3a..c34cf51 100644 30 --- a/README.md 31 +++ b/README.md 32 <span class="h">@@ -1,7 +1,6 @@</span> 33 eFORTH 34 === 35 <span class="d">-# What?</span> 36 <span class="d">-This is an implementation of an elisp-based FORTH. This means that elisp is used to write the function definitions. In fact, no FORTH function definitions are provided at all to the eforth macro from the library. </span> 37 <span class="a">+This is an implementation of an elisp-based FORTH. This means that elisp is used to write the function definitions. In fact, no FORTH function definitions are provided at all to the eforth macro from the library. **The main benefit comes from reducing the verbosity of elisp in a small Domain Specific Language the programmer defines.**</span> 38 # How? 39 Forth code is gone through by the pointer moving through the call stack. When a non-function is found, it is added to the argument stack. When a function is found, it uses up the argument stack if it has arguments, or just runs if it is nullary. Nothing else is provided by the implementation. 40 # Why? 41 <span class="h">@@ -12,11 +11,11 @@ and there is no need to define a return stack.</span> 42 # Usage: 43 example: 44 45 <span class="d">-```</span> 46 <span class="a">+```elisp</span> 47 (require 'eforth) 48 (defun 8pan () 49 (interactive) 50 <span class="d">- (eforth ((n . (lambda () (switch-to-buffer nil)))</span> 51 <span class="a">+ (eforth '((n . (lambda () (switch-to-buffer nil)))</span> 52 (d . split-window-below) 53 (r . split-window-right) 54 (wr . windmove-right) 55 <span class="h">@@ -28,6 +27,7 @@ example:</span> 56 (nf . other-frame)) 57 (cf del r r wr wr r d wr d wl wl d wl d wr n wr n wr n wl wl wl wd n 58 wr n wr n wr n wl wl wl wu nf))) 59 <span class="a">+</span> 60 ``` 61 62 `M-x 8pan` will produce a new frame with eight panels (emacs-speak: "windows"). Here is how it works: 63 <span class="h">@@ -36,9 +36,14 @@ example:</span> 64 that there are no arguments used, since all of these are nullary functions. Here is how you might use arguments: 65 66 67 <span class="d">-```</span> 68 <span class="d">-(eforth ((ff . find-file)) ("~/some-file" ff))</span> 69 <span class="a">+```elisp</span> 70 <span class="a">+(eforth '((ff . find-file)) ("~/some-file" ff))</span> 71 ``` 72 73 <span class="d">-Here we ran `(find-file "~/some-file")`.</span> 74 <span class="a">+Here we ran `(find-file "~/some-file")`. If you need to reuse a forth, just define an `*env*` variable:</span> 75 76 <span class="a">+``` elisp</span> 77 <span class="a">+(defvar *env* '((>r . to-return-stack) ...))</span> 78 <span class="a">+(eforth *env* (forth code here ...))</span> 79 <span class="a">+</span> 80 <span class="a">+```</span> 81 diff --git a/eforth.el b/eforth.el 82 index 77adc3a..27df4a4 100644 83 --- a/eforth.el 84 +++ b/eforth.el 85 <span class="h">@@ -2,7 +2,7 @@</span> 86 (let ((l)) 87 (dolist (i list-of-lists (nreverse l)) 88 (push (list it i) l)))) 89 <span class="d">-(defmacro eforth (lang list)</span> 90 <span class="a">+(defmacro inner-eforth (lang list)</span> 91 "Forth without a return stack." 92 `(progn ,@(let ((s) (l)) 93 (dolist (i list (nreverse (add-to-each 'funcall l))) 94 <span class="h">@@ -13,14 +13,14 @@</span> 95 (setf s nil)) 96 (push `(lambda () (,fn)) l))) 97 (push i s)))))) 98 <span class="d">-;; (defmacro eforth (lang list)</span> 99 <span class="d">-;; `(progn ,@(inner-eforth lang lsit)))</span> 100 <span class="d">-(eforth ((ff . find-file)) ("~/bogus/" ff))</span> 101 <span class="d">-(eforth ((d . split-window-below))</span> 102 <span class="a">+(defmacro eforth (lang list)</span> 103 <span class="a">+ `(inner-eforth ,(cadr lang) ,list))</span> 104 <span class="a">+(eforth '((ff . find-file)) ("~/bogus/" ff))</span> 105 <span class="a">+(eforth '((d . split-window-below))</span> 106 (d)) 107 (defun 8pan () 108 (interactive) 109 <span class="d">- (eforth ((n . (lambda () (switch-to-buffer nil)))</span> 110 <span class="a">+ (eforth '((n . (lambda () (switch-to-buffer nil)))</span> 111 (d . split-window-below) 112 (r . split-window-right) 113 (wr . windmove-right)</pre> 114 </div></body></html>