Re: [racket-users] How to limit memory usage and raise out-of-memory error?
Cool! That does the job. Thank you. On Fri, Aug 10, 2018 at 3:57 PM, Matthew Flatt wrote: > For the second part, use `thread/suspend-to-kill` to create a thread > that is merely suspended when its custodian is shut down, and then you > can use `(continuation-marks thread-id)` to get the thread's > continuation marks at the point where it was suspended. > > You'll need to wait until either the thread is terminated or the > custodian is shutdown, instead of waiting until the thread terminates. > Use a custodian box (for the same custodian) as a synchronizable event > for custodian shutdown. > > At Fri, 10 Aug 2018 15:27:07 -0500, Shu-Hung You wrote: >> I'm running a thread with memory limit using custodian-limit-memory. >> How do I reliably detect whether the thread I'm running was terminated >> normally or aborted by custodian shutdown? Plus, is it possible to >> obtain the context at the time the memory limit was exceeded? >> >> I can think these two: >> >> 1. Use a channel to indicate normal termination, or >> 2. detect whether the custodian had been shut down. >> >> Both methods address the first question but not the second question. >> Any pointers? >> >> Best, >> Shu-Hung >> >> (define TIMEOUT 60) >> (define MEMORY-LIMIT (* 2 1024 1024 1024)) >> >> (parameterize ([current-custodian (make-custodian)]) >> (custodian-limit-memory (current-custodian) MEMORY-LIMIT) >> (define thread-id >> (thread (λ () >> (displayln "This displayln probably takes lots of >> memory" >> (define ended? (sync/timeout/enable-break TIMEOUT thread-id)) >> (unless ended? (break-thread thread-id 'terminate)) >> (thread-wait thread-id) >> (when (custodian-shut-down? (current-custodian)) >> ;; The context here is not the right one and the exception is not >> ;; raised in the right thread >> (raise (exn:fail:out-of-memory "Out of memory" >> (current-continuation-marks))) >> >> -- >> 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 limit memory usage and raise out-of-memory error?
For the second part, use `thread/suspend-to-kill` to create a thread that is merely suspended when its custodian is shut down, and then you can use `(continuation-marks thread-id)` to get the thread's continuation marks at the point where it was suspended. You'll need to wait until either the thread is terminated or the custodian is shutdown, instead of waiting until the thread terminates. Use a custodian box (for the same custodian) as a synchronizable event for custodian shutdown. At Fri, 10 Aug 2018 15:27:07 -0500, Shu-Hung You wrote: > I'm running a thread with memory limit using custodian-limit-memory. > How do I reliably detect whether the thread I'm running was terminated > normally or aborted by custodian shutdown? Plus, is it possible to > obtain the context at the time the memory limit was exceeded? > > I can think these two: > > 1. Use a channel to indicate normal termination, or > 2. detect whether the custodian had been shut down. > > Both methods address the first question but not the second question. > Any pointers? > > Best, > Shu-Hung > > (define TIMEOUT 60) > (define MEMORY-LIMIT (* 2 1024 1024 1024)) > > (parameterize ([current-custodian (make-custodian)]) > (custodian-limit-memory (current-custodian) MEMORY-LIMIT) > (define thread-id > (thread (λ () > (displayln "This displayln probably takes lots of > memory" > (define ended? (sync/timeout/enable-break TIMEOUT thread-id)) > (unless ended? (break-thread thread-id 'terminate)) > (thread-wait thread-id) > (when (custodian-shut-down? (current-custodian)) > ;; The context here is not the right one and the exception is not > ;; raised in the right thread > (raise (exn:fail:out-of-memory "Out of memory" > (current-continuation-marks))) > > -- > 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] How to limit memory usage and raise out-of-memory error?
I'm running a thread with memory limit using custodian-limit-memory. How do I reliably detect whether the thread I'm running was terminated normally or aborted by custodian shutdown? Plus, is it possible to obtain the context at the time the memory limit was exceeded? I can think these two: 1. Use a channel to indicate normal termination, or 2. detect whether the custodian had been shut down. Both methods address the first question but not the second question. Any pointers? Best, Shu-Hung (define TIMEOUT 60) (define MEMORY-LIMIT (* 2 1024 1024 1024)) (parameterize ([current-custodian (make-custodian)]) (custodian-limit-memory (current-custodian) MEMORY-LIMIT) (define thread-id (thread (λ () (displayln "This displayln probably takes lots of memory" (define ended? (sync/timeout/enable-break TIMEOUT thread-id)) (unless ended? (break-thread thread-id 'terminate)) (thread-wait thread-id) (when (custodian-shut-down? (current-custodian)) ;; The context here is not the right one and the exception is not ;; raised in the right thread (raise (exn:fail:out-of-memory "Out of memory" (current-continuation-marks))) -- 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] Recommendation for learning syntax?
> On Aug 10, 2018, at 1:02 PM, Eric Griffis wrote: > > A few months ago, I was similarly confused. Here's what I remember > learning since then. > > Let's call the character-level syntax of a language concrete and any > higher-level syntax abstract. By these definitions, a parser makes > concrete syntax abstract, and an interpreter translates one piece of > abstract syntax into another. FWIW, this is an rather non-standard use of these terms. concrete: stream of chars lex’ed: stream of chars turned into a stream of tokens, which are words in the vocabulary of the language parsed: a validation that the stream of tokens obeys the grammatical rules of the language StreamOfTokens —> Boolean would work but is usually shunned for a better alterative parsed, again: stream of tokens turned into an abstract syntax tree (AST) whose sheer existence validates that the grammar rules are obeyed and which is a good representation of the program for further processing further processing: skipped for now interpreted: an AST turned into a value plus a stream of observable side-effects In Lisp/Scheme/Racket land, parsed, again is “parse and expand”. In Racket land specifically, the reader creates NOT an S-expression but an AST consisting of syntax objects and the syntax system allows you to add “rules” to the “parse and expand” step to map one subtree to a different one. The key is that these rules are written in a syntax that provides the illusion of plain concrete syntax. — Matthias > > In Racket-space, I don't often see concrete and abstract syntax > discussed together. We tend to talk exclusively about parsing concrete > syntax "into s-expressions," or just assume s-expressions and focus on > abstract interpretation of syntax objects by syntax transformers. > > I didn't truly "get" syntax transformers until I had a working > understanding of the expander and how it affects phase-based > execution. I like to think of expansion as term rewriting, with syntax > transformers as rewrite rule generators. The expander recursively > rewrites the AST at the current phase into the AST for the next phase. > This is a fundamentally different perspective than macros as function > templates. The paper, Macros that Work Together, does a great job > explaining the difference. > > Awareness of the current phase and an ability to re-orient "up" or > "down" quickly are now essential skills for my day-to-day macro > programming. Intuiting which phase a piece of code inhabits got a lot > easier once I internalized the difference between define, > define-syntax, and define-for-syntax. > > When I started with the syntax/parse collection, it was all > syntax-parse and define-syntax-class. These days, I'll start with > define-simple-macro and increase flexibility -- first to > define-syntax-parser, then to syntax-parse inside define-syntax > -- as needed. I was pretty comfortable with syntax-case and > syntax-rules to begin with, which made picking up the syntax/parse > analogues straight forward. > > Eric > > > On Tue, Aug 7, 2018 at 8:48 AM Alex Gian wrote: > Simply put, I find syntax to be a brain > > I can do simple stuff, often by extensive study of example code, and I even > have the odd moment of illumination, which shows me that there is more to it > than just masochism! > > What I do not have is the flow, the mojo, to be able to write syntax like > second nature, and what's more to intersperse it with normal code without > freaking out. > > So I've decided to bite the bullet and dedicate some quality time to the > subject, without constantly winging it. In the light of this, what would the > good folk here recommend as a reasonable path on which to proceed fairly > quickly? I am not averse to meta-anything, but sometimes I just don't see > the elegance that is supposed to be there. > > One of my targets would also be to get the hang of syntax-parse. Are there > any tutorials out there? I do not mind if they are simple. When it comes to > syntax, so am I. > > > -- > 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
[racket-users] Re: how to show raco full (non-abbreviated) error messages
Hi Sam, okay, this is not exactly raco. I mean e.g. this snippet: given procedure: ...amm-3.1/util.scm:58:6 in map: argument mismatch; the given procedure's expected number of arguments does not match the given number of lists given procedure: ...amm-3.1/util.scm:58:6 expected: 2 given: 1 errortrace...: context...: util:table-with-decimals/new util:table-with-decimals table-as-html-with-decimals build-and-save-popdyn-display On Friday, August 10, 2018 at 8:58:21 PM UTC+2, Wolfgang Hukriede wrote: > > hi, > > subject says it all. I think it's a nuisance to cripple error messages > instead of just showing them. What's more, quite often emacs cannot find > the location then. > > thanks, see you > -- 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 show raco full (non-abbreviated) error messages
Can you give an example of what you mean? My guess is that you mean that `raco setup` prints an abbreviated form of the errors at the end of the run, but it also prints the full error message when it's encountered. Sam On Fri, Aug 10, 2018 at 2:58 PM, Wolfgang Hukriede wrote: > hi, > > subject says it all. I think it's a nuisance to cripple error messages > instead of just showing them. What's more, quite often emacs cannot find the > location then. > > thanks, see you > > -- > 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] how to show raco full (non-abbreviated) error messages
hi, subject says it all. I think it's a nuisance to cripple error messages instead of just showing them. What's more, quite often emacs cannot find the location then. thanks, see you -- 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] Recommendation for learning syntax?
A few months ago, I was similarly confused. Here's what I remember learning since then. Let's call the character-level syntax of a language *concrete* and any higher-level syntax *abstract*. By these definitions, a *parser* makes concrete syntax abstract, and an *interpreter* translates one piece of abstract syntax into another. In Racket-space, I don't often see concrete and abstract syntax discussed together. We tend to talk exclusively about parsing concrete syntax "into s-expressions," or just assume s-expressions and focus on abstract interpretation of *syntax objects* by *syntax transformers*. I didn't truly "get" syntax transformers until I had a working understanding of the expander and how it affects phase-based execution. I like to think of expansion as term rewriting, with syntax transformers as rewrite rule generators. The expander recursively rewrites the AST at the current phase into the AST for the next phase. This is a fundamentally different perspective than macros as function templates. The paper, *Macros that Work Together*, does a great job explaining the difference. Awareness of the current phase and an ability to re-orient "up" or "down" quickly are now essential skills for my day-to-day macro programming. Intuiting which phase a piece of code inhabits got a lot easier once I internalized the difference between define, define-syntax, and define-for-syntax. When I started with the syntax/parse collection, it was all syntax-parse and define-syntax-class. These days, I'll start with define-simple-macro and increase flexibility -- first to define-syntax-parser, then to syntax-parse inside define-syntax -- as needed. I was pretty comfortable with syntax-case and syntax-rules to begin with, which made picking up the syntax/parse analogues straight forward. Eric On Tue, Aug 7, 2018 at 8:48 AM Alex Gian wrote: > Simply put, I find syntax to be a brain > > I can do simple stuff, often by extensive study of example code, and I > even have the odd moment of illumination, which shows me that there is more > to it than just masochism! > > What I do not have is the flow, the mojo, to be able to write syntax like > second nature, and what's more to intersperse it with normal code without > freaking out. > > So I've decided to bite the bullet and dedicate some quality time to the > subject, without constantly winging it. In the light of this, what would > the good folk here recommend as a reasonable path on which to proceed > fairly quickly? I am not averse to meta-anything, but sometimes I just > don't see the elegance that is supposed to be there. > > One of my targets would also be to get the hang of syntax-parse. Are > there any tutorials out there? I do not mind if they are simple. When it > comes to syntax, so am I. > > -- > 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 embed a scheme'y text editor in another GUI application?
David Thrane Christiansen writes: >> Wow, those are stunning examples! I had no idea! > > Thanks! > >> BTW, do you have code for either of these posted anywhere under a libre >> license? Might be interesting to look at :) > > I don't typically post the source code of the slides themselves, > because I don't really design them for independent consumption outside > of the context of the talk, and I don't want to do tech support for > them. > > But the Idris interaction library has an example with it: > https://github.com/david-christiansen/idris-interaction.rkt > > The second one uses bits and pieces of Pie, from > https://github.com/the-little-typer/pie. I plan on publicly > documenting that library much better at some point - right now there's > only docs for the Pie language itself. > > If that's not enough to get started, contact me off-list and I'll send > the (potentially somewhat bitrotted) source for either talk. > > David Cool... I see the bits in the slideshow.rkt and gui/ directory of Pie, and that looks helpful. Thanks much :) -- 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: parser-tools/lex
On Friday, 10 August 2018 13:57:18 UTC+1, Zeta Convex wrote: > > I'm trying to match anything that isn't a tab or space, but I end up > matching nearly everything. > Ah, I think I just figured it out. I need to replace >*[(:+ (complement (:or #\Tab #\Space)))* > with [(+(char-complement (:or #\Tab #\Space))) It took me a long time to figure that out! -- 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] parser-tools/lex
I'm trying to match anything that isn't a tab or space, but I end up matching nearly everything. Here's a snip from the code: (define tsv-lexer (lexer [(eof) 'EOF] [#\space (tsv-lexer input-port)] [#\tab (tsv-lexer input-port)] *[(:+ (complement (:or #\Tab #\Space)))* (begin (display "lexeme is:") (displayln lexeme) (token-FIELD lexeme))] )) If use input "AAA " I get the output: lexeme is:AAA but it should be matching just AAA. What's going wrong? -- 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 display all paths of a tree without repetitions
On Sun, Aug 5, 2018 at 3:40 PM Matthias Felleisen wrote: > I“d write it like this: > > (struct tree (val left right) #:transparent) > ;; Tree = '() | (tree X Tree Tree) > > (define (printer t0) > (local (;; from-t0 : the path from t0 to t > (define (printer/acc t from-t0) > (cond > [(empty? t) >(map display (reverse (cons " end" from-t0))) >(newline)] > [else >(define from-t (list* " --> " (tree-val t) from-t0)) >(printer/acc (tree-left t) from-t) >(unless (empty? (tree-right t)) > (printer/acc (tree-right t) from-t))]))) > (printer/acc t0 '( > > (printer tree1) I took a while to understand this. It's brilliant. (Thanks for taking the time --- no matter how little that might've been for you.) FWIW, to understand it, I had to use the substitution method on paper. Here's my final version --- using string-join. Thanks again! (require racket/local) (require racket/string) (define (print-tree-elegant t0) (local ((define (format-all-items ls) (map (lambda (item) (format "~a" item)) ls)) (define (printer/acc t path-from-t0-to-t) (cond [(empty? t) (displayln (string-join (reverse (format-all-items path-from-t0-to-t)) " --> "))] [else (define from-t (cons (tree-root t) path-from-t0-to-t)) (printer/acc (tree-left t) from-t) (unless (empty? (tree-right t)) (printer/acc (tree-right t) from-t))]))) (printer/acc t0 '( -- 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.