Code Monkey home page Code Monkey logo

racket-collections's Introduction

racket-collections's People

Contributors

lexi-lambda avatar countvajhula avatar alexknauth avatar stamourv avatar

Stargazers

 avatar Nikita avatar ebigram avatar  avatar Taylor Hodge avatar Lîm Tsú-thuàn avatar June Kelly avatar  avatar caocao485 avatar Grzegorz Caban avatar  avatar  avatar Vladilen Kozin avatar Isak avatar Jinzhou Zhang avatar  avatar bb010g avatar Daniele avatar interplinternet avatar Richard avatar Pete Doherty avatar  avatar hkrish avatar James Milne avatar James Edward Lewis II avatar Ben Greenman avatar Alexandre Souza avatar Jiamo avatar Hashim avatar Maximilian Eckenbach avatar Peter Nagy avatar Ronie Uliana avatar Cory Burgett avatar Ehtesh Choudhury avatar vexed avatar John Smith avatar Emmanuel Oga avatar dap avatar 404 avatar Kyle Isom avatar Zeeshan Lakhani avatar Jeremy Heiler avatar Sam Tobin-Hochstadt avatar Mark Thom avatar Christoffer Sawicki avatar Ha-Duong Nguyen avatar Asumu Takikawa avatar Greg Hendershott avatar  avatar Bryan Garza avatar  avatar Jack Firth avatar

Watchers

 avatar  avatar  avatar caocao485 avatar Ziwen Yu avatar  avatar

racket-collections's Issues

Request: mutation on collections

Can we have an extension to the collections package, which adds mutable-collections in which we have set-nth! and set-nth*!? Or is there a reason why these were not added in the first place?

Take and drop aren't lazy for finite sequences

For sequences that are known-finite?, take and drop check the length of the input sequence eagerly before computing the result, so that something like:

(take 3 (range 10000000))

... forces the entire finite sequence, even though (range 10000000) on its own would be lazily computed.

Possible fix: Compute the result lazily and raise an error if a point is reached where the remaining sequence is empty but more values are still expected.

It's possible this would have some backwards compatibility implications, since code that formerly would raise an error immediately would now raise the error at a later stage.

raco pkg install error "conjoin: unbound identifier"

I'm getting errors about conjoin:

/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*

Full transcript:

$ raco pkg install collections
Resolving "collections" via http://download.racket-lang.org/releases/6.2/catalog/
Resolving "collections" via http://pkgs.racket-lang.org
Downloading https://github.com/lexi-lambda/racket-collections/tarball/5d69a8e189ff16c9fb240c7e13ea607711924068
The following uninstalled packages are listed as dependencies of collections:
   alexis-util
Would you like to install these dependencies? [Y/n/a/c/?] 
Resolving "alexis-util" via http://download.racket-lang.org/releases/6.2/catalog/
Resolving "alexis-util" via http://pkgs.racket-lang.org
Downloading https://github.com/lexi-lambda/racket-alexis/tarball/f5e3cbad14ba951a302bc45d1b0e1c554a13b523
The following uninstalled packages were listed as dependencies
and they were installed:
 dependencies of collections:
   alexis-util
raco setup: version: 6.2 [3m]
raco setup: installation name: 6.2
raco setup: variants: 3m
raco setup: main collects: /usr/racket/collects
raco setup: collects paths: 
raco setup:   /home/greg/.racket/6.2/collects
raco setup:   /usr/racket/collects
raco setup: main pkgs: /usr/racket/share/pkgs
raco setup: pkgs paths: 
raco setup:   /usr/racket/share/pkgs
raco setup:   /home/greg/.racket/6.2/pkgs
raco setup: links files: 
raco setup:   /usr/racket/share/links.rktd
raco setup:   /home/greg/.racket/6.2/links.rktd
raco setup: main docs: /usr/racket/doc
raco setup: --- updating info-domain tables ---
raco setup: updating: /home/greg/.racket/6.2/share/info-cache.rktd
raco setup: --- pre-installing collections ---
raco setup: --- installing foreign libraries ---
raco setup: --- installing shared files ---
raco setup: --- compiling collections ---
raco setup: --- parallel build using 4 jobs ---
raco setup: 3 making: <pkgs>/alexis-util/alexis
raco setup: 2 making: <pkgs>/alexis-util/typed
raco setup: 2 making: <pkgs>/alexis-util/typed/alexis
raco setup: 2 making: <pkgs>/alexis-util/typed/alexis/util
raco setup: 1 making: <pkgs>/collections/data
raco setup: 1 making: <pkgs>/collections/data/collection
raco setup: 3 making: <pkgs>/alexis-util/alexis/private
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection/contract.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:708:4
   /usr/racket/collects/setup/parallel-do.rkt:431:20: loop
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  context...:
   standard-module-name-resolver
   standard-module-name-resolver
   /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
   /usr/racket/collects/racket/private/map.rkt:26:19: loop
   /usr/racket/collects/racket/require.rkt:26:3
   /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
   try-next
   try-next
   /usr/racket/collects/racket/private/reqprov.rkt:243:2
   /usr/racket/collects/syntax/wrap-modbeg.rkt:46:4
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection/indexable.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:708:4
   /usr/racket/collects/setup/parallel-do.rkt:431:20: loop
raco setup: 1 making: <pkgs>/collections/data/collection/private
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  context...:
   standard-module-name-resolver
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection/sequence.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:708:4
   /usr/racket/collects/setup/parallel-do.rkt:431:20: loop
raco setup: 1 making: <pkgs>/collections/data/collection/private/test
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  context...:
   standard-module-name-resolver
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection/private/test/collection.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   ...
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  context...:
   standard-module-name-resolver
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection/private/test/dict.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   ...
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  context...:
   standard-module-name-resolver
raco setup: 1 making: <pkgs>/collections/data/scribblings
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  compilation context...:
   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection.rkt
   /home/greg/.racket/6.2/pkgs/collections/data/collection/private/test/sequence-lib.rkt
  context...:
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   /usr/racket/collects/compiler/cm.rkt:548:42
   /usr/racket/collects/compiler/cm.rkt:513:0: maybe-compile-zo
   /usr/racket/collects/compiler/cm.rkt:628:2: do-check
   /usr/racket/collects/compiler/cm.rkt:744:4: compilation-manager-load-handler
   standard-module-name-resolver
   /usr/racket/collects/compiler/cm.rkt:341:0: compile-zo*
   /usr/racket/collects/compiler/cm.rkt:556:26
   ...
raco setup: 1 making: <pkgs>/collections/data/scribblings/collection
raco setup: 1 making: <pkgs>/collections/data/scribblings/private
raco setup: 3 making: <pkgs>/alexis-util/alexis/private/test
raco setup: 3 making: <pkgs>/alexis-util/alexis/scribblings
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  context...:
   standard-module-name-resolver
raco setup: 3 making: <pkgs>/alexis-util/alexis/util
raco setup: --- creating launchers ---
raco setup: --- installing man pages ---
raco setup: --- building documentation ---
raco setup: 1 running: <pkgs>/alexis-util/alexis/scribblings/alexis-util.scrbl
raco setup: 3 running: <pkgs>/collections/data/scribblings/collections.scrbl
/home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
  in: conjoin
  context...:
   standard-module-name-resolver
   standard-module-name-resolver
   /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
   /usr/racket/collects/racket/private/map.rkt:26:19: loop
   /usr/racket/collects/racket/require.rkt:26:3
   /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
   try-next
   try-next
   /usr/racket/collects/racket/private/reqprov.rkt:243:2
   /usr/racket/collects/syntax/wrap-modbeg.rkt:46:4
   standard-module-name-resolver
   /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
   /usr/racket/collects/racket/private/reqprov.rkt:431:5
   /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
   try-next
   /usr/racket/collects/racket/private/reqprov.rkt:243:2
   ...

  context...:
   /usr/racket/collects/setup/parallel-do.rkt:330:4: work-done method in list-queue%
   /usr/racket/collects/setup/parallel-do.rkt:280:17
   /usr/racket/collects/setup/parallel-do.rkt:234:4
   /usr/racket/share/pkgs/racket-index/setup/scribble.rkt:138:0: setup-scribblings
   /usr/racket/collects/setup/setup-core.rkt:69:0: setup-core
   /usr/racket/collects/setup/setup.rkt:65:3
   /usr/racket/collects/pkg/main.rkt:16:0: setup
   (submod /usr/racket/collects/pkg/main.rkt main): [running body]
   /usr/racket/collects/pkg/raco.rkt: [traversing imports]
raco setup: 3 rendering: <pkgs>/alexis-util/alexis/scribblings/alexis-util.scrbl
raco setup: 2 rendering: <pkgs>/racket-index/scribblings/main/user/local-redirect.scrbl
raco setup: 1 rendering: <pkgs>/racket-index/scribblings/main/user/release.scrbl
raco setup: 0 rendering: <pkgs>/racket-index/scribblings/main/user/search.scrbl
raco setup: 1 rendering: <pkgs>/racket-index/scribblings/main/user/start.scrbl
raco setup: --- installing collections ---
raco setup: --- post-installing collections ---
raco setup: --- summary of errors ---
raco setup: error: during making for <pkgs>/collections/data
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data/collection
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data/collection
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup: error: during making for <pkgs>/collections/data/collection
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data/collection
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup: error: during making for <pkgs>/collections/data/collection
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data/collection/private
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup: error: during making for <pkgs>/collections/data/collection/private/test
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data/collection/private/test
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup: error: during making for <pkgs>/collections/data/collection/private/test
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data/collection/private/test
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup: error: during making for <pkgs>/collections/data/collection/private/test
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     compiling: <pkgs>/collections/data/collection/collection.rkt
raco setup: error: during making for <pkgs>/collections/data/collection/private/test
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup: error: during building docs for <pkgs>/collections/data/scribblings/collections.scrbl
raco setup:   /home/greg/.racket/6.2/pkgs/collections/data/collection/collection.rkt:182:5: conjoin: unbound identifier in module
raco setup:     in: conjoin
raco setup:     context...:
raco setup:      standard-module-name-resolver
raco setup:      standard-module-name-resolver
raco setup:      /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
raco setup:      /usr/racket/collects/racket/private/map.rkt:26:19: loop
raco setup:      /usr/racket/collects/racket/require.rkt:26:3
raco setup:      /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
raco setup:      try-next
raco setup:      try-next
raco setup:      /usr/racket/collects/racket/private/reqprov.rkt:243:2
raco setup:      /usr/racket/collects/syntax/wrap-modbeg.rkt:46:4
raco setup:      standard-module-name-resolver
raco setup:      /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
raco setup:      /usr/racket/collects/racket/private/reqprov.rkt:431:5
raco setup:      /usr/racket/collects/racket/require-transform.rkt:266:2: expand-import
raco setup:      try-next
raco setup:      /usr/racket/collects/racket/private/reqprov.rkt:243:2
raco setup:      ...
raco setup:   
raco pkg install: packages installed, although setup reported errors

Improve documentation of gen:indexable

I had a hard time figuring out how to create a struct that implements gen:indexable
My attempt:
(struct ash (h) #:methods gen:indexable [(define (ref collection index) (hash-ref (ash-h collection) index)) (define (set-ref collection index value) (ash (hash-set (ash-h collection) index value)))]
With error message:
gen:indexable: generic method definition has an incorrect arity; expected a procedure that accepts 1 or more arguments ref: #<procedure:ref>
Asking for help on slack I realised the expected definition was (define (ref collection . rest) ...)

I have two questions

  1. Could you update the documentation with a small example?
  2. How is this choice motivated? It seems different to the rest of the generics

Every n-th element in a sequence

Some of the built-in Racket sequences provide start, end and step args, like (in-vector) and (in-string) (link). There doesn't seem to be an out-of-the-box way to do this with data/collection sequences, or is there?

How about a new interface every that looks something like this:

(define (every cnt seq)
  (if (empty? seq)
      empty-stream
      (let ([head (first seq)]
            [tail (with-handlers
                    ([exn:fail?
                      (λ (exn)
                        empty-stream)])
                    (drop cnt seq))])
        (stream-cons head (every cnt tail)))))

which could be used like:

(take 10 (every 5 (naturals)))
;; evens
(take 10 (every 2 (naturals)))
;; odds
(take 10 (every 2 (naturals 1)))
;; with an offset
(take 10 (every 7 (drop 100 (naturals))))
;; together with subsequence for start, stop, step
(every 3 (subsequence (naturals) 10 20))
;; in vector
(every 3 #(1 2 3 4 5 6 7 8 9 10))

which yield the outputs (converted to list):

'(0 5 10 15 20 25 30 35 40 45)
> 
'(0 2 4 6 8 10 12 14 16 18)
> 
'(1 3 5 7 9 11 13 15 17 19)
> 
'(100 107 114 121 128 135 142 149 156 163)
>
'(10 13 16 19)
>
'(1 4 7 10)

Do you think this would be a worthwhile addition to data/collection? If so, I could put something like it in a PR.

Adding update-ref functions?

Hi there. I noticed updating functions (hash-update...) aren't included in the generic interface for indexables.
Seems like it's an easy addition (though I could be wrong) by just adding them to collections-lib/data/collection/indexable.rkt like so:

(provide
 gen:indexable indexable? indexable/c
 ref set-ref update-ref)

(define-generics indexable
  (ref indexable . _)
  (set-ref indexable . _)
  (update-ref indexable . _)
  #:defaults
  ([hash? (define ref hash-ref)
          (define set-ref hash-set)
          (define update-ref hash-update)]
   [dict? (define ref dict-ref)
          (define set-ref dict-set)
          (define update-ref dict-update)]
   [sequence? (define ref nth)
              (define set-ref set-nth)
              (define update-ref update-nth)]))

Seems to work locally with just this change, but I'm not sure if there are some potential issues with their inclusion that I'm missing and so I didn't want to make a PR directly.
Thanks :)

Optional strictness?

The lazy behavior of the generic map, filter, etc. functions is very useful, but sometimes lazyness isn't something I want. For example, tests, docs examples, and REPL experimentation. It'd be nice to be able to turn the lazyness off. Maybe a parameter, or strict versions of the functions?

> (map add1 (list 1 2 3))
#<stream>
> (map-strict add1 (list 1 2 3))
'(2 3 4)
> (use-strict-sequences!)
> (map add1 (list 1 2 3))
'(2 3 4)

No license file

I was considering studying this to see how to implement transducers for Guile, but I notice there's no license file! No license == effectively proprietary, so it would be great if you could add one! Maybe the LGPL, to make it compatible with Racket itself?

unclear on reason for `gen:indexable` arity error

This will work:

#lang racket
(require data/collection)
(struct wrapped-collection (value)
    #:methods gen:countable
     [(define (length c) 42)])

(length (wrapped-collection 'foo)) ; 42

But remove the c from the definition of length, and it won't:

#lang racket
(require data/collection)
(struct wrapped-collection (value)
    #:methods gen:countable
     [(define (length) 42)])

And the error message makes sense — length expects one argument, and we removed it:

git/racket/racket/collects/racket/private/generic.rkt:523:0: gen:countable: generic method definition
 has an incorrect arity; expected a procedure that accepts 1 argument
  length: #<procedure:length>

Now consider this example, with gen:indexable:

#lang racket
(require data/collection)
(struct wrapped-collection (value)
    #:methods gen:indexable
     [(define (ref c i) 42)])

It immediately triggers a similar arity error:

git/racket/racket/collects/racket/private/generic.rkt:523:0: gen:indexable: 
generic method definition has an incorrect arity; expected a procedure that 
accepts 1 or more arguments
  ref: #<procedure:ref>

But why? ref does in fact accept the right number of arguments.

`has-key?` function for `indexable` interface

I'm attempting to make some lenses that view maybes of indexables, but there's no way to test if a key is in an indexable. I was expecting some sort of has-key? complement to ref, where (has-key? indexable key) => #t implies that (ref indexable key) won't throw. Is this something that should be part of the indexable interface?

Better default print representation

In your original talk you suggested that having a better default print representation for streams would make generic collections more user-friendly. In the light of #27 and #28 , what do you think about defining a new sequence type, annotated-sequence which simply wraps a sequence returned from this library and annotates it with known finiteness or anything else that may be useful? In addition, it would include a clean print representation that:

  • prints the entire sequence if it is known-finite?
  • forces the first few elements if it isn't

This would allow us to resolve #27 and #28 . In addition, if all APIs in the library wrapped their result with annotated-sequence, using generic sequences in practice would always have useful print representations, even if the core stream type doesn't.

set-nth* guarantees

Is there any guarantee that set-nth* will not create intermediate copies of the sequence? The documentation says it calls set-nth repeatedly but that means it'll probably copy the original sequence once per set tuple, right?

Range does not return a known finite sequence

At the moment, Racket's in-range is simply re-provided as range. As this doesn't encode known finiteness, it results in unexpected behavior when used with other APIs:

(empty? (range 0)) ;=> #t
(empty? (take 5 (range 0))) ;=> #f
(length (take 5 (range 3))) ;=> 5

This happens because take and drop return bounded sequences without forcing the input sequence if it isn't known-finite?. For range, this means that it returns a bounded sequence of length 5 (in the above example) even though the input is actually known finite and of length 3.

Suggested fix: Wrap in-range with a sequence that implements gen:countable and always returns true for known-finite?.

Bug: conj* and extend* for collections that aren't sequences

If a struct type implements gen:collection but not gen:sequence, then conj* and extend* result in a contract error.

(struct bag (contents)
  #:transparent
  #:methods gen:collection
  [(define (conj col elem)
     (bag (cons elem (bag-contents col))))])

main.rkt> (conj (bag (list 1 2 3)) 4)
(bag '(4 1 2 3))

main.rkt> (extend (bag (list 1 2 3)) (list 4))
(bag '(4 1 2 3))

main.rkt> (conj* (bag (list 1 2 3)) 4)
; conj*: broke its own contract
;   promised: sequence?
;   produced: (bag '(4 1 2 3))
;   in: the range of
;       (->* (collection?) #:rest any/c sequence?)
;   contract from: 
;       <pkgs>/collections-lib/data/collection/collection.rkt
;   blaming: <pkgs>/collections-lib/data/collection/collection.rkt
;    (assuming the contract is correct)
;   at: <pkgs>/collections-lib/data/collection/collection.rkt:44.3
; Context:
;  .../private/blame.rkt:347:0 body of "/Users/siddhartha/work/lisp/racket/generator-util/main.rkt"
;  .../contract/combinator.rkt:324:9
;  .../private/arrow-val-first.rkt:486:18
;  .../racket/repl.rkt:11:26

main.rkt> (extend* (bag (list 1 2 3)) (list 4))
; extend*: broke its own contract
;   promised: sequence?
;   produced: (bag '(4 1 2 3))
;   in: the range of
;       (->*
;        (collection?)
;        #:rest
;        (listof sequence?)
;        sequence?)
;   contract from: 
;       <pkgs>/collections-lib/data/collection/collection.rkt
;   blaming: <pkgs>/collections-lib/data/collection/collection.rkt
;    (assuming the contract is correct)
;   at: <pkgs>/collections-lib/data/collection/collection.rkt:43.3
; Context:
;  .../private/blame.rkt:347:0 body of "/Users/siddhartha/work/lisp/racket/generator-util/main.rkt"
;  .../contract/combinator.rkt:324:9
;  .../private/arrow-val-first.rkt:486:18
;  .../racket/repl.rkt:11:26

Some APIs could encode more finiteness information in their results

Some APIs do not return known-finite results even when such an inference could reliably be made. These in particular:

rest
take
drop
filter
map
reverse

In the seq library, these APIs are overridden with ones that annotate the result with finiteness information based on whether the input is known-finite or not. I did this purely for expediency as I was fleshing out the interfaces in that library, but it's very likely that these changes would be better incorporated upstream in data/collection, since otherwise, in order to use these libraries together, you need to:

(require (except-in data/collection rest take drop ...)
         seq)

instead of just

(require data/collection seq)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.