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-03-08 8:20 ID:PciHwIt7

Yeah, and the Haskell version isn't strict. I.e. if one application of f to an element of the list produces _|_, the program won't be affected unless it actually requires evaluation of the element. I.e. if that part of the result list is never used, well, nothing happens!

Contrast with the scheme version, where if "f" becomes _|_ at any stage, the whole evaluation of map falls down right there. I've heard that there's "optional" lazy evaluation available for Scheme somehow, but I don't quite see how Haskell's default behaviour could be found there without syntax contortions. The Haskell "map" is two really short lines for fuck's sake.

Name: Anonymous 2007-03-08 8:52 ID:8iiPARSk

Wow. Way to write an unnecessarily verbose implementation in lisp just to claim that it sucks.

(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))


Also Haskell wasn't around 20 years ago. You idiot.

Name: Anonymous 2007-03-08 8:57 ID:lf8KjFgA

Wrong, Haskell is 20 years old.

Name: Anonymous 2007-03-08 9:15 ID:8iiPARSk

>>4
The decision to form a committee to start work on a language to replace the plethora of lazy functional languages that had sprung up around that time was made in 1987. The first Haskell report wasn't ready until 1990. You can hardly claim that Haskell sprung into existence at that 1987 meeting.

(source: http://research.microsoft.com/~simonpj/papers/history-of-haskell/history.pdf)

Name: Anonymous 2007-03-08 9:52 ID:5xEvRgGA

Pythonic is better:
map = lambda f, l: l and [f(l[0])] + map(f, l[1:]) or []

Name: Anonymous 2007-03-08 10:31 ID:fc2iv5gF

>>3
That's what it says on wikipedia. I couldn't implement it myself because I find scheme unreadable, sorry.

Name: Anonymous 2007-03-08 10:53 ID:8iiPARSk

>>6
Just gtfo.

>>7
You fail almost as hard as wikipedia does.

Name: Anonymous 2007-03-08 10:57 ID:8iiPARSk

>>7
PS: I just checked out the wikipedia article and found that the simple definition is just a few lines above the version you copypastaed. So you fail doubly hard.

Name: Anonymous 2007-03-08 12:02 ID:fc2iv5gF

>>9
But that one's not constant space.

Name: Anonymous 2007-03-08 12:42 ID:8iiPARSk

>>10
It's equivalent to the Haskell implementation in >>1

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

map f xs = [f x | x <- xs]

Name: Anonymous 2007-03-08 13:16 ID:8iiPARSk

>>12
That's cheating since list comprehensions are just sugar for map and filter.

Name: Anonymous 2007-03-08 13:36 ID:fc2iv5gF

Okay here's a challenge to you Lisp heads then: write a function that takes a list of numbers X and an arbitrary list Y and splits Y into sublists the size of x1, x2, x3,...

in other words:
f [2,5,0,3] [1..15] == [[1,2],[3,4,5,6,7],[],[8,9,10],[11,12,13,14,15]]

here's the Haskell version:

f = foldr (\n r -> splitAt n >>> second r >>> uncurry (:)) return

Name: Anonymous 2007-03-08 13:37 ID:Heaven

>>13
Syntactic sugar isn't cheating, it's part of what makes a language good.

Name: Anonymous 2007-03-08 14:29 ID:0K1rHNcu

>>14
f = foldr (\n r -> splitAt n >>> second r >>> uncurry (:)) return

i don't care how long the lisp implementation of this would be; that code is just plain unreadable

Name: Anonymous 2007-03-08 14:29 ID:8iiPARSk

>>15
It's cheating when you're effectively just saying map = map.

Name: Anonymous 2007-03-08 15:05 ID:HAXZGHRF

Pythonic is still better:
map = lambda f, s: [f(i) for i in s]

Name: Anonymous 2007-03-08 15:51 ID:+zfmzq04

>>18
One word.  The automatic failure by posting something in Python.  Thread over.

Name: Anonymous 2007-03-08 16:05 ID:0K1rHNcu

Perl is better:
map

Name: Anonymous 2007-03-08 16:52 ID:HAXZGHRF

Python is better:
map = map

Name: Anonymous 2007-03-08 18:08 ID:y8b7j2FS

lol Python tries to emulate Haskell constructions like:
[f i | i <- s]

Name: Anonymous 2007-03-09 1:15 ID:D6jfNXCs

composing function in phyton: compose(f, compose(h, g))

FAIL FAIL FAIL

Name: Anonymous 2007-03-09 12:55 ID:30NVleim

>>3
win rar

>>23
agreed python is mega fail

Name: Anonymous 2007-03-09 14:39 ID:XDJhv50N

C++:

std::map<key_type, val_type> map;

Name: Anonymous 2007-03-09 15:02 ID:EmXvn2/u

>>25
Fail.

Name: Anonymous 2007-03-09 15:26 ID:Elye7AiN

C#:

Systems.Collections.Generic.HashMap

Name: Anonymous 2007-03-09 16:17 ID:30NVleim

>>25
>>27
LOL @ FAGS WHO DONT KNOW WHAT MAP IS

Name: Anonymous 2007-03-10 5:47 ID:YeZ1LdoH

BITCHES DON'T KNOW ABOUT MY BASIC FUNCTIONAL PROGRAMMING TOOLS

Name: Anonymous 2007-03-10 6:05 ID:wGCvAh2I

Name: Anonymous 2007-03-10 6:38 ID:YeZ1LdoH

>>30
USE XOR MOTHERFUCKER

Name: Anonymous 2007-07-14 11:02 ID:2D5LhY9n

>>14
f = foldr (\n r -> splitAt n >>> second r >>> uncurry (:)) return
my eyeballs are fuxx0r3d

Name: Anonymous 2007-07-14 11:12 ID:S+VYkp2c

>>30
Pythonic is better
b, a = a, b

Name: Anonymous 2007-07-14 11:20 ID:2D5LhY9n

2007-03-10 06:05  ID:wGCvAh2I
2007-07-14 11:12  ID:S+VYkp2c
So you did it in 3005 hours.  Yay for imperative programming.

Name: Anonymous 2007-07-14 11:43 ID:13pZjECx

uotse shdelkeyadze

Name: Anonymous 2007-07-14 12:08 ID:2D5LhY9n

>>35
Я ГРУЗИН

Name: Anonymous 2007-07-14 12:11 ID:13pZjECx

I GRUZIN

Name: Anonymous 2007-07-14 14:08 ID:+NYZrvYp

What you faggots are forgetting is that faggot shit like list comprehensions and all that syntactical sugar can be added to lisp . With lisp you can get as much syntactical sugar as you want.

Macros faggot, do you speak them?

Name: Anonymous 2007-07-14 15:23 ID:4U/+81ZL


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER


(define (map f list)
  (if (null? list) list
      (cons (f (car list)) (map f (cdr list)))))

THREAD OVER

Name: Anonymous 2007-07-15 20:17 ID:3OgO/mI2

first of all, lisp's map is different than haskell map. Lisp's map takes a variable number of arguments, so you can write something like

(map + '(1 2 3) '(4 5 6)) --> (5 7 9)


still, if you want a nice definition of a haskell-like map in scheme, I'm guessing it would be something like

(define (map f list)
  (foldr nil (lambda (e acc) (cons (f e) acc)) list))

which of course is the equivalent of

map f list = foldr [] (/ e acc -> (f e):acc)) list

which of course may seem shorter, but only because of syntax, and if haskell macros are any indication of, it matters little.
(The same applies to pattern matching vs. accesor functions, unless you like 20+ functions breaking when you add a field in your data type).

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