Commit | Line | Data |
---|---|---|
6937c7aa BT |
1 | ;;; Guile Emacs Lisp |
2 | ||
3 | ;;; Copyright (C) 2011 Free Software Foundation, Inc. | |
4 | ||
5 | ;;; This library is free software; you can redistribute it and/or modify | |
6 | ;;; it under the terms of the GNU Lesser General Public License as | |
7 | ;;; published by the Free Software Foundation; either version 3 of the | |
8 | ;;; License, or (at your option) any later version. | |
9 | ;;; | |
10 | ;;; This library is distributed in the hope that it will be useful, but | |
11 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | ;;; Lesser General Public License for more details. | |
14 | ;;; | |
15 | ;;; You should have received a copy of the GNU Lesser General Public | |
16 | ;;; License along with this library; if not, write to the Free Software | |
17 | ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
18 | ;;; 02110-1301 USA | |
19 | ||
20 | ;;; Code: | |
9b15703d BT |
21 | |
22 | (defmacro @ (module symbol) | |
23 | `(guile-ref ,module ,symbol)) | |
24 | ||
25 | (defun funcall (function &rest arguments) | |
26 | (apply function arguments)) | |
27 | ||
28 | (defun fset (symbol definition) | |
29 | (funcall (@ (language elisp runtime subrs) fset) symbol definition)) | |
30 | ||
31 | (fset 'symbol-value (@ (language elisp runtime subrs) symbol-value)) | |
32 | (fset 'symbol-function (@ (language elisp runtime subrs) symbol-function)) | |
33 | (fset 'set (@ (language elisp runtime subrs) set)) | |
34 | (fset 'makunbound (@ (language elisp runtime subrs) makunbound)) | |
35 | (fset 'fmakunbound (@ (language elisp runtime subrs) fmakunbound)) | |
36 | (fset 'boundp (@ (language elisp runtime subrs) boundp)) | |
37 | (fset 'fboundp (@ (language elisp runtime subrs) fboundp)) | |
38 | (fset 'throw (@ (language elisp runtime subrs) throw)) | |
39 | (fset 'eval (@ (language elisp runtime subrs) eval)) | |
40 | (fset' load (@ (language elisp runtime subrs) load)) | |
41 | ||
42 | ;;; Equality predicates | |
43 | ||
44 | (fset 'eq (@ (guile) eq?)) | |
45 | (fset 'equal (@ (guile) equal?)) | |
46 | ||
47 | ;;; Numerical type predicates | |
48 | ||
49 | (defun floatp (object) | |
50 | (and (funcall (@ (guile) real?) object) | |
51 | (or (funcall (@ (guile) inexact?) object) | |
52 | (null (funcall (@ (guile) integer?) object))))) | |
53 | ||
54 | (defun integerp (object) | |
55 | (and (funcall (@ (guile) exact?) object) | |
56 | (funcall (@ (guile) integer?) object))) | |
57 | ||
58 | (defun numberp (object) | |
59 | (funcall (@ (guile) real?) object)) | |
60 | ||
61 | (defun wholenump (object) | |
62 | (and (funcall (@ (guile) exact?) object) | |
63 | (funcall (@ (guile) integer?) object) | |
64 | (>= object 0))) | |
65 | ||
66 | (defun zerop (object) | |
67 | (= object 0)) | |
68 | ||
69 | ;;; Numerical comparisons | |
70 | ||
71 | (fset '= (@ (guile) =)) | |
72 | ||
73 | (defun /= (num1 num2) | |
74 | (null (= num1 num2))) | |
75 | ||
76 | (fset '< (@ (guile) <)) | |
77 | (fset '<= (@ (guile) <=)) | |
78 | (fset '> (@ (guile) >)) | |
79 | (fset '>= (@ (guile) >=)) | |
80 | ||
81 | (defun max (&rest numbers) | |
82 | (apply (@ (guile) max) numbers)) | |
83 | ||
84 | (defun min (&rest numbers) | |
85 | (apply (@ (guile) min) numbers)) | |
86 | ||
87 | ;;; Arithmetic functions | |
88 | ||
89 | (fset '1+ (@ (guile) 1+)) | |
90 | (fset '1- (@ (guile) 1-)) | |
91 | (fset '+ (@ (guile) +)) | |
92 | (fset '- (@ (guile) -)) | |
93 | (fset '* (@ (guile) *)) | |
94 | (fset '% (@ (guile) modulo)) | |
95 | (fset 'abs (@ (guile) abs)) | |
96 | ||
97 | ;;; Floating-point rounding | |
98 | ||
99 | (fset 'ffloor (@ (guile) floor)) | |
100 | (fset 'fceiling (@ (guile) ceiling)) | |
101 | (fset 'ftruncate (@ (guile) truncate)) | |
102 | (fset 'fround (@ (guile) round)) | |
103 | ||
104 | ;;; Numeric conversion | |
105 | ||
106 | (defun float (arg) | |
107 | (if (numberp arg) | |
108 | (funcall (@ (guile) exact->inexact) arg) | |
109 | (signal 'wrong-type-argument `(numberp ,arg)))) | |
110 | ||
111 | ;;; List predicates | |
112 | ||
113 | (fset 'consp (@ (guile) pair?)) | |
114 | ||
115 | (defun null (object) | |
116 | (if object nil t)) | |
117 | ||
118 | (fset 'not #'null) | |
119 | ||
120 | (defun atom (object) | |
121 | (null (consp object))) | |
122 | ||
123 | (defun listp (object) | |
124 | (or (consp object) (null object))) | |
125 | ||
126 | (defun nlistp (object) | |
127 | (null (listp object))) | |
128 | ||
129 | ;;; Lists | |
130 | ||
131 | (fset 'cons (@ (guile) cons)) | |
132 | (fset 'list (@ (guile) list)) | |
133 | (fset 'make-list (@ (guile) make-list)) | |
134 | (fset 'append (@ (guile) append)) | |
135 | (fset 'reverse (@ (guile) reverse)) | |
136 | ||
137 | (defun car (list) | |
138 | (if (null list) | |
139 | nil | |
140 | (funcall (@ (guile) car) list))) | |
141 | ||
142 | (defun cdr (list) | |
143 | (if (null list) | |
144 | nil | |
145 | (funcall (@ (guile) cdr) list))) | |
146 | ||
147 | (defun car-safe (object) | |
148 | (if (consp object) | |
149 | (car object) | |
150 | nil)) | |
151 | ||
152 | (defun cdr-safe (object) | |
153 | (if (consp object) | |
154 | (cdr object) | |
155 | nil)) | |
156 | ||
157 | (defun setcar (cell newcar) | |
158 | (if (consp cell) | |
159 | (progn | |
160 | (funcall (@ (guile) set-car!) cell newcar) | |
161 | newcar) | |
162 | (signal 'wrong-type-argument `(consp ,cell)))) | |
163 | ||
164 | (defun setcdr (cell newcdr) | |
165 | (if (consp cell) | |
166 | (progn | |
167 | (funcall (@ (guile) set-cdr!) cell newcdr) | |
168 | newcdr) | |
169 | (signal 'wrong-type-argument `(consp ,cell)))) | |
170 | ||
171 | (defun nthcdr (n list) | |
172 | (let ((i 0)) | |
173 | (while (< i n) | |
174 | (setq list (cdr list) | |
175 | i (+ i 1))) | |
176 | list)) | |
177 | ||
178 | (defun nth (n list) | |
179 | (car (nthcdr n list))) | |
180 | ||
8f2f6566 BT |
181 | ;;; Strings |
182 | ||
183 | (defun string (&rest characters) | |
184 | (funcall (@ (guile) list->string) | |
185 | (mapcar (@ (guile) integer->char) characters))) | |
186 | ||
9b15703d BT |
187 | ;;; Sequences |
188 | ||
189 | (fset 'length (@ (guile) length)) | |
8f2f6566 BT |
190 | |
191 | (defun mapcar (function sequence) | |
192 | (funcall (@ (guile) map) function sequence)) |