<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>82984</integer>
    </number>
    <user>
      <string>???</string>
    </user>
    <title>
      <string>ACL Exercise 5.6</string>
    </title>
    <contents>
      <string>;;; iterative version

(defun intersperse (obj lst)
  (let ((result nil))
    (dolist (x lst (reverse (cdr result)))
      (setf result (nconc (list obj x) result)))))

;;;  recursive version

(defun intersperse (obj lst)
  (let ((res (intersperse-internal obj lst)))
    (subseq res 0 (- (length res) 1))))

(defun intersperse-internal (obj lst)
  (unless (null lst)
    (append (list (car lst) obj)
	    (intersperse-internal obj (cdr lst)))))

(defun makelist (x)
  (if (listp x)
      x
      (list x)))

;;; mapping version
(defun intersperse (obj lst)
  (reduce #'(lambda (x y) (append (makelist x) (makelist obj) (makelist y))) lst))
  </string>
    </contents>
    <universal-time>
      <integer>3455655454</integer>
    </universal-time>
    <channel>
      <string>None</string>
    </channel>
    <colorization-mode>
      <string>None</string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </paste>
  <annotation>
    <number>
      <integer>3</integer>
    </number>
    <user>
      <string>???</string>
    </user>
    <title>
      <string>ACL Exercise 6.4</string>
    </title>
    <contents>
      <string>;;; My solution 

;; fancy-most returns `count' (default 2) functions with the highest score
;; fn - test function which gives a score

(defun fancy-most (fn lst &amp;key (count 2))
  (let ((scores (mapcar #'(lambda (x) (cons x (funcall fn x))) lst)))
    (values-list (mapcar #'car (subseq (sort scores #'&gt; :key #'cdr) 0 count)))))
    
;; test 
(fancy-most #'length '((a b) (a b c) (a))) ; =&gt; (A B C), (A B) 	      


;; Someone else's solution, possibly more efficient?

(defun most (fn lst)
  (if (null lst)
      (values nil nil)
      (if (= (length lst) 1)
        (values (car lst) nil)
        (let* ((wins (if (&gt; (funcall fn (car lst)) (funcall fn (cadr lst)))
                         (car lst)
                         (cadr lst)))
               (wins2 (if (&gt; (funcall fn (car lst)) (funcall fn (cadr lst)))
                         (cadr lst)
                         (car lst))))
          (dolist (obj (cdr (cdr lst)))
            (let ((score (funcall fn obj)))
              (if (&gt; score (funcall fn wins))
                (setf wins2 wins
                      wins  obj)
                (if (&gt; score (funcall fn wins2))
                  (setf wins2 obj)))))
          (values wins wins2)))))

(most #'length '((a b) (a b c) (a))) ; =&gt; (A B C), (A B)</string>
    </contents>
    <universal-time>
      <integer>3455689405</integer>
    </universal-time>
    <channel>
      <string>None</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>2</integer>
    </number>
    <user>
      <string>???</string>
    </user>
    <title>
      <string>untitled</string>
    </title>
    <contents>
      <string>public class Counter
{
	private static m_Counter;
	public static int Stamp()
	{
		return ++m_Counter;
	}
	
	public static int ResetStamp()
	{
		return (m_Counter=0);
	}	
}

Counter.Stamp();
Counter.Stamp();
Counter.ResetStamp();
Counter.Stamp();</string>
    </contents>
    <universal-time>
      <integer>3455670414</integer>
    </universal-time>
    <channel>
      <string>None</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>1</integer>
    </number>
    <user>
      <string>???</string>
    </user>
    <title>
      <string>untitled</string>
    </title>
    <contents>
      <string>;;; ACL 6.5 Example

(let ((counter 0))
  (defun reset-stamp ()
    (setf counter 0))
  (defun stamp ()
    (setf counter (+ counter 1))))</string>
    </contents>
    <universal-time>
      <integer>3455669845</integer>
    </universal-time>
    <channel>
      <string>None</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
</paste-with-annotations>
