Skip to content

Commit

Permalink
Added the missing functions.
Browse files Browse the repository at this point in the history
These should have been part of #80, oops.
  • Loading branch information
skx committed Nov 12, 2022
1 parent c503bef commit 8356941
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions stdlib/stdlib/stdlib.lisp
Original file line number Diff line number Diff line change
@@ -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
;;
Expand All @@ -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)
Expand Down

0 comments on commit 8356941

Please sign in to comment.