From e0bede31f0094f6e2b4893a9db726fa67ca84ad4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 18 Jun 2015 06:35:09 -0700 Subject: Library .txr files become .tl and are autoloaded. * lisplib.c (ver_set_entries, ver_instantiate, txr_case_set_entries, txr_case_instantiate): New static functions. (lisplib_init): Register new functions. * share/txr/stdlib/txr-case.txr: Reduced to a load for the corresponding .tl file, retained for backward compatibility. * share/txr/stdlib/ver.txr: Likewise. * share/txr/stdlib/txr-case.tl: New file, based on previous contents of corresponding .txr file. * share/txr/stdlib/ver.tl: Likewise. --- share/txr/stdlib/txr-case.tl | 41 +++++++++++++++++++++++++++++++++++++++++ share/txr/stdlib/txr-case.txr | 43 +------------------------------------------ share/txr/stdlib/ver.tl | 1 + share/txr/stdlib/ver.txr | 2 +- 4 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 share/txr/stdlib/txr-case.tl create mode 100644 share/txr/stdlib/ver.tl (limited to 'share') diff --git a/share/txr/stdlib/txr-case.tl b/share/txr/stdlib/txr-case.tl new file mode 100644 index 00000000..2e0c5979 --- /dev/null +++ b/share/txr/stdlib/txr-case.tl @@ -0,0 +1,41 @@ +(defmacro txr-if (name args input : then else) + (let ((syms (keep-if [andf true symbolp [notf keywordp] [notf (op eq t)]] + args)) + (arg-exprs [mapcar [iffi symbolp (ret ^',@1)] args]) + (result (gensym "res-")) + (bindings (gensym "bindings-")) + (insym (gensym "input-"))) + ^(let* ((,insym ,input) + (,result (match-fun ',name (list ,*arg-exprs) + (if (stringp ,insym) (list ,insym) ,insym) + nil))) + (if ,result + (let ((,bindings (car ,result))) + (let (,*[mapcar (ret ^(,@1 (cdr (assoc ',@1 ,bindings)))) + syms]) + ,then)) + ,else)))) + +(defmacro txr-when (name args input . body) + ^(txr-if ,name ,args ,input (progn ,*body))) + +(defmacro txr-case-impl (sym . clauses) + (tree-case clauses + (((name args . body) . other-clauses) + (if (eq name t) : + ^(txr-if ,name ,args ,sym + (progn ,*body) + (txr-case-impl ,sym ,*other-clauses)))) + (((sym . rest) . other-clauses) + (if (eq sym t) + (if other-clauses + (error "txr-case: clauses after (t ...) clause ignored") + ^(progn ,*rest)) + (error "txr-case: bad syntax: ~s" (car clauses)))) + (atom + (error "txr-case: unexpected atom in syntax: ~s" atom)))) + +(defmacro txr-case (input-expr . clauses) + (let ((input (gensym "input-"))) + ^(let ((,input ,input-expr)) + (txr-case-impl ,input ,*clauses)))) diff --git a/share/txr/stdlib/txr-case.txr b/share/txr/stdlib/txr-case.txr index 12321a31..9b65d1bc 100644 --- a/share/txr/stdlib/txr-case.txr +++ b/share/txr/stdlib/txr-case.txr @@ -1,42 +1 @@ -@(do - (defmacro txr-if (name args input : then else) - (let ((syms (keep-if [andf true symbolp [notf keywordp] [notf (op eq t)]] - args)) - (arg-exprs [mapcar [iffi symbolp (ret ^',@1)] args]) - (result (gensym "res-")) - (bindings (gensym "bindings-")) - (insym (gensym "input-"))) - ^(let* ((,insym ,input) - (,result (match-fun ',name (list ,*arg-exprs) - (if (stringp ,insym) (list ,insym) ,insym) - nil))) - (if ,result - (let ((,bindings (car ,result))) - (let (,*[mapcar (ret ^(,@1 (cdr (assoc ',@1 ,bindings)))) - syms]) - ,then)) - ,else)))) - - (defmacro txr-when (name args input . body) - ^(txr-if ,name ,args ,input (progn ,*body))) - - (defmacro txr-case-impl (sym . clauses) - (tree-case clauses - (((name args . body) . other-clauses) - (if (eq name t) : - ^(txr-if ,name ,args ,sym - (progn ,*body) - (txr-case-impl ,sym ,*other-clauses)))) - (((sym . rest) . other-clauses) - (if (eq sym t) - (if other-clauses - (error "txr-case: clauses after (t ...) clause ignored") - ^(progn ,*rest)) - (error "txr-case: bad syntax: ~s" (car clauses)))) - (atom - (error "txr-case: unexpected atom in syntax: ~s" atom)))) - - (defmacro txr-case (input-expr . clauses) - (let ((input (gensym "input-"))) - ^(let ((,input ,input-expr)) - (txr-case-impl ,input ,*clauses))))) +@(load "txr-case.tl") diff --git a/share/txr/stdlib/ver.tl b/share/txr/stdlib/ver.tl new file mode 100644 index 00000000..85221ca0 --- /dev/null +++ b/share/txr/stdlib/ver.tl @@ -0,0 +1 @@ +(defvar *lib-version* 108) diff --git a/share/txr/stdlib/ver.txr b/share/txr/stdlib/ver.txr index 18a987e7..2339bda7 100644 --- a/share/txr/stdlib/ver.txr +++ b/share/txr/stdlib/ver.txr @@ -1 +1 @@ -@(do (defvar *lib-version* 108)) +@(load "ver.tl") -- cgit v1.2.3