From 8356941a03abc9d4a40ebcbc43d0caa0f053d680 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sat, 12 Nov 2022 12:09:00 +0200 Subject: [PATCH] Added the missing functions. These should have been part of #80, oops. --- stdlib/stdlib/stdlib.lisp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/stdlib/stdlib/stdlib.lisp b/stdlib/stdlib/stdlib.lisp index 817a7aa..57477cf 100644 --- a/stdlib/stdlib/stdlib.lisp +++ b/stdlib/stdlib/stdlib.lisp @@ -1,13 +1,21 @@ ;;; stdlib.lisp - Standard library as implemented in lisp. +;; Convert a number to a binary string. +(set! dec2bin (fn* (n:number) + "Convert the given number to a binary string representation of that number." + (base n 2))) +;; Convert a number to a hexadecimal string. +(set! dec2hex (fn* (n:number) + "Convert the given number to a hexadecimal string representation." + (base n 16))) ;; Useful for creating a list of numbers (set! repeated (fn* (n:number x) "Return a list of length n whose elements are all x." - (when (pos? n) - (cons x (repeated (dec n) x))))) + (when (pos? n) + (cons x (repeated (dec n) x))))) ;; Return the last element of a list ;; @@ -16,7 +24,7 @@ ;; (set! last (fn* (lst:list) "Return the last element of the given list" (car (reverse lst)))) ;; (set! last (fn* (lst:list) - "last returns the last item in the specified list, it is the inverse of (butlast) and the logical opposite of (car)." + "Return the last item in the specified list, it is the inverse of (butlast) and the logical opposite of (car)." (let* (c (cdr lst)) (if (! (nil? c)) (last c)