Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Lisp and Scheme

Name: Anonymous 2007-03-08 8:14 ID:fc2iv5gF

Why is this shit still around? Didn't Haskell obsolete it 20 years ago?

Compare map:

 (define (map f lst)
   (let loop ((lst lst)
              (res '()))
     (if (null? lst)
       (reverse res)
       (loop (cdr lst)
             (cons (f (car lst)) res)))))

vs.

 map f []     = []
 map f (x:xs) = f x : map f xs

Name: Anonymous 2007-07-15 20:46 ID:cxlH6lUq

(defmacro filter ((predicate argument) sequence
                  &key (start 0 startp) (end nil endp))
  (let ((elt (gensym "ELT")))
    `(remove-if-not (lambda (,elt)
                      (,predicate ,elt ,argument))
                    ,(if (or startp endp)
                         `(subseq ,sequence ,start ,end)
                         sequence))))

(defmacro << (&rest body)
  `(append ,@body))

(defmacro [] (&rest body)
  `(list ,@body))

(defmacro 1-n (lst frst secnd &rest body)
  `(when lst
    (let ((,frst (car ,lst))
          (,secnd (cdr ,lst)))
      ,@body)))

;;;;;;;;;;;

;;; Haskell
qsort []     = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs)

;;; Lisp
(defun qsort (lst) (1-n lst x xs (<< (qsort (filter (< x) xs)) ([] x) (qsort (filter (>= x) xs)))))



Thread over.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List