forthe.el (1557 bytes)
1 ;;; forthe.el --- FORTH in elisp. -*- lexical-binding: t; -*- 2 ;; Copyright (C) 2019 Spenser Truex 3 ;; Author: Spenser Truex <web@spensertruex.com> 4 ;; Created: 2019-06-22 5 ;; Version: 0.0.2 6 ;; Package-Requires: ((emacs "24")) 7 ;; Keywords: convenience abbrev tools extensions 8 ;; URL: https://spensertruex.com/forthe 9 ;; Homepage: 10 ;; This file is not part of GNU Emacs. 11 ;; This file is free software. 12 ;; License: 13 ;; Licensed with the GNU GPL v3 see: 14 ;; <https://www.gnu.org/licenses/>. 15 ;;; Commentary: 16 ;; Version 0.0.1 17 ;; 18 ;; Docs available as: HTML | ORG-mode 19 ;; 20 ;; Code on github 21 ;; 22 ;; This is an implementation of an elisp-based FORTH. This means that elisp 23 ;; is used to write the function definitions. In fact, no FORTH function 24 ;; definitions are provided at all to the Forthe macro from the library. 25 ;; The main benefit comes from reducing the verbosity of elisp in a small 26 ;; Domain Specific Language the programmer defines. 27 28 ;;; Code: 29 30 (defun forthe--inner (lang list) 31 "Internal function for the `forthe' macro. 32 LANG are the bindings for the forth. 33 LIST is full of the Forthe stack (RPN)." 34 (let (s) 35 (dolist (i list) 36 (if (assoc i lang) 37 (let ((fn (cadr (assoc i lang)))) 38 (if s 39 (progn (apply fn s) (setf s nil)) 40 (funcall fn))) 41 (push i s))))) 42 43 (defmacro forthe (lang list) 44 "Define and execute a FORTH language (called Forthe). 45 LANG are the let-bindings for the FORTH's operators. 46 LIST is the forth's stack." 47 `(forthe--inner ,lang ',list)) 48 49 (provide 'forthe) 50 ;; forthe.el ends here