1
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
41
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.
43
Name:
Anonymous
2007-07-15 20:58
ID:cxlH6lUq
>>15
If syntactic sugar (see: pattern matching) makes a language good, then a language that allows you to define your own syntactic sugar is even better.
...
HOW DO I UNDERSTOOD THE IMPLICATIONS OF MACROS?
44
Name:
Anonymous
2007-07-15 21:00
ID:TZF+Q6RH
>>6
Why is this shit still around? Didn't C obsolete it 20 years ago?
45
Name:
Anonymous
2007-07-15 22:38
ID:Heaven
Type inference is for fags
46
Name:
Anonymous
2007-07-15 23:30
ID:3OgO/mI2
>>14
why? this is almost as short (a few characters of difference) and cleaner
f [] l2 = l2
f t:r l2 = frs:f r rst
where (frs, rst) = splitAt t l2
contrast:
f [] l2 = l2 f t:r l2 = frs:f r rst where (frs, rst) = splitAt t l2
f = foldr (\n r -> splitAt n >>> second r >>> uncurry (:)) return
of course lisp version is similar to this.