It could be possible to save a character per sublist: use a symbol as separator. I will use a seperator ';' and '|' as a blocker of separated sublisting. (Although they wouldnt work for common lisp since they are already used.)
If you read in the blocker and separator as symbols, you can make them work like this. (Feel like this code is rather clumsy though.)
It does cut down on a look of hooks. Although newbies are often scared of hooks, it might be a good idea to let them use the hooks because if they don't, they might not realize properly(or as fast) that there are lists in there.
If you read in the blocker and separator as symbols, you can make them work like this. (Feel like this code is rather clumsy though.)
(defun apply-separators (tree separator blocker)
(let (here out sublist)
(flet ((add-here ()
(if sublist
(push (reverse here) out)
(setf out (append here out)))
(setf sublist nil)
(setf here nil)))
(dolist (el tree)
(cond
((eql el separator)
(setf sublist t)
(push (reverse here) out)
(setf here nil))
((eql el blocker)
(add-here))
(t
(push (if (listp el)
(apply-separators el separator blocker)el)
here))))
(unless (null here)
(add-here))
(reverse out))))
This will convert stuff like this: (b-> '|', s-> ';')
(apply-separators '(1 2 3 s (4 5 s 6 7 b 1 2) 4 6 s 4 9 1 b 1 2 3 4 5 b 1 4 s 5 5) 's 'b) -> ((1 2 3) ((4 5) (6 7) 1 2) (4 6) (4 9) 1 2 3 4 (1 4) (5 5))
This can make some code prettier, especially very non-functional code, and when you need sublists, here i also added xml-like stuff.
<defmethod apply-separators> (tree list ; separator symbol ; blocker symbol)
(let (here out sublist)
(flet ((add-here () |
if sublist
(push (reverse here) out)
(setf out (append here out));
setf sublist nil;
setf here nil;))
(dolist (el tree)
(cond
(eql el separator;
setf sublist t;
push (reverse here) out;
setf here nil;)
(eql el blocker;
add-here;)
(t
push (if (listp el)
(apply-separators el separator blocker) el)
here;)))
(unless | null here;
add-here;)
(reverse out)))
</defmethod apply-separators>
Now, i myself am not sure if this is a good idea. But what do you think? Could i get slime to accept it? (Edit: changed it to make it a little more readable.)It does cut down on a look of hooks. Although newbies are often scared of hooks, it might be a good idea to let them use the hooks because if they don't, they might not realize properly(or as fast) that there are lists in there.
Last edited by Jasper on , edited 3 times in total.