Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added ftab, fset and fvec iterators and optional ITERATE drivers
- Loading branch information
Showing
14 changed files
with
389 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(in-package :cl-user) | ||
|
||
(asdf:defsystem :x.fdatatypes-iterate | ||
:depends-on (:x.let-star :x.fdatatypes :iterate) | ||
:serial t | ||
:components ((:module "x.fdatatypes-iterate" | ||
:components ((:file "package") | ||
(:file "iterate"))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
(in-package :x.fdatatypes-iterate) | ||
|
||
(defmacro-driver (for key/val :in-fdatatype container) | ||
(destructuring-bind (key val) key/val | ||
(let ((kwd (if generate 'generate 'for)) | ||
(iterator (gensym)) | ||
(result-template (gensym)) | ||
(tmp-key (gensym)) | ||
(tmp-val (gensym)) | ||
(validp (gensym))) | ||
`(progn | ||
(with ,iterator = (iterator ,container)) | ||
(while ,iterator) | ||
(with ,result-template = (list nil nil)) | ||
(with ,tmp-key) | ||
(with ,tmp-val) | ||
(with ,validp) | ||
(,kwd (,key ,val) next | ||
(progn | ||
(multiple-value-setq (,iterator ,tmp-key ,tmp-val ,validp) | ||
(iterator-next ,iterator)) | ||
(unless ,validp (terminate)) | ||
(setf (first ,result-template) ,tmp-key | ||
(second ,result-template) ,tmp-val) | ||
,result-template)))))) | ||
|
||
(defmacro-driver (for key :in-fdatatype-keys container) | ||
(let ((kwd (if generate 'generate 'for))) | ||
`(progn | ||
(,kwd (,key _) :in-fdatatype ,container)))) | ||
|
||
(defmacro-driver (for val :in-fdatatype-vals container) | ||
(let ((kwd (if generate 'generate 'for))) | ||
`(progn | ||
(,kwd (_ ,val) :in-fdatatype ,container)))) | ||
|
||
(defmacro-driver (for val :in-fvec fvec) | ||
(let ((kwd (if generate 'generate 'for))) | ||
`(progn | ||
(,kwd ,val :in-fdatatype-vals (the fvec ,fvec))))) | ||
|
||
(defmacro-driver (for key :in-fset fset) | ||
(let ((kwd (if generate 'generate 'for))) | ||
`(progn | ||
(,kwd ,key :in-fdatatype-keys (the fset ,fset))))) | ||
|
||
(defmacro-driver (for key/val :in-ftab ftab) | ||
(let ((kwd (if generate 'generate 'for))) | ||
`(progn | ||
(,kwd ,key/val :in-fdatatype (the ftab ,ftab))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(in-package :x.fdatatypes) | ||
|
||
(defpackage :x.fdatatypes-iterate | ||
(:use :cl :iterate :x.fdatatypes)) | ||
|
||
;; This package does not export anything in itself, | ||
;; it uses x.fdatatypes:iterator and x.fdatatypes:iterator-next | ||
;; function to create iterate drivers. | ||
;; | ||
;; These iterate drivers also support iterate generators, when the key, value or both | ||
;; are updated on demand with (next key) ;; or (next val) | ||
;; in iterate loop. | ||
;; | ||
;; Wildcards '_' can be used instead of key or val when they are not needed | ||
;; | ||
;; Iterate's drivers are recognized by keywords, and x.fdatatype's iterate | ||
;; drivers are: | ||
;; | ||
;; ------------------------ | ||
;; :IN-FDATATYPE | ||
;; ex: (iter (for (key val) :in-fdatatype ftab/fset/fvec) ;; or instead 'for' - 'generate' | ||
;; | ||
;; ------------------------ | ||
;; :IN-FDATATYPE-KEYS | ||
;; ex: (iter (for key :in-fdatatype-keys ftab/fset/fvec) ;; or instead 'for' - 'generate' | ||
;; | ||
;; for fvec, it's key is it's index | ||
;; | ||
;; ------------------------ | ||
;; :IN-FDATATYPE-VALS | ||
;; ex: (iter (for val :in-fdatatype-vals ftab/fset/fvec) ;; or instead 'for' - 'generate' | ||
;; | ||
;; for fset, it's value it always T | ||
;; | ||
;; ------------------------ | ||
;; :IN-FVEC | ||
;; ex: (iter (for val :in-fvec fvec) ;; or instead 'for' - 'generate' | ||
;; | ||
;; ------------------------ | ||
;; :IN-FSET | ||
;; ex: (iter (for key :in-fset fset) ;; or instead 'for' - 'generate' | ||
;; | ||
;; ------------------------ | ||
;; :IN-FTAB | ||
;; ex: (iter (for (key val) :in-ftab ftab) ;; or instead 'for' - 'generate' | ||
;; | ||
;; | ||
;; Drivers :IN-FVEC, :IN-FSET and :IN-FTAB accepts only fvec, respectively fset and ftab, | ||
;; or fail otherwise. | ||
;; | ||
;; With :IN-FDATATYPE, :IN-FDATATYPE-KEYS and :IN-FDATATYPE-VALS any x.fdatatype can be used. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
(in-package :x.fdatatypes) | ||
|
||
(eval-when (:compile-toplevel :load-toplevel :execute) | ||
(defun %reevaluate-constant (name value test) | ||
(if (not (boundp name)) | ||
value | ||
(let ((old (symbol-value name)) | ||
(new value)) | ||
(if (not (constantp name)) | ||
(prog1 new | ||
(cerror "Try to redefine the variable as a constant." | ||
"~@<~S is an already bound non-constant variable ~ | ||
whose value is ~S.~:@>" name old)) | ||
(if (funcall test old new) | ||
old | ||
(restart-case | ||
(error "~@<~S is an already defined constant whose value ~ | ||
~S is not equal to the provided initial value ~S ~ | ||
under ~S.~:@>" name old new test) | ||
(ignore () | ||
:report "Retain the current value." | ||
old) | ||
(continue () | ||
:report "Try to redefine the constant." | ||
new)))))))) | ||
|
||
(defmacro define-constant (name initial-value &key (test ''eql) documentation) | ||
`(defconstant ,name (%reevaluate-constant ',name ,initial-value ,test) | ||
,@(when documentation `(,documentation)))) | ||
|
||
(defmacro nconcing ((&key (init nil) | ||
(into 'nconc-result) | ||
(call 'nconc-it) | ||
(count nil) | ||
(last nil) | ||
(before-last nil)) | ||
&body body) | ||
(let ((head-sym (gensym "HEAD")) | ||
(tail-sym (gensym "TAIL"))) | ||
`(let* ((,head-sym (cons nil ,init)) | ||
(,tail-sym (last ,head-sym)) | ||
(,into (cdr ,head-sym)) | ||
,@(when count `((,count (length ,init)))) | ||
,@(when last `((,last nil))) | ||
,@(when before-last `((,before-last (last ,init 2))))) | ||
(flet ((,call (x) | ||
,@(when before-last | ||
`((setf ,before-last | ||
(unless (eq ,head-sym ,tail-sym) | ||
,tail-sym)))) | ||
(rplacd ,tail-sym (setf ,tail-sym (list x))) | ||
(setf ,into (cdr ,head-sym)) | ||
,@(when last `((setf ,last ,tail-sym))) | ||
,@(when count `((incf ,count))))) | ||
,@body)))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.