-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshiftless-types.el
More file actions
85 lines (64 loc) · 2.18 KB
/
shiftless-types.el
File metadata and controls
85 lines (64 loc) · 2.18 KB
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
(require 'cl-lib)
(require 'dash)
(defun shiftless::atom-predicate (obj)
(or (symbolp obj)
(numberp obj)
(stringp obj)))
;;; symbol
(cl-defmethod shiftless::atom-string ((atom symbol))
(symbol-name atom))
(cl-defmethod shiftless::atom-symbol ((atom symbol))
atom)
(cl-defmethod shiftless::value ((atom symbol))
atom)
(cl-defmethod shiftless::atom-boolean ((atom symbol))
atom)
(cl-defmethod shiftless::atom-integer ((atom symbol))
(error "symbol cannot be converted to integer"))
(cl-defmethod shiftless::atom-float ((atom symbol))
(error "symbol cannot be converted to float"))
;;; number
(cl-defmethod shiftless::atom-symbol ((atom number))
(error "number cannot be converted to symbol"))
(cl-defmethod shiftless::value ((atom number))
atom)
(cl-defmethod shiftless::atom-boolean ((atom number))
(declare (ignore atom))
t)
(cl-defmethod shiftless::atom-integer ((atom number))
(round atom))
(cl-defmethod shiftless::atom-float ((atom number))
(float atom))
(cl-defmethod shiftless::atom-string ((atom number))
(prin1-to-string atom))
;;; string
(defun shiftless::stringp (string)
(and (stringp string)
(< 0 (length string))
(= ?' (elt string 0))))
(cl-defmethod shiftless::value ((atom string))
(if (shiftless::stringp atom)
(shiftless::make-atom atom)
atom))
(cl-defmethod shiftless::atom-symbol ((atom string))
(if (shiftless::stringp atom)
(shiftless::atom-symbol (shiftless::make-atom atom))
(intern (downcase atom))))
(cl-defmethod shiftless::atom-boolean ((atom string))
(if (shiftless::stringp atom)
t
(shiftless::atom-boolean (shiftless::make-atom atom))))
(cl-defmethod shiftless::atom-integer ((atom string))
(if (shiftless::stringp atom)
(shiftless::atom-integer (shiftless::make-atom atom))
(round (string-to-number atom))))
(cl-defmethod shiftless::atom-float ((atom string))
(if (shiftless::stringp atom)
(shiftless::atom-float (shiftless::make-atom atom))
(float (string-to-number atom))))
(cl-defmethod shiftless::atom-string ((atom string))
(if (shiftless::stringp atom)
(shiftless::make-atom atom)
atom))
(provide 'shiftless-types)
;;; shiftless-types.el ends here