Skip to content

Instantly share code, notes, and snippets.

@lagenorhynque
Last active November 8, 2019 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lagenorhynque/dc43bfc08c4835b6515a3ab484a4ed51 to your computer and use it in GitHub Desktop.
Save lagenorhynque/dc43bfc08c4835b6515a3ab484a4ed51 to your computer and use it in GitHub Desktop.
"destructive"(?) reverse in Common Lisp, Scheme and Ruby
* (defparameter xs '(1 2 3))
XS
* xs
(1 2 3)
* (nreverse xs)
(3 2 1)
* xs
(1)
irb(main):001:0> xs = [1, 2, 3]
=> [1, 2, 3]
irb(main):002:0> xs.reverse!
=> [3, 2, 1]
irb(main):003:0> xs
=> [3, 2, 1]
gosh> (define xs '(1 2 3))
xs
gosh> xs
(1 2 3)
gosh> (reverse! xs)
(3 2 1)
gosh> xs
(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment