Hello,

I was trying to understand the imap module so I created the following
script called main.rkt inside a src/ folder.

The file looks like this:
#lang racket/base

(require racket/function
         net/imap)

(define (start-server user pass host port)
  (define-values (conn total new)
    (parameterize ([imap-port-number port])
      (imap-connect host user pass "INBOX" #:try-tls? #true)))

  (dynamic-wind
    (void)
    (thunk
     (let loop ()
       (imap-noop conn)
       (define unseen (imap-unseen conn))
       (printf "unseen: ~a~n" unseen)
       (loop)))
    (thunk
     (imap-disconnect conn))))

(module+ main

  (require racket/cmdline)

  (define hostname (make-parameter "localhost"))
  (define port (make-parameter "465"))
  (define password (make-parameter #f))

  (define username
    (command-line
     #:program "s10-tryout server"
     #:once-each
     [("-h" "--hostname") h
                          "Hostname (optional)"
                          (hostname h)]
     [("-p" "--port") p
                      "Port (optional)"
                      (port p)]
     [("--password") pass
                     "Password (optional)"
                     (password pass)]
     #:args (user)
     user))

  (unless (password)
    (password (read)))

  (start-server (username) (password) (hostname) (port)))


The most interesting thing about this is how it fails (surely due to
some error of mine), but without actually helping much even when called
with errortrace:

$ racket -l errortrace -t src/main.rkt
parse-command-line: expected argument of type <table as a list of
flag-list/procedure pairs (no pre-defined flags: "-h")>; given:
'((once-each (("-h" "--hostname")
#<procedure:...cket/cmdline.rkt:141:76> (("Hostname (optional)") "h"))
(("-p" "--port") #<procedure:...cket/cmdline.rkt:141:76> (("Port
(optional)") "p")) (("--password")
#<procedure:...cket/cmdline.rkt:141:76> (("Passw...
  errortrace...:
   /home/pmatos/installs/racket-6.12/collects/racket/cmdline.rkt:199:13:
(define username (command-line #:program "s10-tryout server" #:once-each
(("-h" ....) h ....) ((....) ....) (....) ....))
  context...:
   /home/pmatos/installs/racket-6.12/collects/racket/cmdline.rkt:266:10:
for-loop
   /home/pmatos/installs/racket-6.12/collects/racket/cmdline.rkt:257:4:
for-loop
   /home/pmatos/installs/racket-6.12/collects/racket/cmdline.rkt:251:2:
for-loop
   /home/pmatos/installs/racket-6.12/collects/racket/cmdline.rkt:229:0:
parse-command-line10
   (submod /home/pmatos/Projects/s10-tryout/src/main.rkt main): [running
body]


This is Racket 6.12. The error message complains about a
parse-command-line which I never called. Then the type in the message:
<table as a list of flag-list/procedure pairs (no pre-defined flags:
"-h")> is not very useful either if you do not understand the inner
working of parse-command-line.

The most surprising thing is that errortrace complains about:
/home/pmatos/installs/racket-6.12/collects/racket/cmdline.rkt:199:13:
(define username (command-line #:program "s10-tryout server" #:once-each
(("-h" ....) h ....) ((....) ....) (....) ....))

But the expression (define username...) is on line 30 of main.rkt, not
on line 199 of cmdline.rkt.

Should this be reported as a bug?

-- 
Paulo Matos

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to