Created
May 11, 2018 17:42
-
-
Save westerp/befe5bb8c0649ff3a88ecc6cbec4663f to your computer and use it in GitHub Desktop.
Suggested solution to: Create a function which gets a list as parameter and creates a list in which only the original list's atoms exist in reversed order. example : list: (a (b c) d e)) output: (e d a)
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
(defun reverse-filter-atoms (l) | |
(funcall | |
((lambda (f) | |
((lambda (g) (funcall g g)) | |
(lambda (g) | |
(funcall f (lambda (&rest args) (apply (funcall g g) args)))))) | |
(lambda (fa) | |
(lambda (l k) | |
(if (endp l) | |
(funcall k l) | |
(funcall fa | |
(cdr l) | |
(lambda (r) | |
(funcall k | |
(if (atom (car l)) | |
(cons (car l) r) | |
r)))))))) | |
l | |
(lambda (l) | |
(funcall | |
((lambda (f) | |
((lambda (g) (funcall g g)) | |
(lambda (g) | |
(funcall f (lambda (&rest args) (apply (funcall g g) args)))))) | |
(lambda (r) | |
(lambda (l acc) | |
(if (endp l) | |
acc | |
(funcall r (cdr l) (cons (car l) acc)))))) | |
l | |
'())))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now that's simple!