user2033237
user2033237

Reputation: 23

Lisp Move Elements in a List

I have a list of the form:

(or a b c (and d e) f g (and h i) (==> x y))

and I like to move the sublists beginning with and after the or like this:

(or (and d e) (and h i) a b c f g (==> x y))

How can I do this? I'm not sure what's the best way since it's a list and I can't just put an element whatever I want, like I can with other data structures.

Upvotes: 1

Views: 536

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139251

? (stable-sort (rest '(or a b c (and d e) f g (and h i) (==> x y)))
               (lambda (x y)
                 (and (consp x) (eq (first x) 'and))))
((AND H I) (AND D E) A B C F G (==> X Y))

Upvotes: 1

Related Questions