-
Notifications
You must be signed in to change notification settings - Fork 0
/
fset.lisp
64 lines (54 loc) · 2.4 KB
/
fset.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;;; Copyright (C) 2011 Alessio Stalla
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(in-package :doplus)
(defstruct (fset-iterator (:constructor %make-fset-iterator)
(:conc-name #.(string '#:%fset-iterator-)))
function index element endp)
(defun make-fset-iterator (iterator-function)
(multiple-value-bind (elt not-done)
(funcall iterator-function :get)
(%make-fset-iterator :function iterator-function :index 0
:element elt :endp (not not-done))))
(defun fset-iterator-step (seq iter from-end)
(declare (ignore seq from-end))
(multiple-value-bind (elt not-done)
(funcall (%fset-iterator-function iter) :get)
(setf (%fset-iterator-element iter) elt
(%fset-iterator-endp iter) (not not-done))
(incf (%fset-iterator-index iter)))
iter)
(defun fset-iterator-endp (seq iter limit from-end)
(declare (ignore seq limit from-end))
(%fset-iterator-endp iter))
(defun fset-iterator-element (seq iter)
(declare (ignore seq))
(%fset-iterator-element iter))
(defun fset-iterator-index (seq iter)
(declare (ignore seq))
(%fset-iterator-index iter))
(defun (setf fset-iterator-element) (new-value seq iter)
(declare (ignore new-value seq iter))
(error "FSet collections are immutable"))
(defun fset-iterator-copy (seq iter)
(declare (ignore seq iter))
(error "FSet iterators cannot be copied"))
(defmethod make-sequence-iterator ((sequence fset:seq) &key from-end start end)
(when (or from-end start end)
(error "Not implemented"))
(let ((iterator (make-fset-iterator (fset:iterator sequence))))
(values iterator nil nil ;;limit from-end
#'fset-iterator-step #'fset-iterator-endp
#'fset-iterator-element #'(setf fset-iterator-element)
#'fset-iterator-index #'fset-iterator-copy)))