fork download
  1. (defun @group (lst)
  2. (labels ((rec (@s not@s lst)
  3. (if (null lst)
  4. (values @s not@s)
  5. (if (char= #\@
  6. (char (symbol-name (car lst))
  7. 0))
  8. (rec (append @s
  9. (list (list (first lst)
  10. (second lst))))
  11. not@s
  12. (cddr lst))
  13. (rec @s (append not@s (list (first lst))) (cdr lst))))))
  14. (rec nil nil lst)))
  15.  
  16.  
  17. (dolist (lst '((t1 t2 @t3 t4 @t5 t6 @t7 t8 t9) ; test data
  18. (t1 t2 t3)
  19. (@t1 @t2 @t3)
  20. (@t1 '(t2 t3) @t4 '())))
  21. (multiple-value-bind (x y) (@group lst)
  22. (format t "~A~%~A~%~%" x y)))
Success #stdin #stdout 0.02s 10600KB
stdin
Standard input is empty
stdout
((@T3 T4) (@T5 T6) (@T7 T8))
(T1 T2 T9)

NIL
(T1 T2 T3)

((@T1 @T2) (@T3 NIL))
NIL

((@T1 '(T2 T3)) (@T4 'NIL))
NIL