Skip to content

Instantly share code, notes, and snippets.

@Jach
Last active November 8, 2017 19:22
Show Gist options
  • Select an option

  • Save Jach/b92d70d01ac55a07f357c41bf5c01d24 to your computer and use it in GitHub Desktop.

Select an option

Save Jach/b92d70d01ac55a07f357c41bf5c01d24 to your computer and use it in GitHub Desktop.
How to write Lisp like C...
(defun reverse-string-c (string string-length)
(prog ((pos 0) (half (truncate (/ string-length 2))))
START (if (= pos half)
(return string))
(let ((swap-pos (- string-length pos 1)))
(rotatef (schar string pos) (schar string swap-pos)))
(incf pos)
(go START)))
(defun reverse-string (string)
(reverse-string-c string (length string)))
(reverse-string "hello")
@Jach
Copy link
Copy Markdown
Author

Jach commented Nov 8, 2017

Second revision more lispy, handles 0- and 1-length strings, but still using a goto instead of a loop :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment