| 129 | |
| 130 | To solve this problem in Scheme recursively, let's define a recursive function that will process the list of lists and split them into groups whenever a sublist starts with the specified symbol. |
| 131 | |
| 132 | ### Steps: |
| 133 | |
| 134 | 1. **Base Case**: If the list of lists is empty, return an empty list. |
| 135 | 2. **Recursive Case**: |
| 136 | - If the first sublist starts with the given symbol and the current group is not empty, start a new group. |
| 137 | - Otherwise, continue adding sublists to the current group. |
| 138 | |
| 139 | ### Scheme Implementation: |
| 140 | |
| 141 | Here’s how you can implement this in Scheme: |
| 142 | |
| 143 | ```scheme |
| 144 | (define (split-list-of-lists list-of-lists symbol) |
| 145 | (define (split-helper lists current-group result) |
| 146 | (cond |
| 147 | ((null? lists) |
| 148 | (if (null? current-group) |
| 149 | result |
| 150 | (append result (list current-group)))) |
| 151 | ((equal? (caar lists) symbol) |
| 152 | (if (null? current-group) |
| 153 | (split-helper (cdr lists) (list (car lists)) result) |
| 154 | (split-helper (cdr lists) (list (car lists)) (append result (list current-group))))) |
| 155 | (else |
| 156 | (split-helper (cdr lists) (append current-group (list (car lists))) result)))) |
| 157 | (split-helper list-of-lists '() '())) |
| 158 | |
| 159 | ;; Example usage: |
| 160 | (define list-of-lists |
| 161 | '((a 1 2 3) |
| 162 | (b 4 5 6) |
| 163 | (* 7 8 9) |
| 164 | (c 10 11) |
| 165 | (* 12 13) |
| 166 | (d 14 15 16))) |
| 167 | |
| 168 | (define symbol '*) |
| 169 | |
| 170 | (split-list-of-lists list-of-lists symbol) |
| 171 | ``` |
| 172 | |
| 173 | ### Explanation: |
| 174 | |
| 175 | 1. **`split-list-of-lists`**: The main function that initializes the recursive process with an empty `current-group` and `result`. |
| 176 | |
| 177 | 2. **`split-helper`**: |
| 178 | - **Base Case**: When `lists` is empty, if `current-group` is also empty, return the `result`. Otherwise, append the `current-group` to the `result`. |
| 179 | - **When symbol is encountered**: If the current group is not empty, append it to the result and start a new group. If the current group is empty, simply start a new group with the current sublist. |
| 180 | - **Else case**: Append the current sublist to the `current-group` and continue the recursion. |
| 181 | |
| 182 | ### Example Output: |
| 183 | Running the above code with the example `list-of-lists` and `symbol`, you should get: |
| 184 | |
| 185 | ```scheme |
| 186 | '(((a 1 2 3) (b 4 5 6)) |
| 187 | ((* 7 8 9) (c 10 11)) |
| 188 | ((* 12 13) (d 14 15 16))) |
| 189 | ``` |
| 190 | |
| 191 | This Scheme code recursively processes the list of lists and splits them into groups based on the given symbol. |
| 192 | |