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

Wonky error when missing newlines between messages #59

Open
hashimmm opened this issue Apr 11, 2023 · 0 comments
Open

Wonky error when missing newlines between messages #59

hashimmm opened this issue Apr 11, 2023 · 0 comments

Comments

@hashimmm
Copy link

hashimmm commented Apr 11, 2023

I tried the "echo" challenge from the fly-io site. Good idea to have a simple echo things to sort out the basic setup.

So one program I tried was the following Racket code:

#lang racket/base

(require json)
(require racket/match)
(require racket/port)

(define (main)
  (for ([h (in-producer read-json eof)])
    (match h
      [(hash-table ('dest dest)
                   ('src src)
                   ('body body)
                   (k v) ...)
       (match body
         [(hash-table ('type "echo")
                      ('msg_id msg_id)
                      (bk bv))
          (write-json
           (hash
            'src dest
            'dest src
            'body (hash 'type "echo_ok"
                        'msg_id msg_id
                        'in_reply_to msg_id
                        bk bv)))]
         [(hash-table ('type "init")
                      ('msg_id msg_id)
                      (bk bv) ...)
          (write-json
           (hash 'src dest
                 'dest src
                 'body
                 (hash 'type "init_ok"
                       'in_reply_to msg_id)))]
         [_
          #f])]
      [_
       #f])
    (flush-output)))

(module+ main
  (main))

The above code results in the following error:

java.lang.AssertionError: Assert failed: Invalid dest for message #maelstrom.net.message.Message{:id 1, :src "n0", :dest "c0", :body {:in_reply_to 1, :type "init_ok"}}

I sorta guessed by reading the spec that making my code emit a newline after each message would follow the stated spec better and might just work. And it did! Simply adding (displayln "") before (flush-output) in the above code makes it work and pass the tests.

The way to run the above code is, assuming Racket 8.8 is installed, to generate an executable using raco exe echo.rkt, then running the resulting echo binary with maelstrom.

PS I don't feel too strongly about this thing and wouldn't mind if the issue is closed as unimportant

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

1 participant