README.org (3989 bytes)
1 #+TITLE: SL: A Package Dependency Language 2 #+AUTHOR: Spenser Truex 3 #+EMAIL: web@spensertruex.com 4 5 [[https://github.com/equwal/sl][Github]] | [[https://spensertruex.com/sl--dependency-language][Homepage]] 6 7 8 SL is a Domain Specific Language (ie. simple programming language) for dealing 9 with ambiguous dependency situations. It is more expressive than the standard 10 method in Common Lisp: the use of reader macros. It provides symbol aliasing 11 based on compile-time rules. 12 13 * Benefits 14 - Symbol aliasing at compile time provides a means of abstracting separate but similar interfaces. Forked projects, or projects that duplicate work. 15 - Far more expressive and concise than reader macros, while still very simple. 16 - There is also the use case of renaming things for import, like =with-gensyms= to =with-unique-names= or similar. 17 * Drawbacks 18 All the drawbacks of a new, experimental program apply. 19 * Examples 20 The only external macro is =defsl=. There is BNF below, though some examples are in order. 21 ** Simple 22 This defines =operator-arglist= (in the current package) as 23 =slynk:operator-arglist=, unless =slynk= is unavailable, in which case 24 =swank:operator-arglist= is used. 25 #+BEGIN_SRC lisp 26 (defsl operator-arglist :fn :eq slynk swank) 27 #+END_SRC 28 The =:fn= shows that a FUNCTION is being defined, as opposed to a =:sym= symbol; 29 to define another namespace a list is required: =(accessor-fn boundp-fn)=. =:eq= 30 denotes that the packages have the same name for this function. 31 For this simplest of examples, consider the reader macro alternative. 32 #+BEGIN_SRC lisp 33 #+(and slynk swank) (setf (symbol-function 'operator-arglist) 34 slynk:operator-arglist) 35 #+(and slynk (not swank)) (setf (symbol-function 'operator-arglist) 36 slynk:operator-arglist) 37 #+(and (not slynk) swank) (setf (symbol-function 'operator-arglist) 38 swank:operator-arglist) 39 #+END_SRC 40 ** Complex example 41 #+BEGIN_SRC lisp 42 (defsl gensymmer (macro-function macro-function) 43 utils with-unique-names 44 alexandria with-gensyms) 45 #+END_SRC 46 To break this down: 47 - =gensymmer= is now defined as =utils:with-unique-names=. 48 - =macro-function= was used twice: once as a =setfable= place, and once as a 49 predicate. 50 - If the =utils= package does not exist, then =sl::gensymmer= is defined as 51 =alexanrdia:with-gensyms=. 52 - to define different names for each package, they must be "qualified" with the 53 package name. 54 55 * Rationale and Purpose 56 I made this since =asdf= was not enough abstraction for what I needed: to 57 arbitrarily choose dependencies and renames for any symbol. I could write what I 58 am doing twice, or I could write the compiler for =SL= (ie. the first two 59 letters of SLy and SLime). Once I have that, I can bend that fork until I have a 60 coherent set of names for all the functions I need, and which work on both (in 61 principle). You could just intern the symbols (like with #+ reader syntax) but 62 those tend to explode exponentially; since SL is 100% compile-time, it is 63 similar (but more expressive). 64 65 * Install 66 Use ASDF to install. Usually this should work: 67 #+BEGIN_SRC sh 68 $ cd ~/common-lisp/ 69 $ git clone git@github.com:equwal/sl.git 70 CL-USER> (asdf:load-system :sl) 71 #+END_SRC 72 73 * BNF 74 [[https://spensertruex.com/sl--dependency-language][See with syntax highlighting on the webpage]]. 75 #+BEGIN_SRC bnf 76 (defsl <sl-name> <fnsym> <package spec>) 77 <package spec> ::= <eq> 78 | <packages> 79 <eq> ::= :eq <preferences> 80 <fnsym> ::= :fn 81 | :sym 82 | <fnpair> 83 84 <fnpair> ::= (setfable-place bound-predicate) 85 <packages> ::= <package> <fn name> <more packages> 86 <package> ::= symbol 87 <fn name> ::= symbol 88 <preferences> ::= <package> <more packages> 89 <more packages> ::= ε 90 | <package> 91 | <package> <more packages> 92 #+END_SRC 93 * Issues: 94 - This is a new thing. 95 - =defsl= is quite possibly the world's most unhygenic macro: don't expect 96 anything about evaluation order or number of evaluations to be true.