Re: [racket-users] Using Greek Letters
Oh I got it, it should be " \theta " and then " Alt + \ ". Thank you sirs. 2018-04-18 17:22 GMT-03:00 Robby Findler: > On a Mac, it is control-\. On other platforms it is something else. Check > in edit|show active keybindings. Search for "Tex". > > Robby > > On Wed, Apr 18, 2018 at 3:19 PM wrote: > >> Hey Philip, thanks. >> >> I don't get it yet, I type " \theta " and then when I type " Ctrl + \ " I >> get a Lamba symbol: " λ " ending with " \thetaλ " and nothing happens. >> >> I really would like to be able to type it instead of copying pasting, >> cause you know. >> >> >> >> Em quarta-feira, 18 de abril de 2018 15:52:50 UTC-3, Philip McGrath >> escreveu: >> >>> (Forgot to reply all …) >>> >>> Assuming what you are referring to is the "LaTeX and TeX inspired >>> keybindings" for DrRacket (https://docs.racket-lang.org/ >>> drracket/Keyboard_Shortcuts.html#%28part._.La.Te.X_and_. >>> Te.X_inspired_keybindings%29), you can insert the character "θ" by >>> typing "\theta", then, with the insertion point positioned at the end of >>> the "\theta", holding down the control key while pressing the \ key. >>> >>> Note that this is not the only way to enter characters like "θ" into >>> DrRacket: you can also copy and paste text containing theta, use a keyboard >>> mapping at the operating-system level that supports Greek letters, or use >>> the "Emoji & Symbols" viewer on Mac OS, among other methods. >>> >>> Once you are able to enter θ, you can define it as the name for some >>> value in the same way as any other identifier, e.g.: >>> >>> #lang racket >>> >>> (define θ >>> "Hi") >>> >>> (string-append θ ", world!") >>> >>> >>> -Philip >>> >>> On Wed, Apr 18, 2018 at 1:23 PM, wrote: >>> >> I saw the oficial Racket list of all the LaTeX thing and made some research, but I don't get it. Can someone please explain me how to digite the greek letter Theta for example? And how to use it as the mathematical Theta function if that's possible? Thank you a lot in advance! -- 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...@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.
Re: [racket-users] Using Greek Letters
On a Mac, it is control-\. On other platforms it is something else. Check in edit|show active keybindings. Search for "Tex". Robby On Wed, Apr 18, 2018 at 3:19 PMwrote: > Hey Philip, thanks. > > I don't get it yet, I type " \theta " and then when I type " Ctrl + \ " I > get a Lamba symbol: " λ " ending with " \thetaλ " and nothing happens. > > I really would like to be able to type it instead of copying pasting, > cause you know. > > > > Em quarta-feira, 18 de abril de 2018 15:52:50 UTC-3, Philip McGrath > escreveu: > >> (Forgot to reply all …) >> >> Assuming what you are referring to is the "LaTeX and TeX inspired >> keybindings" for DrRacket ( >> https://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html#%28part._.La.Te.X_and_.Te.X_inspired_keybindings%29), >> you can insert the character "θ" by typing "\theta", then, with the >> insertion point positioned at the end of the "\theta", holding down the >> control key while pressing the \ key. >> >> Note that this is not the only way to enter characters like "θ" into >> DrRacket: you can also copy and paste text containing theta, use a keyboard >> mapping at the operating-system level that supports Greek letters, or use >> the "Emoji & Symbols" viewer on Mac OS, among other methods. >> >> Once you are able to enter θ, you can define it as the name for some >> value in the same way as any other identifier, e.g.: >> >> #lang racket >> >> (define θ >> "Hi") >> >> (string-append θ ", world!") >> >> >> -Philip >> >> On Wed, Apr 18, 2018 at 1:23 PM, wrote: >> > I saw the oficial Racket list of all the LaTeX thing and made some >>> research, but I don't get it. >>> >>> Can someone please explain me how to digite the greek letter Theta for >>> example? And how to use it as the mathematical Theta function if that's >>> possible? >>> >>> Thank you a lot in advance! >>> >>> >>> -- >>> 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...@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.
Re: [racket-users] Using Greek Letters
Hey Philip, thanks. I don't get it yet, I type " \theta " and then when I type " Ctrl + \ " I get a Lamba symbol: " λ " ending with " \thetaλ " and nothing happens. I really would like to be able to type it instead of copying pasting, cause you know. Em quarta-feira, 18 de abril de 2018 15:52:50 UTC-3, Philip McGrath escreveu: > > (Forgot to reply all …) > > Assuming what you are referring to is the "LaTeX and TeX inspired > keybindings" for DrRacket ( > https://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html#%28part._.La.Te.X_and_.Te.X_inspired_keybindings%29), > > you can insert the character "θ" by typing "\theta", then, with the > insertion point positioned at the end of the "\theta", holding down the > control key while pressing the \ key. > > Note that this is not the only way to enter characters like "θ" into > DrRacket: you can also copy and paste text containing theta, use a keyboard > mapping at the operating-system level that supports Greek letters, or use > the "Emoji & Symbols" viewer on Mac OS, among other methods. > > Once you are able to enter θ, you can define it as the name for some value > in the same way as any other identifier, e.g.: > > #lang racket > > (define θ > "Hi") > > (string-append θ ", world!") > > > -Philip > > On Wed, Apr 18, 2018 at 1:23 PM,wrote: > >> I saw the oficial Racket list of all the LaTeX thing and made some >> research, but I don't get it. >> >> Can someone please explain me how to digite the greek letter Theta for >> example? And how to use it as the mathematical Theta function if that's >> possible? >> >> Thank you a lot in advance! >> >> >> -- >> 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...@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.
[racket-users] Re: Refinement Type, Type Check Error
Hi Ray, Thanks for the report and insight into refinement type usage "in the wild"! =) It looks like this particular program type checks if you add `#:with-refinements` to the #lang line at the top of the file. i.e., make the first line `#:lang typed/racket #:with-refinements` I would recommend adding that line any time your using refinement types -- it makes the type checker work a little harder and be better prepared to reason about refinement type usages. Even though that fixes the error, the message it was printing was still pretty bizarre, so I've opened a GitHub issue (https://github.com/racket/typed-racket/issues/696) and will find some time to look into it. Feel free to log as many issues there as you see fit while trying to make use of refinement types! =) Best, Andrew -- 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 Greek Letters
(Forgot to reply all …) Assuming what you are referring to is the "LaTeX and TeX inspired keybindings" for DrRacket (https://docs.racket-lang.org/ drracket/Keyboard_Shortcuts.html#%28part._.La.Te.X_and_. Te.X_inspired_keybindings%29), you can insert the character "θ" by typing "\theta", then, with the insertion point positioned at the end of the "\theta", holding down the control key while pressing the \ key. Note that this is not the only way to enter characters like "θ" into DrRacket: you can also copy and paste text containing theta, use a keyboard mapping at the operating-system level that supports Greek letters, or use the "Emoji & Symbols" viewer on Mac OS, among other methods. Once you are able to enter θ, you can define it as the name for some value in the same way as any other identifier, e.g.: #lang racket (define θ "Hi") (string-append θ ", world!") -Philip On Wed, Apr 18, 2018 at 1:23 PM,wrote: > I saw the oficial Racket list of all the LaTeX thing and made some > research, but I don't get it. > > Can someone please explain me how to digite the greek letter Theta for > example? And how to use it as the mathematical Theta function if that's > possible? > > Thank you a lot in advance! > > > -- > 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.
[racket-users] On Richard P. Gabriel’s “The Structure of a Programming Language Revolution”
Hello all, I have a rather different sort of question to ask about from my usual fare. A month or two ago, I read an essay written by Richard P. Gabriel and published at Onward! 2012 called “The Structure of a Programming Language Revolution”. The essay itself is available here to those interested in reading it: http://dreamsongs.com/Files/Incommensurability.pdf The essay covers a number of things, from CLOS and Smalltalk to the concept of incommensurability, but one of the things I found most intriguing was this thesis: > The real paradigm shift? Systems versus languages. Before 1990, a > person interested in programming could work comfortably both in > programming languages and in programming systems, but not so easily > after. To tell the truth, I never even noticed the different words — > language versus system — never attached any significance to the word > choice until this exploration. I used the phrases interchangeably for > many years: Programming System / Programming Language. Gabriel goes onto elaborate on the difference between so-called “systems thinking” and “language thinking”. From his perspective, Common Lisp sits squarely in the “systems” camp, and Scheme in the “language” camp. He makes the claim that the amount of effort Common Lisp dedicates to things like redefinition to support a running system are the effect of systems thinking, which has more or less fallen out of favor in the academic community in recent decades. This got me thinking about Racket, since much of Racket sits firmly in the language thinking camp. Racket focuses on the language being a single source of truth, on soundness, on syntactic properties and formal semantics. It discourages things like long-running systems and dynamic reflection. On the other hand, Racket is clearly made up of many systems in addition to its many languages: the macro system, the chaperone/impersonator system, and the namespace system all come to mind. (On the other hand, perhaps the line is much blurrier than Gabriel would have one believe: do contracts really belong cleanly to either philosophy?) Since then, I’ve wondered what thoughts other Racketeers would have in response to Gabriel’s essay. The ability to have a live, dynamic system akin to Common Lisp’s images is a useful feature, but it certainly requires “systems thinking”, and it is unsatisfying from a “language thinking” point of view. To pose a question to those who have been doing this longer than me, do you think this proposed philosophical binary really makes sense? Does Racket really fit in more closely with one or the other? Philosophically, does Racket reject things like CLOS and redefinition/long-running images just because they don’t work in the edge cases, or is there some bigger picture here that I’m not seeing? Thanks in advance for your thoughts, Alexis -- 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] Using Greek Letters
I saw the oficial Racket list of all the LaTeX thing and made some research, but I don't get it. Can someone please explain me how to digite the greek letter Theta for example? And how to use it as the mathematical Theta function if that's possible? Thank you a lot in advance! -- 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] Refinement Type, Type Check Error
I'm receiving a type check error when I use a moderately complex predicate, in a Refinement type, where in the same use case a simple predicate works fine. I think it might be a bug. The gist has a working example, followed by the error example. https://gist.github.com/RayRacine/c68d85b1a9353630097ac7c917eed74c FWIW, the example is from some Bluetooth (LE) stack code for a home IOT project. Turn on/off lights, stuff like that. The low level Bluetooth HCI communication protocol is rife with these kinds of constrained msg parameters. I left the example reflecting the "problem domain" in case there is some interest in who/how is applying TR's Refinement types in real life. Hopefully, it is not too verbose over a minimal error example. Also interested in hearing if this is an appropriate use of Refinement types. As Refinement types are still considered "Experimental" I certainly expected to hit some snags, but overall super impressive. Feedback-wise, TR has picked up some coding bugs at compile time that at best would have been picked up at runtime and most likely from errors during the back and forth Bluetooth HCI messages between Host and Controller. Which is a real pain detect, debug and fix. So kudos Refine. Also I know the Dependent type stuff is still underway, and not sure how Cut, but adding Dependent Type support for Bytes as well as Vector would be nice. -- 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] announcement: racket-peg release 0.2
On 2018-04-14 16:57, David Storrs wrote: Sounds interesting. Is there any documentation on it aside from the README? Yes, It's documented here http://docs.racket-lang.org/peg/index.html and the examples in the repo should be a good resource for using the library too. Don't hesitate to make a github issue if there is anything lacking! -- 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] Is it possible to pass syntax information from bottom up?
Matthias, Thank you for the reference. It turns out that I should have looked into local-expand rather than expand-syntax. Out of the two options (inserting type info into syntax or keeping it in the syntax-property) I chose the latter, because I like thinking of them as properties rather than syntax. Stephen, thank you. I actually wrote a similar program myself before I received yours. It is similar. I put it here for the record. One difference is that it uses syntax-track-origin to handle nested (this). #lang racket/base (require racket/format (for-syntax syntax/parse) (for-syntax racket/base)) (define-syntax (print stx) (syntax-parse stx (((~literal print) expr) (with-syntax ((expanded (local-expand #'expr 'expression '( (case (syntax-property #'expanded 'number-type) ((float) (syntax/loc stx (displayln (~r expanded #:notation 'positional #:precision '(= 2) ((integer) (syntax/loc stx (printf "~a\n" expanded (define-syntax (this stx) (syntax-parse stx (((~literal this) (expr ...)) (with-syntax ((expanded (local-expand #'(expr ...) 'expression '( (syntax-track-origin (syntax/loc stx expanded) (car (syntax-e #'(expr ...))) #'this))) (((~literal this) datum) (if (exact? (syntax->datum #'datum)) (begin (printf "we know at compile time that it is an integer\n") (syntax-property (syntax/loc stx datum) 'number-type 'integer)) (begin (printf "we know at compile time that it is a float\n") (syntax-property (syntax/loc stx datum) 'number-type 'float)) (print (this (this (this 123 (print (this (this (this 456.0 Regards, Dmitry On 18.04.2018 16:39, Matthias Felleisen wrote: You want to look at Stephen's Turnstile, a DSL for making typed DSLs and macros. Like all type systems, this is exactly what it does. Here is the link to the paper: https://www2.ccs.neu.edu/racket/pubs/#popl17-ckg It obscures what you need, which is a combination of local-expand, syntax-parse and its various hooks. The rough idea is to locally expand a given phrase and to expand in such a way that macros return two pieces of information: the expanded syntax and the additional property. You can try to encode this with #'(begin expanded-code property) or just use a syntax-property, whatever fits best. When the local-expand returns, take apart the macro and re-do the same thing. Details in the implementation. You may also wish to look at the implementation of Alexis’ Hackett. On Apr 18, 2018, at 8:40 AM, Dmitry Pavlovwrote: Hello, I am looking for an advice on how to write a macro that is aware of the information extracted from syntax objects from another macro that is called "inside" the first one. For instance, let it be the (this) macro that detects if its argument is an integer or float, and let it be the (print) macro that should emit the according printing command -- at compile time. Here is a stub (not working) to show what I am trying to achieve: #lang racket/base (require racket/format (for-syntax syntax/parse) (for-syntax racket/base)) (define-syntax (print stx) (syntax-parse stx (((~literal print) expr) (if #t ;; need some condition here that knows whether expr is an integer or a float (syntax/loc stx (displayln (~r expr #:notation 'positional #:precision '(= 2 (syntax/loc stx (printf "~a\n" expr)) (define-syntax (this stx) (syntax-parse stx (((~literal this) (expr ...)) (syntax/loc stx (expr ...)) ) (((~literal this) datum) (if (exact? (syntax->datum #'datum)) (printf "we know at compile time that is is an integer\n") (printf "we know at compile time that is is a float\n")) (syntax/loc stx datum (print (this (this (this 123 (print (this (this (this 456.0 How do I achieve that (print) knows which number is in (this) down there? I thought about (syntax-property), but it does not work, either because I am misapplying it, or because of the way the syntax expander works. I also tried to (expand-syntax) to get the syntax expander work bottom-up, but eventually decided that it can not work too, or I do not understand how it should work. The other option that I see is "manual" processing of the whole syntax tree after the (syntax-parse) did its job. But it seems a bit extra for the task. Is it the only way? Best regards, Dmitry -- 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
Re: [racket-users] announcement: racket-peg release 0.2
Sounds interesting. Is there any documentation on it aside from the README? On Fri, Apr 13, 2018 at 1:26 PM,wrote: > hello! > > I have created a PEG parser library for racket. It's basically regex turned > up to 11. > It lets you write parsers like this: > > (define-peg marked-palindrome > (or "m" > (and "1" marked-palindrome "1") > (and "0" marked-palindrome "0"))) > > or like this: > > #lang peg > expr <- sum ; > sum <-- (product ('+' / '-') sum) / product ; > product <-- (value ('*' / '/') product) / value ; > value <-- number / '(' expr ')' ; > number <-- [0-9]+ ; > > It is available from the racket pkgs repository, or on github: > * https://pkgd.racket-lang.org/pkgn/package/peg > * https://github.com/rain-1/racket-peg > > I welcome feedback and hope that the library is of use. > > -- > 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] Is it possible to pass syntax information from bottom up?
Here's a version of your program that performs as you specified: http://pasterack.org/pastes/91460 But do take a look at the paper, docs [1], or codebase [2], which turns this idea into complete languages. [1]: http://docs.racket-lang.org/turnstile/index.html [2]: https://github.com/stchang/macrotypes On Wed, Apr 18, 2018 at 9:39 AM, Matthias Felleisenwrote: > > You want to look at Stephen's Turnstile, a DSL for making typed DSLs and > macros. Like all type systems, this is exactly what it does. > > Here is the link to the paper: > > https://www2.ccs.neu.edu/racket/pubs/#popl17-ckg > > It obscures what you need, which is a combination of local-expand, > syntax-parse and its various hooks. The rough idea is to locally expand a > given phrase and to expand in such a way that macros return two pieces of > information: the expanded syntax and the additional property. You can try to > encode this with > > #'(begin expanded-code property) > > or just use a syntax-property, whatever fits best. When the local-expand > returns, take apart the macro and re-do the same thing. > > Details in the implementation. > > You may also wish to look at the implementation of Alexis’ Hackett. > > > > > > >> On Apr 18, 2018, at 8:40 AM, Dmitry Pavlov wrote: >> >> Hello, >> >> I am looking for an advice on how to write a macro that is aware of the >> information extracted from syntax objects from another macro that is called >> "inside" the first one. For instance, let it be the (this) macro that >> detects if its argument is an integer or float, and let it be the (print) >> macro that should emit the according printing command -- at compile time. >> >> Here is a stub (not working) to show what I am trying to achieve: >> >> #lang racket/base >> >> (require racket/format >> (for-syntax syntax/parse) >> (for-syntax racket/base)) >> >> (define-syntax (print stx) >> (syntax-parse stx >> (((~literal print) expr) >> (if #t ;; need some condition here that knows whether expr is an >> integer or a float >> (syntax/loc stx >>(displayln (~r expr #:notation 'positional #:precision '(= 2 >> (syntax/loc stx >>(printf "~a\n" expr)) >> >> (define-syntax (this stx) >> (syntax-parse stx >> (((~literal this) (expr ...)) >> (syntax/loc stx (expr ...)) >> ) >> (((~literal this) datum) >> (if (exact? (syntax->datum #'datum)) >>(printf "we know at compile time that is is an integer\n") >>(printf "we know at compile time that is is a float\n")) >> (syntax/loc stx datum >> >> >> (print (this (this (this 123 >> (print (this (this (this 456.0 >> >> >> How do I achieve that (print) knows which number is in (this) down there? >> I thought about (syntax-property), but it does not work, either because I am >> misapplying it, or because of the way the syntax expander works. >> >> I also tried to (expand-syntax) to get the syntax expander work bottom-up, >> but eventually decided that it can not work too, or I do not understand how >> it should work. >> >> The other option that I see is "manual" processing of the whole syntax tree >> after the (syntax-parse) did its job. But it seems a bit extra for the task. >> Is it the only way? >> >> Best regards, >> >> Dmitry >> >> >> -- >> 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.
Re: [racket-users] How to obtain the public IP of the sender of an HTTP request?
Wow. Thanks, Greg, that's really helpful. This is what I love about this list -- ask a simple question and you get the answer and also a lot of useful related information from experienced people. On Wed, Apr 18, 2018 at 8:37 AM, Greg Hendershottwrote: >> PS if you're running the Racket web server as a proxy behind Apache, then >> `request-client-ip` will always be the localhost IP. However, Apache stores >> the original request IP in special header called X-Forwarded-For [1] which >> can be retrieved like so: > > Same header with nginx or AWS ELB in front. > > > If you're having Apache/nginx/ELB/whatever handle SSL, and the Racket > web server itself is plain http, then you may also be interested in > X-Forwarded-Proto. > > > For example, if you want to redirect http to https -- a nice thing to > do for users -- you could do something like: > > (define/contract ((wrap-http->https handler) req) wrapper? > (match (headers-assq* #"x-forwarded-proto" (request-headers/raw req)) > [(header _ #"http") > (redirect-to (path->external-uri >(url->string (struct-copy url (request-uri req) > [scheme #f] > [port #f]))) > permanently)] > [_ (handler req)])) > > p.s. This is using a "wrapper" style of composing handlers, where: > > (define handler? (-> request? response?)) > (define wrapper? (-> handler? handler?)) > > and the basic `dispatch` handler might be wrapped with something like this: > > (serve/servlet (~> ;Note: requests go UP this chain, responses DOWN > dispatch > wrap-gzip > wrap-not-modified > wrap-authorize > wrap-authenticate > wrap-http->https > wrap-timed-and-logged) > #:servlet-path "/" > #:servlet-regexp#px"" > #:listen-ip #f > #:port (current-internal-port) ;e.g. 8080 > #:launch-browser? (not (current-production)) > #:servlet-responder error-responder) -- 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] Is it possible to pass syntax information from bottom up?
You want to look at Stephen's Turnstile, a DSL for making typed DSLs and macros. Like all type systems, this is exactly what it does. Here is the link to the paper: https://www2.ccs.neu.edu/racket/pubs/#popl17-ckg It obscures what you need, which is a combination of local-expand, syntax-parse and its various hooks. The rough idea is to locally expand a given phrase and to expand in such a way that macros return two pieces of information: the expanded syntax and the additional property. You can try to encode this with #'(begin expanded-code property) or just use a syntax-property, whatever fits best. When the local-expand returns, take apart the macro and re-do the same thing. Details in the implementation. You may also wish to look at the implementation of Alexis’ Hackett. > On Apr 18, 2018, at 8:40 AM, Dmitry Pavlovwrote: > > Hello, > > I am looking for an advice on how to write a macro that is aware of the > information extracted from syntax objects from another macro that is called > "inside" the first one. For instance, let it be the (this) macro that detects > if its argument is an integer or float, and let it be the (print) macro that > should emit the according printing command -- at compile time. > > Here is a stub (not working) to show what I am trying to achieve: > > #lang racket/base > > (require racket/format > (for-syntax syntax/parse) > (for-syntax racket/base)) > > (define-syntax (print stx) > (syntax-parse stx > (((~literal print) expr) > (if #t ;; need some condition here that knows whether expr is an integer > or a float > (syntax/loc stx >(displayln (~r expr #:notation 'positional #:precision '(= 2 > (syntax/loc stx >(printf "~a\n" expr)) > > (define-syntax (this stx) > (syntax-parse stx > (((~literal this) (expr ...)) > (syntax/loc stx (expr ...)) > ) > (((~literal this) datum) > (if (exact? (syntax->datum #'datum)) >(printf "we know at compile time that is is an integer\n") >(printf "we know at compile time that is is a float\n")) > (syntax/loc stx datum > > > (print (this (this (this 123 > (print (this (this (this 456.0 > > > How do I achieve that (print) knows which number is in (this) down there? > I thought about (syntax-property), but it does not work, either because I am > misapplying it, or because of the way the syntax expander works. > > I also tried to (expand-syntax) to get the syntax expander work bottom-up, > but eventually decided that it can not work too, or I do not understand how > it should work. > > The other option that I see is "manual" processing of the whole syntax tree > after the (syntax-parse) did its job. But it seems a bit extra for the task. > Is it the only way? > > Best regards, > > Dmitry > > > -- > 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.
[racket-users] Is it possible to pass syntax information from bottom up?
Hello, I am looking for an advice on how to write a macro that is aware of the information extracted from syntax objects from another macro that is called "inside" the first one. For instance, let it be the (this) macro that detects if its argument is an integer or float, and let it be the (print) macro that should emit the according printing command -- at compile time. Here is a stub (not working) to show what I am trying to achieve: #lang racket/base (require racket/format (for-syntax syntax/parse) (for-syntax racket/base)) (define-syntax (print stx) (syntax-parse stx (((~literal print) expr) (if #t ;; need some condition here that knows whether expr is an integer or a float (syntax/loc stx (displayln (~r expr #:notation 'positional #:precision '(= 2 (syntax/loc stx (printf "~a\n" expr)) (define-syntax (this stx) (syntax-parse stx (((~literal this) (expr ...)) (syntax/loc stx (expr ...)) ) (((~literal this) datum) (if (exact? (syntax->datum #'datum)) (printf "we know at compile time that is is an integer\n") (printf "we know at compile time that is is a float\n")) (syntax/loc stx datum (print (this (this (this 123 (print (this (this (this 456.0 How do I achieve that (print) knows which number is in (this) down there? I thought about (syntax-property), but it does not work, either because I am misapplying it, or because of the way the syntax expander works. I also tried to (expand-syntax) to get the syntax expander work bottom-up, but eventually decided that it can not work too, or I do not understand how it should work. The other option that I see is "manual" processing of the whole syntax tree after the (syntax-parse) did its job. But it seems a bit extra for the task. Is it the only way? Best regards, Dmitry -- 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] How to obtain the public IP of the sender of an HTTP request?
> PS if you're running the Racket web server as a proxy behind Apache, then > `request-client-ip` will always be the localhost IP. However, Apache stores > the original request IP in special header called X-Forwarded-For [1] which > can be retrieved like so: Same header with nginx or AWS ELB in front. If you're having Apache/nginx/ELB/whatever handle SSL, and the Racket web server itself is plain http, then you may also be interested in X-Forwarded-Proto. For example, if you want to redirect http to https -- a nice thing to do for users -- you could do something like: (define/contract ((wrap-http->https handler) req) wrapper? (match (headers-assq* #"x-forwarded-proto" (request-headers/raw req)) [(header _ #"http") (redirect-to (path->external-uri (url->string (struct-copy url (request-uri req) [scheme #f] [port #f]))) permanently)] [_ (handler req)])) p.s. This is using a "wrapper" style of composing handlers, where: (define handler? (-> request? response?)) (define wrapper? (-> handler? handler?)) and the basic `dispatch` handler might be wrapped with something like this: (serve/servlet (~> ;Note: requests go UP this chain, responses DOWN dispatch wrap-gzip wrap-not-modified wrap-authorize wrap-authenticate wrap-http->https wrap-timed-and-logged) #:servlet-path "/" #:servlet-regexp#px"" #:listen-ip #f #:port (current-internal-port) ;e.g. 8080 #:launch-browser? (not (current-production)) #:servlet-responder error-responder) -- 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.