Welcome to the CHICKEN Scheme pasting service

keyword argument processing as seen in the iup egg pasted by murphy on Fri Jul 5 20:06:03 2013

(define ((make-constructor-procedure proc #!key [apply-args values]) . args)
  (let more ([keys '()] [key-args '()] [pos-args '()] [rest args])
    (cond
      [(null? rest)
       (let ([handle (apply proc (apply-args (reverse! pos-args)))])
         (do-ec (:parallel (:list key keys) (:list arg key-args))
           ((if (procedure? arg) callback-set! attribute-set!) handle key arg))
                handle)]
      [(keyword? (car rest))
       (more
        (cons (car rest) keys) (cons (cadr rest) key-args) pos-args
        (cddr rest))]
      [else
       (more
        keys key-args (cons (car rest) pos-args)
        (cdr rest))])))

modification to do what Timusan wants ;-) added by murphy_tcc on Fri Jul 5 20:14:35 2013

(define (arguments&keys&values args)
  (let more ([keys '()] [key-args '()] [pos-args '()] [rest args])
    (cond
      [(null? rest)
       (values pos-args keys key-args)]
      [(keyword? (car rest))
       (more
        (cons (car rest) keys) (cons (cadr rest) key-args) pos-args
        (cddr rest))]
      [else
       (more
        keys key-args (cons (car rest) pos-args)
        (cdr rest))])))

(define (plist->alist args)
  (receive (args keys vals) (arguments&keys&values args)
    (map cons keys vals)))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the operator to construct procedures?
Visually impaired? Let me spell it for you (wav file) download WAV