Last active
November 8, 2019 03:52
-
-
Save lagenorhynque/dc43bfc08c4835b6515a3ab484a4ed51 to your computer and use it in GitHub Desktop.
"destructive"(?) reverse in Common Lisp, Scheme and Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* (defparameter xs '(1 2 3)) | |
XS | |
* xs | |
(1 2 3) | |
* (nreverse xs) | |
(3 2 1) | |
* xs | |
(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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