Skip to content

Instantly share code, notes, and snippets.

View abishek's full-sized avatar

Abishek Goda abishek

View GitHub Profile
@abishek
abishek / split-sentence-to-words.lisp
Created August 8, 2020 12:45
A simple defun to split a space separated string into individual word strings. "one two three" into ("one" "two" "three") so to say.
(defun split-sentence-to-words (sentence)
(let ((word '()))
(loop for ch across sentence
if (member ch '(#\space #\tab #\,))
collect (coerce (reverse word) 'string) into words and do (setf word '())
else
do (push ch word)
finally (return (append words (coerce (reverse word) 'string))))))
@abishek
abishek / read-dot-env.lisp
Created January 19, 2020 12:56
A quick piece of code to read .env files. A line beginning with a # is treated as a comment. When this grows, I plan to make a separate project and push into quicklisp.
(defun load-env (pathname)
(with-open-file (stream pathname)
(read-env stream)))
(defun read-env (stream)
(remove-nils
(loop for line = (read-line stream nil :eof)
until (eq line :eof)
collect (process-env-string line))))
@abishek
abishek / number-to-digit-list.lisp
Last active January 9, 2019 14:42
A lisp function to convert a given number into a list of digits and to convert it back to a number
(defun number-to-digit-list (number)
(if (> number 9)
(append (number-to-digit-list (truncate (/ number 10))) (cons (mod number 10) '()))
(list number)))
(defun digit-list-to-number (digit-list)
(reduce #'+ (loop for pos from 0
and digit in (reverse digit-list)
collect (* digit (expt 10 pos)))))