Re: [racket-users] Sending a file via HTML request.
> On Aug 24, 2016, at 4:36 AM, Normal Loone wrote: > > Sorry, I should have been clearer: > > I want to send a file directly from DrRacket to a server. I have submit > button as a plugin in DrRacket and it then should take the file and send it > to the server (the file is known, doesnt need to be selected from user). > > I tried the code from HTH Stephen, but problem is that the web application > starts on DrRacket start and not when I press the button, how I wanted it. > > So if someone could tell me a way to just directly send a file with DrRacket > as an HTML request, I'd really appreciate that. Yes, this is a one-liner: #lang racket (require net/http-client) (http-sendrecv #"example.com" #"/" #:method "POST" #:data "MY FAVORITE BYTES”) This will send a POST request to example.com, with path /, and attach the bytes #”MY FAVORITE BYTES”. John Clements -- 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. signature.asc Description: PGP signature
Re: [racket-users] warnings for requiring opaque types in typed racket 6.6
On 08/24/2016 02:28 PM, Alex Knauth wrote: > That's the short-term solution. A better solution would be for typed racket > to implement a different version of #:opaque that would actually wrap the > values in opaque structs when they flow from untyped-to-typed and unwrap them > when they flow from typed-to-untyped. That way typed racket would know how to > protect the values. we will be eagerly awaiting such a change to typed racket, as unsafe requires are worrisome. If a lay-programmer could contribute do let me know, though I am not sure I know where to start. -- Matthew Eric Bassett | http://mebassett.info -- 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. signature.asc Description: OpenPGP digital signature
[racket-users] [ANN] A type-expander library for Typed/Racket
Based on Asumu's work on type expanders (https://github.com/racket/racket/compare/master...takikawa:tr-type-expander), I have written a library which adds support for type expanders in typed/racket. Type expanders are to types what match expanders are to match patterns. A type expander is a special macro which can appear wherever a type would normally be expected, and must expand to a type. The library is written using literate programming, with (a variant of) scribble/lp2. The annotated source code is available here: http://docs.racket-lang.org/type-expander.hl/ and the documentation here: http://docs.racket-lang.org/type-expander/ This library comes along with the multi-id library (http://docs.racket-lang.org/multi-id/, literate source: http://docs.racket-lang.org/multi-id.hl/), which allows easy definition of an identifier which acts as a type expander, match expander, normal macro and identifier macro. It can be used to define new datatypes, where a single identifier represents the type, match clause, literal instance as in (foo-datatype 1 2 3), and constructor function as in (map foo-datatype …). The type-expander library is in beta status: * It works well and I have been using it for a while without issues. * The API should not change significantly in the future. * However, there are many typed/racket primitives which are not overloaded yet, as noted in the documentation (patches are welcome). * Also, a couple of features are missing (patches are welcome again): * The special form `Let`, which acts like `let-syntax` for types, is only partially implemented. * The special form `(Λ (stx) . body)`, which acts as an anonymous type expander, is not implemented at all. * There is no syntax-local-type-introduce. Any feedback is appreciated! :) Regards, Georges Dupéron -- 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] Re: Sending a file via HTML request.
I posted to this thread yesterday through Gmane, but I see it hasn't yet appeared. Posting through Gmane has been flaky lately - I'm sending this updated version via email.Not sure what's happening with Gmane. Apologies if you see things multiple times. George On 8/24/2016 7:36 AM, Normal Loone wrote: Sorry, I should have been clearer: I want to send a file directly from DrRacket to a server. I have submit button as a plugin in DrRacket and it then should take the file and send it to the server (the file is known, doesnt need to be selected from user). I tried the code from HTH Stephen, but problem is that the web application starts on DrRacket start and not when I press the button, how I wanted it. So if someone could tell me a way to just directly send a file with DrRacket as an HTML request, I'd really appreciate that. On Tue, 23 Aug 2016 02:09:24 -0700 (PDT), Normal Loone wrote: >Yeah, my main problem is how do I pack the file into a JSON Object >and then send it? Just FYI: JSON is a printable coding, so any non-printable characters in a binary file must be escaped - making the transfer larger. The read-json and write-json functions take care of escaping, but if you are sending large files, the conversion overhead may be significant. Note that converting an arbitrary binary file to JSON is convoluted - JSON is meant to handle character strings, not bytes. You have to do something like: (string->jsexpr (bytes->string/utf-8 file-bytes)) which is a problem if the file is very large as the file data and converted string both need to be in memory. It's possible to send a file in pieces and reassemble it at the receiver, but that can get quite complicated. >With (require net/http-client) I could already establish a connection >with (http-conn-sendrecv! hc uri), but All I can send is the empty >header of the http request. > >How do I add the HTML code or the file in the json object within it? If the data is JSON encoded, you can send it as an HTTP string parameter: e.g., (require net/http-client net/uri-codec) (let [ (params (alist->form-urlencoded (list (cons 'file json-encoded-data )) ))) (headers (list "Content-Type: application/x-www-form-urlencoded") ) ] (let-values [ ((resp-code resp-hdrs port) (http-sendrecv host url #:method #"POST" #:data params #:headers headers )) ] (printf "~s~n~s~n~s~n" resp-code resp-hdrs (port->bytes port)) )) The print at the end is displaying the server's response. There is a limit - which I can't recall at the moment - to the size of simple upload forms, so you might have trouble sending a long file this way. Large uploads, binary data uploads, and piecemeal incremental uploads are meant to be done using multipart forms. Multipart forms are complex to encode: they have opening headers, boundary markers enclosing and sometimes interspersed with the data, and closing footers after the data. I don't have a ready example. For more information see http://www.rfc-base.org/rfc-1867.html Hope this helps, George -- 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] Re: Sending a file via HTML request.
Vishesh Yadav wrote a DrRacket plugin that automatically compiles a program to JS via whalesong and uploads it to a server. It sounds related to what you are describing so you may want to take a look at his code. The plugin code is here: https://github.com/vishesh/drracket-whalesong in particular these lines may be of interest: https://github.com/vishesh/drracket-whalesong/blob/master/tool.rkt#L62-L74 and the server code is here: https://github.com/vishesh/whalebin If you want to try it out, the server is running at bigbang.ccs.neu.edu (but seems to be experiencing temporary problems at the moment). On Wed, Aug 24, 2016 at 7:36 AM, Normal Loone wrote: > Sorry, I should have been clearer: > > I want to send a file directly from DrRacket to a server. I have submit > button as a plugin in DrRacket and it then should take the file and send it > to the server (the file is known, doesnt need to be selected from user). > > I tried the code from HTH Stephen, but problem is that the web application > starts on DrRacket start and not when I press the button, how I wanted it. > > So if someone could tell me a way to just directly send a file with DrRacket > as an HTML request, I'd really appreciate that. > > -- > 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] warnings for requiring opaque types in typed racket 6.6
> On Aug 24, 2016, at 9:12 AM, Matthew Eric Bassett wrote: > > thank you for your reply, Alex. That was informative and helpful. > > On 08/19/2016 02:56 PM, Alex Knauth wrote: >> So to work around that, you can use `define-new-subtype` along with >> `unsafe-require/typed`. >> >> #lang typed/racket >> (require typed/racket/unsafe) >> (define-new-subtype My-Type (make-my-type My-Type)) >> (unsafe-require/typed "untyped.rkt" [my-type? (-> Any Boolean : My-Type)] >> [my-type My-Type]) >> > > This is quite wonky and the warnings in the Typed Racket docs about > unsafe make me very wary about using such stuff in production. Can the > others confirm if this is indeed the desired behavior or something that > might be fixed in a later version? The warnings for `unsafe-required/typed` are definitely not the desired behavior, and there is currently a pull request to fix that: https://github.com/racket/typed-racket/pull/418 With this pull request, you would be able to use #lang typed/racket (require typed/racket/unsafe) (unsafe-require/typed "untyped.rkt" [#:opaque My-Type my-type?] [my-type My-Type]) (my-type? my-type) ; produces #t Without it producing that warning. However it's still not a very good solution because it still uses unsafe. That's the short-term solution. A better solution would be for typed racket to implement a different version of #:opaque that would actually wrap the values in opaque structs when they flow from untyped-to-typed and unwrap them when they flow from typed-to-untyped. That way typed racket would know how to protect the values. Alex Knauth -- 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] warnings for requiring opaque types in typed racket 6.6
thank you for your reply, Alex. That was informative and helpful. On 08/19/2016 02:56 PM, Alex Knauth wrote: > So to work around that, you can use `define-new-subtype` along with > `unsafe-require/typed`. > > #lang typed/racket > (require typed/racket/unsafe) > (define-new-subtype My-Type (make-my-type My-Type)) > (unsafe-require/typed "untyped.rkt" [my-type? (-> Any Boolean : My-Type)] > [my-type My-Type]) > This is quite wonky and the warnings in the Typed Racket docs about unsafe make me very wary about using such stuff in production. Can the others confirm if this is indeed the desired behavior or something that might be fixed in a later version? Regards, M.e. > > Alex Knauth > >> Hi all, >> >> I note that Racket 6.6 now issues warnings for certain generated >> contracts in typed/untyped interactions. In particular, these warnings >> come up when requiring an untyped file from a typed file. For example, >> say I have >> >> test.rkt: >> - >> #lang racket >> >> >> (define my-type >> (let () >> (struct my-type () ) >> (my-type))) >> (define (my-type? x) >> (eq? x my-type)) >> >> >> (provide my-type? my-type) >> >> And follow that with type interactions: >> >> $ racket -I typed/racket >> Welcome to Racket v6.6. >> -> (require/typed "test.rkt" [#:opaque My-Type my-type?] [my-type My-Type]) >> my-type?: contract violation >> any-wrap/c: Unable to protect opaque value passed as `Any` >> value: # >> This warning will become an error in a future release. >> in: the 1st argument of >> a part of the or/c of >> (or/c >> struct-predicate-procedure?/c >> (-> Any boolean?)) >> contract from: (interface for my-type?) >> blaming: top-level >> (assuming the contract is correct) >> at: readline-input:1.44 >> >> I use a similar pattern to call the untyped db library from typed code, >> say with >> (require/typed db [#:opaque Sql-Null] [sql-null Sql-Null]), which would >> bring up a similar warning. >> >> Is there a "correct" way to handle these sorts of cases? >> >> Thanks! >> >> Matthew Eric >> >> -- >> Matthew Eric Bassett | http://mebassett.info > > -- Matthew Eric Bassett | http://mebassett.info -- 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. signature.asc Description: OpenPGP digital signature
Re: [racket-users] Racket Shell
On Sat, Aug 20, 2016 at 4:17 PM, William G Hatch wrote: > I'm really interested in people's thoughts about both parts and ways people > think they could be improved. Hi, William. Have you looked at ESHELL to see if it has anything of interest? %(format-time-string "%D %H:%M:%S" (seconds-to-time 1471456370)) 08/17/16 14:52:50 % %for i in (list 'a 'b 'c) {echo $i} a b c % %for i in (list 'a 'b 'c) {echo x = $i} ("x" "=" a) ("x" "=" b) ("x" "=" c) % This echo is actually a Lisp function. %which echo eshell/echo is a compiled Lisp function in `em-basic.el' % %which *echo c:/emacs/git/usr/bin/echo.exe % To invoke the echo program, use an asterisk: %for i in (list 'a 'b 'c) {*echo x = $i} x = a x = b x = c % The manual: https://www.gnu.org/software/emacs/manual/html_node/eshell/index.html -- 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] Using the base language’s get-info function with make-meta-reader
> On Aug 24, 2016, at 2:05 AM, Alexis King wrote: > > When using make-meta-reader from syntax/module-reader, is it possible > to access the “base” language’s get-info function from within the > read or read-syntax wrapping functions? I’d like to adjust how a > particular meta language is read based on a property on the base > language. A month or so ago I started work on a version of make-meta-reader that would allow this, but I got caught up in the I-have-no-idea-what-it's-supposed-to-be-doing of it. Matthew Flatt answered the first question I had about what the second argument was, but then I had other things to do and I never finished it. If I have more time in the next 2 weeks I could look at it again... Alex Knauth > Currently, my guess is the answer is a fairly flat “no”, but I > figured I’d ask in case I was missing something. -- 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] Re: Sending a file via HTML request.
Sorry, I should have been clearer: I want to send a file directly from DrRacket to a server. I have submit button as a plugin in DrRacket and it then should take the file and send it to the server (the file is known, doesnt need to be selected from user). I tried the code from HTH Stephen, but problem is that the web application starts on DrRacket start and not when I press the button, how I wanted it. So if someone could tell me a way to just directly send a file with DrRacket as an HTML request, I'd really appreciate that. -- 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.