-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfset.lisp
71 lines (66 loc) · 3.15 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
65
66
67
68
69
70
71
;;;; fset.lisp - Override some FSet generics with CL-consistent alternatives
;;;;
;;;; Copyright (C) 2020 GrammaTech, Inc.
;;;;
;;;; This code is licensed under the MIT license. See the LICENSE.txt
;;;; file in the project root for license terms.
;;;;
;;;; This project is sponsored by the Office of Naval Research, One
;;;; Liberty Center, 875 N. Randolph Street, Arlington, VA 22203 under
;;;; contract # N68335-17-C-0700. The content of the information does
;;;; not necessarily reflect the position or policy of the Government
;;;; and no official endorsement should be inferred.
(uiop/package:define-package :gt/fset
(:import-from :cl :defgeneric :defmethod :&key :&optional)
(:import-from :fset :collection)
(:import-from :alexandria)
(:shadow :last :union :intersection :set-difference)
(:export :last :lastcar :union :intersection :set-difference))
(in-package :gt/fset)
(defgeneric last (collection &optional n)
(:documentation #.(documentation 'cl:last 'function))
(:method ((collection null) &optional (n 1))
(declare (ignorable collection n)) nil)
(:method ((collection cons) &optional (n 1))
(cl:last collection n))
(:method ((collection collection) &optional (n 1)
&aux (len (fset:size collection)))
(fset:subseq collection (if (<= len n) 0 (- len n)))))
(defgeneric lastcar (collection)
(:documentation #.(documentation 'alexandria:lastcar 'function))
(:method ((collection null))
(declare (ignorable collection)) nil)
(:method ((collection cons))
(cl:car (last collection)))
(:method ((collection collection))
(fset:first (last collection))))
(defgeneric union (collection-1 collection-2 &key key test test-not)
(:documentation #.(documentation 'cl:union 'function))
(:method ((collection-1 list) (collection-2 list)
&rest args &key key test test-not)
(declare (ignorable key test test-not))
(apply #'cl:union collection-1 collection-2 args))
(:method ((collection-1 collection) (collection-2 collection)
&key key test test-not)
(declare (ignorable key test test-not))
(fset:union collection-1 collection-2)))
(defgeneric intersection (collection-1 collection-2 &key key test test-not)
(:documentation #.(documentation 'cl:intersection 'function))
(:method ((collection-1 list) (collection-2 list)
&rest args &key key test test-not)
(declare (ignorable key test test-not))
(apply #'cl:intersection collection-1 collection-2 args))
(:method ((collection-1 collection) (collection-2 collection)
&key key test test-not)
(declare (ignorable key test test-not))
(fset:intersection collection-1 collection-2)))
(defgeneric set-difference (collection-1 collection-2 &key key test test-not)
(:documentation #.(documentation 'cl:set-difference 'function))
(:method ((collection-1 list) (collection-2 list)
&rest args &key key test test-not)
(declare (ignorable key test test-not))
(apply #'cl:set-difference collection-1 collection-2 args))
(:method ((collection-1 collection) (collection-2 collection)
&key key test test-not)
(declare (ignorable key test test-not))
(fset:set-difference collection-1 collection-2)))