-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsequence.lisp
69 lines (46 loc) · 2.01 KB
/
sequence.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
;;;; sequence.lisp - extensible sequences functionality.
;;; May not be supported on all Lisp implementations, but should be enabled automatically when cl-patterns is loaded on an implementation with support.
;;; https://github.com/guicho271828/common-lisp-extensions/issues/8
;;; http://www.sbcl.org/manual/#Extensible-Sequences
(in-package #:cl-patterns)
;;; scale
(defmethod sequence:length ((this scale))
(length (scale-notes this)))
(defmethod sequence:elt ((this scale) index)
(elt (scale-notes this) index))
(defmethod sequence:emptyp ((this scale))
nil)
;;; tuning
(defmethod sequence:length ((this tuning))
(length (tuning-pitches this)))
(defmethod sequence:elt ((this tuning) index)
(elt (tuning-pitches this) index))
(defmethod sequence:emptyp ((this tuning))
nil)
;;; chord
(defmethod sequence:length ((this chord))
(length (chord-indexes this)))
(defmethod sequence:elt ((this chord) index)
(elt (chord-indexes this) index))
(defmethod sequence:emptyp ((this chord))
nil)
;;; pstream
(defmethod sequence:length ((this pstream))
(slot-value this 'number)) ; FIX: this should use the history-length pstream slot instead once it is implemented
(defmethod sequence:elt ((this pstream) index)
(pstream-elt this index))
(defmethod (setf sequence:elt) (new-value (this pstream) index)
(sequence:protocol-unimplemented 'sequence:elt this))
(defmethod sequence:adjust-sequence ((this pstream) length &key initial-element initial-contents)
(declare (ignore initial-element initial-contents))
(sequence:protocol-unimplemented 'sequence:adjust-sequence this)) ; FIX?
(defmethod sequence:make-sequence-like ((this pstream) length &key initial-element initial-contents)
(declare (ignore initial-element initial-contents))
(sequence:protocol-unimplemented 'sequence:make-sequence-like this)) ; FIX?
(defmethod sequence:emptyp ((this pstream))
(and (ended-p this)
(null (elt this 0))))
;; FIX: add more (see URL above)
;;; eseq
(defmethod sequence:length ((eseq eseq))
(length (eseq-events eseq)))