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

Racket

Name: Anonymous 2011-01-28 7:43

Why Racket doesn't have a uniform collection interface? It's fucking stupid to have string-ref, vector-ref, list-ref etc in the language.

Name: Anonymous 2011-01-28 7:48

scheme is for niggers

Name: Doctor Racket !RACKET/.HY 2011-01-28 7:58

>>1
You can easily make your own.
http://docs.racket-lang.org/reference/sequences.html

But you'd use car/cdr with lists anyways.

Name: Doctor Racket !RACKET/.HY 2011-01-28 8:03

>>3

(define (sequence-ref seq n)
  (let-values (((next? next) (sequence-generate seq)))
    (let loop ((r '()))
      (if (next?) (loop (next)) r))))
(sequence-ref '(1 2 3) 2) ; 3
(sequence-ref #(1 2 3) 2) ; 3
(sequence-ref "123" 2)    ; #\3
(sequence-ref #"123" 2)   ; 51 (#\3)

Name: Anonymous 2011-01-28 8:17

>>3
>>4
http://docs.racket-lang.org/reference/sequences.html#(mod-path._racket/stream)

According to the page you linked you don't even need to write your own. Or am I missing something?


(stream-ref '(1 2 3) 1)
2
(stream-ref #(1 2 3) 1)
2
(stream-ref "123" 1)
#\2

Name: Doctor Racket !RACKET/.HY 2011-01-28 8:29

>>5
I thought they were delayed lists and jumped that part.
Yes, you can use that.

Name: Anonymous 2011-01-28 8:41

>>6
But the question still stands, why there are distinct functions for each type, why not to have just one generic ref, length, map that would work with any sequence?

Name: Anonymous 2011-01-28 8:50

>>7
You may want your code to be data-structure specific, and because of stream-ref returning two values when applied to an hash (they could just return a cons with (key . value)).
The non-polymorphic ``ref'' (that simply doesn't exist), length, map, etc are inherited from old Lisps, and freshmen in CL often wonder why they are not defined as generics.

However, you could just define your module/#lang that exports them as the stream-* variants and use it.

Name: Doctor Racket !RACKET/.HY 2011-01-28 8:50

>>8
Also, forgot my name.

Name: Anonymous 2011-01-28 9:48

>>9
Look at this faggot!

Name: Anonymous 2011-01-28 9:49

1. It should be possible with swindle, unless they took that out of racket. (ditto for all the clos-alikes like coops & goops)
2. I seem to recall a collections SRFI, but it (obviously) didn't take off.

Name: Doctor Mario!TRiP/.FAG 2011-02-27 11:25

>>3
>>4
>>6
lol too sicp didnt fread

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