Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"hasheqof" is mentioned in the docs but doesn't seem to exist #1725

Closed
ghost opened this issue Jun 18, 2017 · 5 comments
Closed

"hasheqof" is mentioned in the docs but doesn't seem to exist #1725

ghost opened this issue Jun 18, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Jun 18, 2017

A function "hasheqof" is described in racket/pkgs/racket-doc/json/json.scrbl, but doesn't seem to be defined anywhere in the repo.

I wanted it to write a validator for some JSON data, so here's what I came up with.

(define (hasheqof k? v?) 
  (λ (h)
    (for/and ([(k v) h]) 
       (and (k? k) (v? v)))))
@bennn
Copy link
Contributor

bennn commented Jun 18, 2017

Can you use jsexpr? for your validator?

@ghost
Copy link
Author

ghost commented Jun 18, 2017

No can do. I was checking to see if something was a 'terminal' JSON object, ie (hasheqof symbol? string?).

I think it has more applications than just the json module anyway.

@bennn
Copy link
Contributor

bennn commented Jun 19, 2017

How about using the hash/c contract?

> (define (hasheqof k v) (and/c hash-eq? (hash/c k v #:flat? #t)))
> ((hasheqof symbol? string?) (hasheq 'a "a" 'b "b"))
#t

@ghost
Copy link
Author

ghost commented Jun 19, 2017

That's a better implementation, sure.

But the core problem is that the docs mention a contract that doesn't exist. Shouldn't it exist?

@samth
Copy link
Sponsor Member

samth commented Jun 19, 2017

That, or the docs should be fixed.

stamourv added a commit that referenced this issue Jul 10, 2017
Closes #1725

(cherry picked from commit 0f5e95e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants