summary refs log tree commit diff stats
path: root/cl-math.lisp
diff options
context:
space:
mode:
authorDaniel Santos <dacs.git@brilhante.top>2023-01-10 17:31:05 +0000
committerDaniel Santos <dacs.git@brilhante.top>2023-01-10 17:45:16 +0000
commit91fcf477721c1571f20b25de633e5cf8314bd81e (patch)
tree704c7c4288dbd1da526f2120bf8b00982ade3ac8 /cl-math.lisp
parent8be733f5ae19d06c0972b30925f16f0ca2687d77 (diff)
downloadcl-math-91fcf477721c1571f20b25de633e5cf8314bd81e.tar.gz
add implode, explode and may-reverse
Add the functions implode, explode, may-reverse and
the variable *number-units-beginning*
Diffstat (limited to 'cl-math.lisp')
-rw-r--r--cl-math.lisp16
1 files changed, 16 insertions, 0 deletions
diff --git a/cl-math.lisp b/cl-math.lisp
index a217df4..86c7a81 100644
--- a/cl-math.lisp
+++ b/cl-math.lisp
@@ -1,6 +1,8 @@
 ;;; plus one function
 ;;; it is the (next-number) and the (next-number-reversed)
 
+(defvar *number-units-beginning* nil)
+
 (defun next-digit (numerals digit)
   "Given a list of a numeral system and a digit, it returns the next digit."
   (cond
@@ -14,6 +16,20 @@
     ((zerop number) nil)
     (t (cons (mod number 10) (split-number-reversed (truncate number 10))))))
 
+(defun may-reverse (number)
+  "If units is placed on the end, reverse; else keep it."
+  (if *number-units-beginning*
+	(reverse number)
+	number))
+
+(defun explode (number)
+  "Given a number (which can have letters), it returns a list of the number"
+  (may-reverse (loop for letter across (write-to-string number) collect (intern (string letter)))))
+
+(defun implode (number)
+  "Given a list of a number (which can have letters), it returns the number"
+  (intern (apply #'concatenate 'string (mapcar #'symbol-name (may-reverse number)))))
+
 (defun next-list-number (numerals number-list-reversed)
   "Given a list of a numeral system and a list of a number, it returns a list of the next number."
   (cond
'n169' href='#n169'>169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342