Introduce a gen:hash alternative for mappings
- Dominant language
- Racket
- Stars
- 34
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
Would it be worth adding an alternative to the `gen:hash`, `gen:hasheq`, and `gen:hasheqv` forms that doesn't require hardcoding the keys?
Motivation: One alternative use of a hashtable involves mapping from arbitrary keys to values. However, the current `gen:hash` implementation expects the hardcoding of keys, such that the generated hashtables all have the same keys. This current implementation is useful for generating hashtables that represent jsexprs of some constant structure but is quite limiting for the other use/purpose.
An example of this alternative use would be a mapping of string IDs to naturals (maybe representing a score of some type). However, generating something like this is cumbersome (lifting+modifying this from the examples):
```lisp
(define gen:mapping
(gen:let ([keys&vals (gen:list (gen:tuple (gen:string gen:char-alphanumeric) gen:natural) #:max-length 5)])
(make-immutable-hasheq keys&vals)))
```
Introducing such a generator for the mappings, however, would make it considerably more concise (assume `gen:hash*` represents that generator):
```lisp
(define gen:mapping (gen:hash* (gen:string gen:char-alphanumeric) gen:natural))
```
Could this just be implemented by the users? Yes, but currently my stance is that the library itself should support this.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.