Re: [racket-users] http-sendrecv with Google geocode
Hi Sean, On 4/21/2015 1:46 AM, Sean Kanaley wrote: Just comment out #:data and append it to the url: (http-sendrecv maps.googleapis.com http://maps.googleapis.com/ (string-append http://maps.googleapis.com/maps/api/geocode/json?; http://maps.googleapis.com/maps/api/geocode/json form-data) ;#:ssl? ssl? ;#:port port #:version #1.1 #:method #GET #:headers (list Content-Type: application/x-www-form-urlencoded) ;#:data form-data ;#:content-decode decodes )) Doesn't work - I get the same error back: blah, blah ... Your client has issued a malformed or illegal request. That’s all we know I've tried appending the data as you suggest. I've tried adding ? deliberately to the URI. I've tried with and without #:headers. #:version #1.0 and #1.1. #:method #GET vs #POST. Everything produces the same error. But perversely the result of (string-append http://maps.googleapis.com/maps/api/geocode/json?; http://maps.googleapis.com/maps/api/geocode/json form-data) works if I paste it into a browser. George On Mon, Apr 20, 2015 at 8:37 PM, George Neuner gneun...@comcast.net mailto:gneun...@comcast.net wrote: Hi all, I'm having trouble accessing the Google geocode API using http-sendrecv. Code is: (define (lookup address) (let [ (form-data (alist-form-urlencoded (list (cons 'address address) ))) (response #f) (lat #f) (long #f) ] (printf Looking up ~s~n address) (printf = ~s~n form-data) (with-handlers [ (exn:fail? (lambda (e) (fprintf (ferr) ~n~n%%~n~a~n%%~n (format Error: ~a (exn-message e))) )) ] (let-values [ ((errcode header port) (http-sendrecv maps.googleapis.com http://maps.googleapis.com http://maps.googleapis.com/maps/api/geocode/json; http://maps.googleapis.com/maps/api/geocode/json ;#:ssl? ssl? ;#:port port #:version #1.1 #:method #GET #:headers (list Content-Type: application/x-www-form-urlencoded) #:data form-data ;#:content-decode decodes )) ] (set! response (port-string port)) ;(set! response (read-json port)) (printf = ~s~n response) )) (fprintf (ferr) lat:~s long:~s~n lat long ) (values lat long) )) It doesn't yet extract relevant data because I haven't yet successfully gotten anydata. 8-( As a test Ilookup the State House in Boston: (lookup 24 Beacon St, Boston, MA, 01233) Looking up 24 Beacon St, Boston, MA, 01233 = address=24+Beacon+St%2C+Boston%2C+MA%2C+01233 = !DOCTYPE html\nhtml lang=en\n meta charset=utf-8\n meta name=viewport content=\initial-scale=1, minimum-scale=1, width=device-width\\n titleError 400 (Bad Request)!!1/title\n style\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* body{background:url(//www.google.com/images/errors/robot.png http://www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/errors/logo_sm_2.png http://www.google.com/images/errors/logo_sm_2.png) no-repeat}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png http://www.google.com/images/errors/logo_sm_2_hr.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/errors/logo_sm_2_hr.png http://www.google.com/images/errors/logo_sm_2_hr.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/errors/logo_sm_2_hr.png http://www.google.com/images/errors/logo_sm_2_hr.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:55px;width:150px}\n /style\n a
Re: [racket-users] Typed analog of integer-in contract
This works though: #lang typed/racket (require mzlib/etc) (define-type NDigit (U 0 1 2 3 4 5 6 7 8 9)) (define-type SDigit (U 'one 'two 'three 'four 'five 'six 'seven 'eight 'nine)) (: f (- NDigit SDigit)) (define (f i) (evcase i [(ann 0 0) (displayln i) 'two] [(ann 1 1) (displayln i) 'two] [(ann 2 2) (displayln i) 'two] [(ann 3 3) (displayln i) 'two] [else 'one])) This is because the original version didn't annotate the numeric literals, which typecheck as Positive-Byte (except for 0 and 1 which are special). Using = here won't work because the typechecking rule that considers filters for equality doesn't work for =. The comment in the code says ;; `=' is not included. Its type is more useful than this typing rule. Could we get the benefits of both approaches somehow? Cheers, Asumu -- 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.
[racket-users] convert to/from Sribble
Hello, after becoming interested to learn Racket to be used as general-purpose language, I'm considering to use Scribble/Polen for my writing/web projects. However, I'm a bit concerned not finding any converted which could be used to conver markup from/to Scribble which means that using it provides some kind of (vendor) lock-in? Is it true there are no converters available (there is none for Pandoc)? Sincerely, Gour -- Before giving up this present body, if one is able to tolerate the urges of the material senses and check the force of desire and anger, he is well situated and is happy in this world. -- 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.
[racket-users] exploring sribble @ ... seems this should work but doesn't ..
Tyring to use '@' to run a command on a string, fails: racket@ (displayln hello) hello racket@ (require scribble/base) racket@ @displayln{hello} @displayln: undefined; cannot reference undefined identifier context...: /usr/share/racket/collects/racket/private/misc.rkt:87:7 racket@ hello: undefined; cannot reference undefined identifier context...: /usr/share/racket/collects/racket/private/misc.rkt:87:7 Trying to load just the at expression: racket@ (require at-exp) get-module-code: no such file: #path:/usr/share/racket/pkgs/at-exp-lib/at-exp/main.rkt context...: /usr/share/racket/collects/syntax/modcode.rkt:109:0: get-module-path51 /usr/share/racket/collects/syntax/modcode.rkt:212:0: get-module-code79 standard-module-name-resolver /usr/share/racket/collects/racket/private/misc.rkt:87:7 racket@ -- 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.
Re: [racket-users] Typed analog of integer-in contract
#lang typed/racket (define-type NDigit (U 0 1 2 3 4 5 6 7 8 9)) (define-type SDigit (U 'zero 'one 'two 'three 'four 'five 'six 'seven 'eight 'nine)) (: to-string (- NDigit SDigit)) (define (to-string i) (case i [(0) (displayln i) 'zero] [(1) (displayln i) 'zero] [(2) (displayln i) 'zero] [(3) (displayln i) 'zero] [(4) (displayln i) 'zero] [(5) (displayln i) 'zero] [(6) (displayln i) 'zero] [(7) (displayln i) 'zero] [(8) (displayln i) 'zero] [(9) (displayln i) 'zero] ;; can't get here [else (displayln (+ i i)) 'one])) I wish mousing over i would give me more precise types here. Occurrence typing subtracts 2 ... from i's type but somehow it doesn't work thru case. On Apr 20, 2015, at 9:09 PM, Benjamin Greenman wrote: The contract integer-in lets me guarantee an integer is within a certain range. (define/contract (mod3 n) (- integer? (integer-in 0 2)) (modulo n 3)) Is there a similar way to specify a type for an integer range? Or do I need to use a union type? (I'd really like to specify a range containing over a million integers.) -- 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. -- 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.
Re: [racket-users] http-sendrecv with Google geocode
Hi Sean, Even weirder when I tried this morning your string-append solution - which I had left in place - worked immediately with no changes from last night. The only thing different is I had closed DrRacket before going to bed and reopened it this morning. Maybe something was wonky in DrRacket? It had been running about ~14 hours yesterday at the point I started having trouble and I fought with it a couple more hours before quitting? But AFAICR, I've never seen that before. However, as you discovered also, passing the data as #:data doesn't work and now I'm interested in why. ISTM that the URI + #:data should be identical to the string-append with ? and #:method #GET. Also, Google recommends using POST if the data is sensitive, but I can't get POST to work even from a pure HTML form in a browser. So now I'm really curious as to what's going on. Thanks for your help, George On 4/21/2015 3:39 AM, Sean Kanaley wrote: Hi George, I'm not sure then -- I am in Racket 6.1.1. Here is the source that worked for me: #lang racket (require net/http-client net/uri-codec) (define (lookup address) (let [ (form-data (alist-form-urlencoded (list (cons 'address address) ))) (response #f) (lat #f) (long #f) ] (printf Looking up ~s~n address) (printf = ~s~n form-data) (with-handlers [ (exn:fail? (lambda (e) 3; (fprintf (ferr) ~n~n%%~n~a~n%%~n (format Error: ~a (exn-message e))) )) ] (let-values [ ((errcode header port) (http-sendrecv maps.googleapis.com http://maps.googleapis.com (string-append http://maps.googleapis.com/maps/api/geocode/json?; form-data) ;#:ssl? ssl? ;#:port port #:version #1.1 #:method #GET #:headers (list Content-Type: application/x-www-form-urlencoded) ;#:data form-data ;#:content-decode decodes )) ] (set! response (port-string port)) ;(set! response (read-json port)) (printf = ~s~n response) )) ;(fprintf (ferr) lat:~s long:~s~n lat long ) (values lat long) )) (I commented out the fprintfs to avoid dealing with ferr.) It won't work if #:data is uncommented. I hope that helps, otherwise I'm stuck too. -- 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.
Re: [racket-users] convert to/from Sribble
Gour wrote on 04/21/2015 06:50 AM: Another way to get to lots of different formats from Scribble would be to make Scribble generate more-plain HTML5 (i.e., less tag-heavy than in its normal HTML output, throwing away a lot of the info), and then use that as a source format for other converters. Is there any plan to officially adopt such a thing? Good question. Maybe someone on the list can answer. (If you had to do it yourself, even just copying and modifying the existing HTML-generating code would work. Or writing a post-processor using the html-parsing and html-writing packages. But maybe there's a better way.) Neil V. -- 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.
[racket-users] scribble confusion ...
Manual says: remember that the Scribble is just an alternate for S-expressions Please pardon the question .. ah then what good is it? We already have S-expressions. Perhaps it looks a lot nicer? .. but if that works for scribble, do we need one of these looks nicer rewrites for the rest of scheme? :-) More confusion .. this example: racket@ (title On the Cookie-Eating Habits of Mice) If you give a mouse a cookie, he's going to ask for a glass of milk. Ok, so I should read @title{On ...} as (title On ...), but what is the If you give a mouse a cookie .. part? It isn't inside of any function. It crashes big if one gives it to the REPL. In lang scribble it must be that the whole file is a big textbody ? Then there must be a function I can use to get this same effect? @eatfile{ whole file contents here } (title-decl #f '((part On_the_Cookie-Eating_Habits_of_Mice)) #f (style #f '()) '(On the Cookie-Eating Habits of Mice)) racket@ If: undefined; cannot reference undefined identifier context...: /usr/share/racket/collects/racket/private/misc.rkt:87:7 racket@ you: undefined; cannot reference undefined identifier context...: /usr/share/racket/collects/racket/private/misc.rkt:87:7 ... -- 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.
Re: [racket-users] reading writing the preamble of an XML file
Yes, I packaged the logic described by Jay into some utility functions in my sugar/xml module to make it easier to read write an XML file with its prolog: http://pkg-build.racket-lang.org/doc/sugar/#%28part._.X.M.L%29 On Tue, Apr 21, 2015 at 7:25 AM, Nadeem Abdul Hamid nad...@acm.org wrote: Was there ever a resolution to this question? On Mon, Mar 30, 2015 at 2:12 PM, Matthew Butterick m...@mbtype.com wrote: I understand that the preamble of an XML file (e.g., a first line like ?xml version=1.0 encoding=utf-8?) is not part of the X-expression representing that file. That's why in `response/xexpr`, there's an option for adding a preamble. [1] But with static XML files, I'm unclear about how preambles are supposed to be handled. Use case: reading an XML file, modifying it, writing it back out with the same preamble. Reading: is the preamble just discarded? Am I supposed to grab it with [small shiver] a regular expression? ;;; #lang racket/base (require xml) (define x (string-xexpr ?xml version=\1.0\ encoding=\utf-8\?roothello world/root)) x '(root () hello world) ;;; Writing: functions like `xexpr-xml` and `xexpr-string` of course take an Xexpr without a preamble. Again, is the intention that it be added manually (e.g. with `string-append`)? [1] http://docs.racket-lang.org/web-server/http.html?q=response%2Fxexpr#%28def._%28%28lib._web-server%2Fhttp%2Fxexpr..rkt%29._response%2Fxexpr%29%29 -- 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. -- 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.
Re: [racket-users] convert to/from Sribble
We'd love to have an additional renderer for Scribble. On Apr 21, 2015, at 7:05 AM, Neil Van Dyke n...@neilvandyke.org wrote: Gour wrote on 04/21/2015 06:50 AM: Another way to get to lots of different formats from Scribble would be to make Scribble generate more-plain HTML5 (i.e., less tag-heavy than in its normal HTML output, throwing away a lot of the info), and then use that as a source format for other converters. Is there any plan to officially adopt such a thing? Good question. Maybe someone on the list can answer. (If you had to do it yourself, even just copying and modifying the existing HTML-generating code would work. Or writing a post-processor using the html-parsing and html-writing packages. But maybe there's a better way.) Neil V. -- 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. -- 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.
Re: [racket-users] Typed analog of integer-in contract
You could use a union type, but I’m not sure if a large union type would work well in terms of performance? I don't think this will work. This takes a long time to run (although I'm not sure how much of this is the macro expansion). Anyway, if it takes this long on a union type with 1 things in it, I highly doubt it can support a union type with over a million. #lang typed/racket (require (for-syntax syntax/parse racket/list)) (define-syntax (define-range stx) (syntax-parse stx [(_ name range-low range-hi) #`(define-type name (U #,@(range (syntax-e #'range-low) (syntax-e #'range-hi])) (define-range hello 0 1) ~Leif Andersen On Tue, Apr 21, 2015 at 10:41 AM, Matthias Felleisen matth...@ccs.neu.edu wrote: #lang typed/racket (define-type NDigit (U 0 1 2 3 4 5 6 7 8 9)) (define-type SDigit (U 'zero 'one 'two 'three 'four 'five 'six 'seven 'eight 'nine)) (: to-string (- NDigit SDigit)) (define (to-string i) (case i [(0) (displayln i) 'zero] [(1) (displayln i) 'zero] [(2) (displayln i) 'zero] [(3) (displayln i) 'zero] [(4) (displayln i) 'zero] [(5) (displayln i) 'zero] [(6) (displayln i) 'zero] [(7) (displayln i) 'zero] [(8) (displayln i) 'zero] [(9) (displayln i) 'zero] ;; can't get here [else (displayln (+ i i)) 'one])) I wish mousing over i would give me more precise types here. Occurrence typing subtracts 2 ... from i's type but somehow it doesn't work thru case. On Apr 20, 2015, at 9:09 PM, Benjamin Greenman wrote: The contract integer-in lets me guarantee an integer is within a certain range. (define/contract (mod3 n) (- integer? (integer-in 0 2)) (modulo n 3)) Is there a similar way to specify a type for an integer range? Or do I need to use a union type? (I'd really like to specify a range containing over a million integers.) -- 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. -- 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. -- 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.