-
Notifications
You must be signed in to change notification settings - Fork 3
/
manipulators.lisp
43 lines (34 loc) · 1.05 KB
/
manipulators.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
(cl:in-package :objc.manipulators)
(named-readtables:in-readtable :objc-readtable)
(serapeum:eval-always
(let (*it*)
(declare (special *it*))
(defgeneric sel (type sel)
(:method :around (type sel)
(lambda (*it*)
(declare (special *it*))
(call-next-method)))
(:method (type sel)
[*it* sel])
(:method ((type (eql :int)) sel)
[*it* sel]#)
(:method ((type (eql :string)) sel)
[*it* sel]s)
(:method ((type (eql :nsstring)) sel)
[*it* sel]@))))
(defun-ct ext ()
(lambda (it)
(objc-runtime.data-extractors:extract-from-objc it)))
(defun-ct <> (&rest funs)
(apply #'alexandria:compose funs))
(defun-ct <count (f)
(lambda (c &rest v)
(list* c (apply f v))))
(defun-ct add-index (hof f)
(lambda (&rest hof-args)
(let ((count 0))
(declare (dynamic-extent count))
(flet ((nested-lambda (&rest args)
(prog1 (apply f count args)
(incf count))))
(apply hof #'nested-lambda hof-args)))))