Comments (5)
The problem seems to be in the signature of the ref
generic:
(ref indexable . _)
This notation means that the implementation of ref
must have one fixed argument and one rest argument, so this amended example does work (note . i
rather than i
):
#lang racket
(require data/collection)
(struct wrapped-collection (value)
#:methods gen:indexable
[(define (ref c . i) 42)])
(ref (wrapped-collection 'foo) 'bar) ; 42
However, given that you define ref
strictly as a two-ary function, this seems like an error, and that the generic definer should be:
(ref indexable idx)
(set-ref indexable idx val)
from racket-collections.
Curious; it looks like those contracts are not enforced in the #:defaults
block. The motivation for this in the first place was a desire to support hash-ref
/dict-ref
’s failure-thunk
arguments, but it looks like that was a bad idea. It seems like the right thing to do here is to change the generic signature to (ref indexable index)
.
from racket-collections.
The define-generics
docs don’t mention it, but I accidentally discovered how to notate optional arguments in the generic signature:
(ref indexable idx [failure-thunk])
from racket-collections.
Doing such a thing requires all implementations to support a failure thunk; my original intention was to make such support optional but allowed. Of course, this means you could not depend on an arbitrary indexable supporting a failure thunk, so you could not write indexable-generic functions that use it, but you could use the short name if you knew it was used monomorphically.
In retrospect, that’s probably not a great idea. The question just becomes whether or not all indexables should support a failure thunk or if that ought to be optional. It could theoretically be supported in a separate interface with a different name, like gen:indexable/failure
and ref/failure
. Do you have a strong opinion either way?
from racket-collections.
my original intention was to make such support optional but allowed
I’m a generics noob. I have no opinion. Just observing that the docs are incomplete. So maybe what you originally intended is possible (by some other notational means).
from racket-collections.
Related Issues (19)
- raco pkg install error "conjoin: unbound identifier" HOT 3
- Optional strictness? HOT 5
- Generic apply doesn’t properly warn about mutability in contract violations HOT 1
- No license file
- `has-key?` function for `indexable` interface HOT 1
- The example for chunk* in the document failed HOT 2
- `take` and `drop` have their arguments in reverse order from traditional HOT 5
- Request: mutation on collections HOT 4
- set-nth* guarantees HOT 2
- Every n-th element in a sequence HOT 2
- Adding update-ref functions? HOT 1
- Improve documentation of gen:indexable
- Bug: conj* and extend* for collections that aren't sequences
- Should depend on `static-rename-lib` instead of `static-rename`
- Range does not return a known finite sequence
- Some APIs could encode more finiteness information in their results
- Take and drop aren't lazy for finite sequences
- Better default print representation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from racket-collections.