Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

.Re: Idiom for gathering pairs from a list?

6 views
Skip to first unread message

Robert L.

unread,
Jul 18, 2017, 4:21:49 PM7/18/17
to
Rob Warnock wrote:

> The problem with any such automatic sizing is LOOPs like this:
>
> (loop for (a b c . rest) on list by #'cdddr ...)
>
> or even this:
>
> (flet ((stepper (list)
> (case (car list)
> ((:one) (cddr list))
> ((:two) (cdddr list))
> ((:three) (cdddr list))
> (otherwise (cdr list)))))
> (loop for (key a b c) on list by #'stepper ...))
>
> which can parse lists like this:
>
> (:one 123 :two 234 453 :three 7 5 8 :special :other 99 22 :two 34 54)


Let's test that crap.

(setq mlist
'(:one 123 :two 234 453 :three 7 5 8 :special :other 99 22 :two 34 54))
(flet ((stepper (list)
(case (car list)
((:one) (cddr list))
((:two) (cdddr list))
((:three) (cdddr list))
(otherwise (cdr list)))))
(loop for (key a b c) on mlist by #'stepper
do (print (list key a b c))))

(:ONE 123 :TWO 234)
(:TWO 234 453 :THREE)
(:THREE 7 5 8)
(8 :SPECIAL :OTHER 99)
(:SPECIAL :OTHER 99 22)
(:OTHER 99 22 :TWO)
(99 22 :TWO 34)
(22 :TWO 34 54)
(:TWO 34 54 NIL)



(use srfi-1) ; break

(define (parse-list the-list)
(if (null? the-list)
'()
(receive (included excluded) (break keyword? (cdr the-list))
(cons (cons (car the-list) included) (parse-list excluded)))))

(parse-list
'(one: 123 two: 234 453 three: 7 5 8 special: other: 99 22 two: 34 54))

===>
((one: 123) (two: 234 453) (three: 7 5 8) (special:) (other: 99 22)
(two: 34 54))


--
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands.... [T]he real aim stays the
same: the biggest genocide in human history.... --- Nick Griffin
(https://www.youtube.com/watch?v=K0hD7IffTJs)

Robert L.

unread,
Jul 22, 2017, 8:25:31 PM7/22/17
to
(use srfi-1)
(use foof-loop)

(define (parse-list the-list)
(define (k-cdr xs) (drop-while (complement keyword?) (cdr xs)))
(loop ((for x xs (in-list the-list k-cdr))
(for r (listing (cons x (take-while (complement keyword?)
(cdr xs))))))
=> r))

(parse-list
'(one: 123 two: 234 453 three: 7 5 8 special: other: 99 22 two: 34 54))

===>
((one: 123) (two: 234 453) (three: 7 5 8) (special:) (other: 99 22)
(two: 34 54))


--
Professor Goldman ... claimed that he and "most historians" regarded history
as a "weapon" to be used for "determining people's ideas and attitudes."
--- Revilo P. Oliver, "The Price of the Head"
Who controls the past ... controls the future: who controls the present
controls the past. --- Orwell
0 new messages