Hello everyone,

I am working on this project: https://gitlab.com/HiPhish/MsgPack.rkt/

I am writing test cases and I ran into a problem with my ‘ext’ structure. It is 
declared in the file ‘msgpack/main.rkt’, which is required in the file 
‘msgpack/pack.rkt’ (also in ‘msgpack/unpack.rkt’). For my test case the test 
file looks like this:

        (require
          quickcheck
          rackunit/quickcheck
          (file "../../msgpack/main.rkt")
          (file "../../msgpack/pack.rkt"))
        
        (check-property
          (property ()
            (let ([obj (ext #x01 (bytes #x02))])
              (bytes=? (call-with-output-bytes (λ (out) (pack obj out)))
                       (bytes-append (bytes #xD4 (ext-type obj))
                                     (ext-data obj))))))

Here is what happens from my understanding: when I required ‘main.rkt’ the 
structure declaration got evaluated, creating all the functions that go along 
with it, including ‘ext’ and ‘ext?’. Then when I required the ‘pack.rkt’ file 
those declarations got evaluated again and created a new set of ext-related 
functions that just happen to have the same name. This is why I  the object I’m 
trying to pack falls through all the ‘cont’ cases.

This isn’t limited to the test file, I also tried the following on the REPL 
with the same results:

        Welcome to Racket v6.9.
        > (require msgpack msgpack/pack)
        > (define e (ext 1 (bytes 2 3)))
        > (define out (open-output-bytes))
        > (pack e out)
        ; Type not supported by MessagePack [,bt for context]
        > (pack-ext e out)
        ; pack-ext: contract violation
        ;   expected: ext?
        ;   given: #<ext>
        ;   in: the 1st argument of
        ;       (->
        ;        ext?
        ;        (and/c output-port? (not/c port-closed?))
        ;        any)
        ;   contract from:
        ;       <pkgs>/msgpack-rkt/msgpack/pack.rkt
        ;   blaming: top-level
        ;    (assuming the contract is correct)
        ;   at: <pkgs>/msgpack-rkt/msgpack/pack.rkt:53.5
        ; [,bt for context]
        > ,bt
        ; pack-ext: contract violation
        ;   expected: ext?
        ;   given: #<ext>
        ;   in: the 1st argument of
        ;       (->
        ;        ext?
        ;        (and/c output-port? (not/c port-closed?))
        ;        any)
        ;   contract from:
        ;       <pkgs>/msgpack-rkt/msgpack/pack.rkt
        ;   blaming: top-level
        ;    (assuming the contract is correct)
        ;   at: <pkgs>/msgpack-rkt/msgpack/pack.rkt:53.5
        ;   context...:
        ;    
/usr/local/Cellar/minimal-racket/6.9/share/racket/collects/racket/contract/private/blame.rkt:159:0:
 raise-blame-error16
        ;    
/usr/local/Cellar/minimal-racket/6.9/share/racket/collects/racket/contract/private/arrow-val-first.rkt:357:18
        ;    
/usr/local/Cellar/minimal-racket/6.9/share/racket/pkgs/xrepl-lib/xrepl/xrepl.rkt:1448:0
        ;    
/usr/local/Cellar/minimal-racket/6.9/share/racket/collects/racket/private/misc.rkt:88:7
        >

Adding a ‘#:prefab’ to the end of the struct declaration does not solve the 
problem. What am I doing wrong? Both the packing and unpacking need the ‘ext’ 
type for conformance with MessagePack. Do I have to make a large umbrella 
module that provides the entire API? I would prefer is users could just 
‘require’ parts of the library as they need them (i.e. only ‘(require 
msgpack/pack)’ if you only want to unpack data).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to