-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinput.lisp
126 lines (77 loc) · 2.64 KB
/
input.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
(in-package :maxpc.input)
;;; Input interface
(defgeneric make-input (input-source)
(:documentation
"*Arguments and Values:*
_input-source_—an _object_.
*Description:*
{make-input} returns an _input_ for _input-source_."))
(defgeneric input-empty-p (input)
(:documentation
"→ _empty-p_
*Arguments and Values:*
_input_—an _input_.
_empty-p_—a _generalized boolean_.
*Description:*
{input-empty-p} returns _true_ if _input_ is empty."))
(defgeneric input-first (input)
(:documentation
"→ _element_
*Arguments and Values:*
_input_—a non-empty _input_.
_element_—an _object_ of the _type_ designated by the _type specifier_
returned by {input-element-type} when called on _input_.
*Description:*
{input-first} returns the first element in _input_.
*Exceptional Situations:*
If _input_ is empty the behavior of {input-first} is unspecified."))
(defgeneric input-rest (input)
(:documentation
"→ _rest_
*Arguments and Values:*
_input_—a non-empty _input_.
_rest_—the remaining _input_.
*Description:*
{input-rest} returns the remaining _input_ without the first element.
*Exceptional Situations:*
If _input_ is empty the behavior of {input-rest} is unspecified."))
(defgeneric input-position (input)
(:documentation
"→ _position_
*Arguments and Values:*
_input_—an _input_.
_position_—an _integer_ between 0 and {array-dimension-limit} inclusively.
*Description:*
{input-position} returns the _position_ of _input_.")
(:method ((input t))
(declare (ignore input))
0))
(defgeneric input-element-type (input)
(:documentation
"→ _typespec_
*Arguments and Values:*
_input_—an _input_.
_typespec_—a _type specifier_.
*Description:*
{input-element-type} returns a _type specifier_ that designates the _type_
of the elements in _input_.")
(:method ((input t))
(declare (ignore input))
t))
(defgeneric input-sequence (input length)
(:documentation
"→ _sequence_
*Arguments and Values:*
_input_—an _input_.
_length_—an _integer_ between 0 and {array-dimension-limit} inclusively.
_sequence_—a _sequence_.
*Description:*
{input-sequence} returns a _sequence_ of the next _length_ elements in
_input_.
*Exceptional Situations:*
If the number of elements in _input_ are less than _length_ the behavior of
{input-sequence} is unspecified.")
(:method ((input t) (length integer))
(loop for i from 1 to length
for rest = input then (input-rest rest)
collect (input-first rest))))