Welcome to the CHICKEN Scheme pasting service

Turn list of lists into special format pasted by pinkiesOut on Fri Mar 13 03:53:20 2015

;;; This is an example list to play with
(define bar 
  '((created_at)
    (id)
    (id_str)
    ((user)
     (name)
     (screen_name)
     (location))
    (geo)
    ((status)
     (date)
     ((web)
      (url)
      (description))
     (time))
    (coordinates)))

;;; My current version (that doesn't work properly)
(define (foo lst)
  (cond [(null? lst) '()]
	[(list? (car lst))
	 (cons (car (car lst))
	       (foo (cdr (car lst))))]
	[else (cons (car lst)
		    (foo (cdr lst)))]))

;;; This gets things done (well, it should anyway)
(map (lambda (x) (foo x)) bar)

;;; What I want it to return:
'((created_at)
  (id)
  (user name)
  (user screen_name)
  (user location)
  (geo)
  (status date)
  (status web url)
  (status web description)
  (status time)
  (coordinates))

;;; The call to map currently returns. 
'((created_at)
  (id)
  (id_str)
  (user)
  (geo)
  (status)
  (coordinates))

How about this! pasted by DerGuteMoritz on Fri Mar 13 12:51:40 2015

(define (transform lst)
  (define (prefix x)
    (map (lambda (y)
           (if (pair? (car y))
               (cons (append (car x) (car y)) (cdr y))
               (append (car x) y)))
         (cdr x)))

  (reverse!
   (let loop ((lst lst) (result '()))
     (if (null? lst)
         result
         (let ((x (car lst)))
           (if (pair? (car x))
               (loop (append (prefix x) (cdr lst))
                     result)
               (loop (cdr lst)
                     (cons x result))))))))

Slightly nicer :-) added by DerGuteMoritz on Fri Mar 13 13:04:17 2015

(define (transform lst)
  (define (prefix x)
    (map (lambda (y)
           (if (pair? (car y))
               (cons (append (car x) (car y)) (cdr y))
               (append (car x) y)))
         (cdr x)))

  (let loop ((lst lst) (result '()))
    (if (null? lst)
        (reverse! result)
        (let ((x (car lst)))
          (if (pair? (car x))
              (loop (append (prefix x) (cdr lst))
                    result)
              (loop (cdr lst)
                    (cons x result)))))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which module provides `process-wait'?
Visually impaired? Let me spell it for you (wav file) download WAV