I had already solved this problem, but in an unnecessarily convoluted way that seems too specific. Can this be done better?
From a list:
(8 "layer-name" 10 x1 20 y1 10 x2 20 y2 10 x3 20 y3)
8, 10 and 20 are the "key-words" for layer-name, x-coord and y-coord respectively. The actual values follow the "key-words".
Return values should be --> '(("layer-name" x1 y1 x2 y2) ("layer-name" x2 y2 x3 y3))
#lang racket
(require srfi/1)
(define test-list '("multiple-lines" 8 "layer-name" 10 30 20 30 10 40 20 40 10 50 20 50))
(define (get-values lst lst2)
(cond ((eq? lst2 '())
'())
(else
(cons (cadr (member (car lst2) lst))
(get-values lst (cdr lst2))))))
(define (get-multiple-values lst key key2) ; key is single values. key2 is repeatable values
(define (splitter lst keyword) ; (splitter '(10 x1 20 y1 10 x2 20 y2 10 x3 20 y3) 10 20) ---> '((x1 y1 x2 y2 x3 y3) (x2 y2 x3 y3) (x3 y3))
(cond ((not (member keyword lst)) '())
(else (cons (member keyword lst) (splitter (cddr (member keyword lst)) keyword)))))
(define (joiner lst lst-of-lsts) ; (joiner '(1 2) '((a b) (c d))) ---> '((1 2 a b) (1 2 c d))
(cond ((empty? lst-of-lsts) '())
(else (cons (append lst (car lst-of-lsts))
(joiner lst (rest lst-of-lsts))))))
(define (trimmer size lst-of-lsts) ; (trimmer '((x1 y1 x2 y2 x3 y3) (x2 y2 x3 y3) (x3 y3)))
(cond ((empty? lst-of-lsts) '())
((> size (length (car lst-of-lsts)))
(trimmer size (rest lst-of-lsts)))
(else (cons (take (car lst-of-lsts) size)
(trimmer size (rest lst-of-lsts))))))
(joiner (get-values lst key)
(trimmer 4 (map
(lambda (lst) (remq* key2 lst))
(splitter lst (first key2))))))
> '(("layer-name" 30 30 40 40) ("layer-name" 40 40 50 50))