summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-03-05 00:33:46 +0000
committerKarl Berry <karl@freefriends.org>2013-03-05 00:33:46 +0000
commitd472c7d8c47d5a08e34a9f4713164afc5e7a1406 (patch)
tree4249b1eff690be906945d15b1e39e33037b1abdc /Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty
parent0d0778a39975e8293bde2267504f53bd9d3610a6 (diff)
lisp-on-tex (4mar13)
git-svn-id: svn://tug.org/texlive/trunk@29291 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty')
-rw-r--r--Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty56
1 files changed, 56 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty
new file mode 100644
index 00000000000..da4244b9f6b
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/lisp-on-tex/lisp-util.sty
@@ -0,0 +1,56 @@
+%%================================
+%% Definition of Utility Functions
+%%================================
+\makeatletter
+\lispinterp{%
+(\define \listQ (\lambda (\x) (\or (\pairQ \x) (\= () \x))))
+(\define \procedureQ (\lambda (\x)
+ (\or (\funcQ \x) (\closureQ \x) (\envfuncQ \x) (\macroQ \x))))
+(\define \atomQ (\lambda (\x)
+ (\and (\not (\pairQ \x)) (\not (\= () \x)) )))
+(\define \map (\lambda (\f.\args)
+ (\lispif (\= () (\car \args)) ()
+ (\let ((\cars (\@inner@map \car \args)) (\cdrs (\@inner@map \cdr \args)))
+ (\cons (\apply \f \cars)
+ (\apply \map (\cons \f \cdrs))
+ )
+ )
+ )
+ )
+)
+%% @inner@map : ('a -> 'b) -> 'a list -> 'b list
+(\define \@inner@map
+ (\lambda (\f \l)
+ (\lispif (\= () \l) () (\cons (\f (\car \l)) (\@inner@map \f (\cdr \l))))))
+%% not : bool -> bool
+(\define \not (\lambda (\b) (\lispif \b /f /t)))
+%% and : bool... -> bool
+(\define \and
+ (\lambda \l
+ (\lispif (\= () \l)
+ /t
+ (\lispif (\car \l) (\apply \and (\cdr \l)) /f))))
+%% or bool... -> bool
+(\define \or
+ (\lambda \l
+ (\lispif (\= () \l)
+ /f
+ (\lispif (\car \l) /t (\apply \and (\cdr \l))))))
+%% list
+(\define \list (\lambda \x \x))
+%% let bindings
+(\defmacro \let
+ (\lambda (\binds \body)
+ (\lispif (\= \binds ())
+ \body
+ (\list \let (\cdr \binds) (\list \@let (\car (\car \binds)) (\car (\cdr (\car \binds))) \body)))))
+(\defmacro \letM
+ (\lambda (\binds \body)
+ (\lispif (\= \binds ())
+ \body
+ (\list \let (\cdr \binds) (\list \@mlet (\car (\car \binds)) (\car (\cdr (\car \binds))) \body)))))
+% nth
+(\define \nth (\lambda (\lst \n)
+ (\lispif (\= \n :0) (\car \lst) (\nth (\cdr \lst) (\- \n :1)))))
+}
+\makeatother \ No newline at end of file