I thought I had understood mostly everything I learned in Beautiful Racket. But I must be very confused as a whole. I gave myself the task of translating something like this
#lang tcp connect www.google.com 80 text GET / HTTP/1.1 text Host: www.google.com text read-until-eof exit into something like this #lang racket/base (require racket/tcp) (require racket/port) (define host "www.google.com") (define port 80) (define-values (input-port output-port) (tcp-connect host port)) (define (sendline ln) (display ln (current-output-port)) (display ln output-port) (flush-output output-port)) (displayln (format "Connected @ ~a on port ~a." host port)) (sendline "GET / HTTP/1.1\r\n") (sendline (format "Host: ~a\r\n\r\n" host)) (write (port->lines input-port)) (exit) I've achived a bit. I translated that dsl-source into this. '(prelude/connect-to www.google.com 80) '(send-line GET / HTTP/1.1) '(send-line Host: www.google.com) '(send-line) '(loop read until eof) '(exit) Now I don't know how to proceed. I think I must define a macro prelude/connect-to. For example (prelude/connect-to www.google.com 80) should expand to (begin (require racket/tcp) (require racket/port) (define-values (input-port output-port) (tcp-connect "www.google.com" 80)))) Here's what I tried. (See my full code at http://pasterack.org/pastes/16943 ) (define-macro (prelude/connect-to HOST PORT) #'(begin (require racket/tcp) (require racket/port) (define-values (input-port output-port) (tcp-connect HOST PORT)))) This doesn't work because I get the error message www.google.com: unbound identifier in module in: www.google.com This must be because www.google.com is not a string. I don't know how to turn into a string and this must mean I'm very confused. What should my macro do so I'd get the desired expansion? -- 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.