Re: [racket-users] Displaying limited decimal places of a BigFloat?
On Thursday, 25 May 2017 23:44:58 UTC+10, David K. Storrs wrote: > This isn't smooth, but it works: > > #lang at-exp racket > (first (regexp-match @pregexp{\d+\.\d{0,4}} "15.123456789")) > (first (regexp-match @pregexp{\d+\.\d{0,4}} "15.12")) > Thank you - that is certainly more complicated than I though it would be. Another way would be to create a new real number, something like (exact->inexact (bigfloat->real x)) and then apply the conversion to and from a string to it. For example: > (require math/bigfloat) > (bf-precision 255) > (define x (bfsqrt (bf 3))) > x (bf #e1.73205080756887729352744634150587236694280525381038062805580697945193301690881) > (displayln (string->number (real->decimal-string (exact->inexact > (bigfloat->real x)) 4 ))) 1.732 I was just hoping there might be something neater! -- 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] seeking advice on implementing a racket structure editor
I'm looking to make a structure editor for racket code, with an eye to perhaps eventually integrating it into the DrRacket IDE. I haven't used Racket/Draw or Racket/GUI before and I'm currently evaluating their suitability for the task. In general, I'm eager for relatively simple Racket/GUI examples; I've been reading the docs directly, but there are lots of things I'm confused about. I don't have very much GUI experience in general, though I've done a couple small things using Swing in Java. I have some specific questions below but generally I'm looking for guidance in using racket/gui or any other libraries that might be of help here. For the sake of starting somewhere, I'm just trying to make an editor for tree-structured data, without interpreting it as source code as such. That is, I want to make something that opens/saves text files containing (parenthesized) s-expressions whose atoms are (alphanumeric) symbols. I want to represent these s-expressions on-screen as a system of nested boxes. Eventually I want to do fancy things with layout, so I'd like to keep things as abstract as is realistic. Specifically, I don't want to rely too much on text-based flow built-in to whatever library I use, though I am willing to do so to start. So let's say that my atoms will originally be boxes containing text; text% snips from racket/gui seem suitable, and the surrounding box structures can be implemented using text% objects to start, then perhaps pasteboard% objects to allow for more complex flow/positioning. I've already written code that will take an s-expression, and create a nested structure of text% objects on a canvas as described above, but I'm not sure I'm doing it in a very principled way. Specifically, I'd like advice on the best way to approach this from the perspective of 'un-parsing' whatever structure I create to an s-expression when i want to 'save'. What I want to do next is implement both keyboard and mouse controls to navigate through the tree. Specifically, assign keys to select parent/next-child, etc. I'm getting a vague idea of how to do this from the docs but examples would help. Basically the event model is not clear to me, and I am having trouble disentangling snips, editors, administrators, etc. I'm also trying to figure out how to visually indicate a selected subtree. I figured this would be possible using the the style<%> interface, but AFAICT it only has in-built support for text styling; that is, I can't figure out how to change either the background or stroke color of an embedded text% or pasteboard% snip. Presumably I can do this by creating a custom snip% class, which I'm sure I'll want to do at some point, but I'm wondering if I've missed something simpler? I'm also looking for advice on modelling the abstract idea of a 'selection'. To support the functionality I eventually want to create, I want the ability to create 'complex selections' to support structured tree transformations. By this I mean the ability to select a subtree, and the make 'holes' in it by un-selecting certain branches of that subtree - as well as the ability to simultaneously select multiple distinct subtrees. To start with though I just want to implement a simple set of transformations which operate on a single selected subtree. For example, if the selection is a text atom, one transformation would be to overwrite that text. Similarly, I want to implement transformations to create a new child of a selected node, to insert a new parent node between a selected node and its parent, to create new sibling nodes to the left/right of a selected node, and to delete a selected subtree. -- 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] making a language that can return the body of a function
The client module can refer to all imported #% forms. If you don’t export it from the language module, it’s not there. [Well, mostly] Implicitly the client module already refers to #% forms already. > On May 25, 2017, at 7:09 PM, Vityouwrote: > > On Wednesday, May 24, 2017 at 2:05:23 PM UTC-6, Matthias Felleisen wrote: >> Don’t eval. This is a bit crude but it now your lam-s keep track of your >> environment, too. >> >> #lang racket ;; new-lang.rkt >> >> (provide >> #%app >> #%datum >> #%top-interaction >> (rename-out >> (new-lambda lambda) >> (new-mb #%module-begin))) >> >> (require racket/stxparam) >> >> (define-syntax (new-lambda stx) >> (syntax-case stx () >>[(_ (x ...) e ...) >> #`(letrec ([L (lam '(x ...) >>'(e ...) >>(*env) >>(lambda (x ...) >> (syntax-parameterize ([*env >> (lambda (stx) >> (syntax-case stx () >> [(_) #`(append '(x ...) >> (lam-environment L))]))]) >>e) >> ...))]) >> L)])) >> (define-syntax-parameter *env >> (syntax-rules () [(_) '()])) >> (struct lam (parameters bodies environment closure) #:property >> prop:procedure 3) >> >> (define-syntax (new-mb stx) >> (syntax-case stx () >>[(_ e ...) >> #'(#%module-begin >>(let ([v e]) >> (if (lam? v) >> `(let (,@(map (lambda (x) `(,x --some-value--)) >> (lam-environment v))) >> (lambda ,(lam-parameters v) ,@(lam-bodies v))) >> v)) >>...)])) >> >> >> >>> On May 24, 2017, at 3:41 PM, Vityou wrote: >>> >>> On Wednesday, May 24, 2017 at 12:05:19 PM UTC-6, Vityou wrote: On Tuesday, May 23, 2017 at 8:21:59 PM UTC-6, Matthias Felleisen wrote: > Try to start with this: > > > > > > #lang racket ;; new-lang.rkt > > > (provide > #%app > #%datum > #%top-interaction > (rename-out > (new-lambda lambda) > (new-mb #%module-begin))) > > > (define-syntax (new-lambda stx) > (syntax-case stx () >[(_ (x ...) e ...) > #'(lam '(x ...) '(e ...) (lambda (x ...) e ...))])) > > > (struct lam (parameters bodies closure) #:property prop:procedure 2) > > > (define-syntax (new-mb stx) > (syntax-case stx () >[(_ e ...) > #'(#%module-begin >(let ([v e]) > (if (lam? v) > `(lambda ,(lam-parameters v) ,@(lam-bodies v)) > v)) >...)])) > > > > > ;; - - - > > > > #lang s-exp "new-lang.rkt” ;; new-lang-client.rkt > > > ((lambda (x) x) > (lambda (y) y)) > > > > > > > On May 23, 2017, at 10:03 PM, Vityou wrote: > > > On Tuesday, May 23, 2017 at 7:17:18 PM UTC-6, Matthias Felleisen wrote: > Why do you interpret S-expressions instead of re-mapping lambda and > #%app? > > > > > > On May 23, 2017, at 9:14 PM, Vityou wrote: > > I might be able to do something like this, but what I'm looking for is > something that will be able to show the variables available to it in > adition to its source. I'll probable have to do something like what you > did with the struct accept add a field with its available variables and > modify #%app to add to its known variables. > > -- > 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. > > I dont know what I could map lambda to that would let it retain and print > its known variables besides a list. That's probably good enough for most cases, but I tried to add a struct field to record the lexical content, I can't fin a way to mimic evaluating the body of the function in the struct, this is the closest I got: (define-syntax (new-app stx) (syntax-case stx () [(_ f x) #'(let ([result (#%app f x)]) (if (lam? result) (struct-copy lam result [lex (cons `(,(lam-parameter f) ,(if (lam? x) `(λ (,(lam-parameter x)) ,(lam-body x)) x)) (lam-lex f))])
Re: [racket-users] immutable hash table performance
> On May 25, 2017, at 3:49 PM, Matthew Flattwrote: > > At Thu, 25 May 2017 18:28:16 -0400, "'John Clements' via Racket Users" wrote: >>> On May 25, 2017, at 3:27 PM, Jon Zeppieri wrote: >>> Immutable hash operations are logarithmic, not constant time. >> >> I believe our documentation says they’re “effectively constant-time”. > > FWIW, there's a margin note there to explain that the operations are > actually logarithmic-time. That’s a good point, and that note is more prominent than I had initially noticed. Thanks! John -- 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] making a language that can return the body of a function
On Wednesday, May 24, 2017 at 2:05:23 PM UTC-6, Matthias Felleisen wrote: > Don’t eval. This is a bit crude but it now your lam-s keep track of your > environment, too. > > #lang racket ;; new-lang.rkt > > (provide > #%app > #%datum > #%top-interaction > (rename-out > (new-lambda lambda) > (new-mb #%module-begin))) > > (require racket/stxparam) > > (define-syntax (new-lambda stx) > (syntax-case stx () > [(_ (x ...) e ...) > #`(letrec ([L (lam '(x ...) > '(e ...) > (*env) > (lambda (x ...) > (syntax-parameterize ([*env > (lambda (stx) >(syntax-case stx () > [(_) #`(append '(x ...) > (lam-environment L))]))]) > e) > ...))]) > L)])) > (define-syntax-parameter *env > (syntax-rules () [(_) '()])) > (struct lam (parameters bodies environment closure) #:property prop:procedure > 3) > > (define-syntax (new-mb stx) > (syntax-case stx () > [(_ e ...) > #'(#%module-begin > (let ([v e]) > (if (lam? v) > `(let (,@(map (lambda (x) `(,x --some-value--)) > (lam-environment v))) > (lambda ,(lam-parameters v) ,@(lam-bodies v))) > v)) > ...)])) > > > > > On May 24, 2017, at 3:41 PM, Vityouwrote: > > > > On Wednesday, May 24, 2017 at 12:05:19 PM UTC-6, Vityou wrote: > >> On Tuesday, May 23, 2017 at 8:21:59 PM UTC-6, Matthias Felleisen wrote: > >>> Try to start with this: > >>> > >>> > >>> > >>> > >>> > >>> #lang racket ;; new-lang.rkt > >>> > >>> > >>> (provide > >>> #%app > >>> #%datum > >>> #%top-interaction > >>> (rename-out > >>> (new-lambda lambda) > >>> (new-mb #%module-begin))) > >>> > >>> > >>> (define-syntax (new-lambda stx) > >>> (syntax-case stx () > >>> [(_ (x ...) e ...) > >>> #'(lam '(x ...) '(e ...) (lambda (x ...) e ...))])) > >>> > >>> > >>> (struct lam (parameters bodies closure) #:property prop:procedure 2) > >>> > >>> > >>> (define-syntax (new-mb stx) > >>> (syntax-case stx () > >>> [(_ e ...) > >>> #'(#%module-begin > >>> (let ([v e]) > >>> (if (lam? v) > >>> `(lambda ,(lam-parameters v) ,@(lam-bodies v)) > >>> v)) > >>> ...)])) > >>> > >>> > >>> > >>> > >>> ;; - - - > >>> > >>> > >>> > >>> #lang s-exp "new-lang.rkt” ;; new-lang-client.rkt > >>> > >>> > >>> ((lambda (x) x) > >>> (lambda (y) y)) > >>> > >>> > >>> > >>> > >>> > >>> > >>> On May 23, 2017, at 10:03 PM, Vityou wrote: > >>> > >>> > >>> On Tuesday, May 23, 2017 at 7:17:18 PM UTC-6, Matthias Felleisen wrote: > >>> Why do you interpret S-expressions instead of re-mapping lambda and > >>> #%app? > >>> > >>> > >>> > >>> > >>> > >>> On May 23, 2017, at 9:14 PM, Vityou wrote: > >>> > >>> I might be able to do something like this, but what I'm looking for is > >>> something that will be able to show the variables available to it in > >>> adition to its source. I'll probable have to do something like what you > >>> did with the struct accept add a field with its available variables and > >>> modify #%app to add to its known variables. > >>> > >>> -- > >>> 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. > >>> > >>> I dont know what I could map lambda to that would let it retain and print > >>> its known variables besides a list. > >> > >> That's probably good enough for most cases, but I tried to add a struct > >> field to record the lexical content, I can't fin a way to mimic evaluating > >> the body of the function in the struct, this is the closest I got: > >> > >> (define-syntax (new-app stx) > >> (syntax-case stx () > >>[(_ f x) > >> #'(let ([result (#%app f x)]) > >> (if (lam? result) > >> (struct-copy lam > >> result > >> [lex (cons `(,(lam-parameter f) ,(if (lam? x) > >> `(λ > >> (,(lam-parameter x)) ,(lam-body x)) > >> x)) > >> (lam-lex f))]) > >> result))])) > >> > >> It sort of works, but it just blindly tacks on info if the result is a > >> struct. ((lambda (x) x) (lambda (y) y) results in (function (lambda (y) > >> y) (x (lambda (y) y))) > > > > I was able to get it to work by processing updating the list
Re: [racket-users] immutable hash table performance
At Thu, 25 May 2017 18:28:16 -0400, "'John Clements' via Racket Users" wrote: > > On May 25, 2017, at 3:27 PM, Jon Zeppieriwrote: > > Immutable hash operations are logarithmic, not constant time. > > I believe our documentation says they’re “effectively constant-time”. FWIW, there's a margin note there to explain that the operations are actually logarithmic-time. -- 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] immutable hash table performance
> On May 25, 2017, at 3:27 PM, Jon Zeppieriwrote: > > On Thu, May 25, 2017 at 6:16 PM, 'John Clements' via Racket Users > wrote: >> Following up on a discussion I had with another teacher here, I decided to >> briefly investigate the running time of insertion and deletion on mutable vs >> immutable hash tables. I was a bit disappointed to find that it turns out >> that insertion really doesn’t look very constant-time for insertion… or for >> lookup, actually. I drew some pictures: tell me what you think! >> >> https://www.brinckerhoff.org/blog/2017/05/25/hash-table-timings/ >> >> John > > Immutable hash operations are logarithmic, not constant time. I believe our documentation says they’re “effectively constant-time”. John -- 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] immutable hash table performance
On Thu, May 25, 2017 at 6:16 PM, 'John Clements' via Racket Userswrote: > Following up on a discussion I had with another teacher here, I decided to > briefly investigate the running time of insertion and deletion on mutable vs > immutable hash tables. I was a bit disappointed to find that it turns out > that insertion really doesn’t look very constant-time for insertion… or for > lookup, actually. I drew some pictures: tell me what you think! > > https://www.brinckerhoff.org/blog/2017/05/25/hash-table-timings/ > > John Immutable hash operations are logarithmic, not constant time. -- 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] immutable hash table performance
> On May 25, 2017, at 3:20 PM, Ben Greenmanwrote: > > Is the y-axis on the first plot labeled correctly? It's reporting fractions > of a millisecond, but the text talks about 7 vs. 40 seconds. Yes, I believe that’s correct: the 7 seconds is for constructing the table of 10 million elements, so multiply those fractions of a millisecond by 10 million. > > Also the timings links aren't working for me: > https://www.brinckerhoff.org/img/hash-table-timings.rkt > https://www.brinckerhoff.org/img/hash-table-lookup-timings.rkt I believe I’ve fixed this. (Shouldn’t have been an ’s’) there. John -- 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] immutable hash table performance
Is the y-axis on the first plot labeled correctly? It's reporting fractions of a millisecond, but the text talks about 7 vs. 40 seconds. Also the timings links aren't working for me: https://www.brinckerhoff.org/img/hash-table-timings.rkt https://www.brinckerhoff.org/img/hash-table-lookup-timings.rkt On Thu, May 25, 2017 at 6:16 PM, 'John Clements' via Racket Users < racket-users@googlegroups.com> wrote: > Following up on a discussion I had with another teacher here, I decided to > briefly investigate the running time of insertion and deletion on mutable > vs immutable hash tables. I was a bit disappointed to find that it turns > out that insertion really doesn’t look very constant-time for insertion… or > for lookup, actually. I drew some pictures: tell me what you think! > > https://www.brinckerhoff.org/blog/2017/05/25/hash-table-timings/ > > John > > (praise and adulation, as always, to Messrs. Butterick and Hendershott for > pollen & frog, respectively) > > -- > 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] immutable hash table performance
Following up on a discussion I had with another teacher here, I decided to briefly investigate the running time of insertion and deletion on mutable vs immutable hash tables. I was a bit disappointed to find that it turns out that insertion really doesn’t look very constant-time for insertion… or for lookup, actually. I drew some pictures: tell me what you think! https://www.brinckerhoff.org/blog/2017/05/25/hash-table-timings/ John (praise and adulation, as always, to Messrs. Butterick and Hendershott for pollen & frog, respectively) -- 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] What can I do with thread descriptors?
> On May 25, 2017, at 1:16 PM, David Storrswrote: > > 1) What can I do with a thread descriptor? The section on Threads in the reference[1] includes all sorts of functions that operate on thread descriptors, including but not limited to thread-suspend, thread-resume, kill-thread, break-thread, and thread-wait. > 2) Is there a way to get the thread descriptor from inside the thread? Yes, use (current-thread).[2] From the documentation: > Returns the thread descriptor for the currently executing thread. If you just try searching for “thread descriptor” in the documentation, the only result I find is the page that documents these functions and forms. I’m curious: did you find the term somewhere else that wasn’t properly linked to the reference? If so, that should probably be fixed. Alexis [1]: http://docs.racket-lang.org/reference/threads.html [2]: http://docs.racket-lang.org/reference/threads.html#%28def._%28%28quote._~23~25kernel%29._current-thread%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.
[racket-users] What can I do with thread descriptors?
Two questions: 1) What can I do with a thread descriptor? 2) Is there a way to get the thread descriptor from inside the thread? There's no documentation that I can find on what a thread descriptor actually is or what can be done with it. It's an opaque structure...I guess I can use it for eq? and equal? comparisons, but I'm not sure what use that is. One thing I would like to be able to do with threads is give them a label for logging purposes. I've been making that work by creating a label when I create the thread and then parameterizing it into my 'say' macro (which I use in place of 'print' and etc): (define prefix-for-say (make-parameter "")) (define-syntax (say stx) (syntax-case stx () [(say a ...) #'(displayln (~a (prefix-for-say) a ...))] )) (parameterize ((prefix-for-say (label-maker))) (thread (thunk (say "about to do stuff") (do-stuff) (say "did stuff" This would print: "some-label: about to do stuff" "some-label: did stuff" -- 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 a created language in the repl
Vityou, I will give you an example though I myself sometimes doubt that I did it in the right way. Anyway, here is what I did when I had exactly the same problem: - redefine and reexport #% top-interaction - provide #:language-info to the DrRacket's REPL (I am not sure if racket's REPL needs it too, but doing it will not hurt). The provided call should respond to 'configure-runtime key - the 'configure-runtime should trigger a setting of (current-read-interaction) parameter. - at the end of the implementation of (current-read-interaction), it should set another (current-read-interaction) that just returns EOF -- and then sets the original (current-read-interaction) back, so it is kind of a loop. The example (made long ago) is available at: https://github.com/kugelblitz/calc Relevant parts: /language.rkt (see top-interaction) /lang/reader.rkt (reference to lang-info) /lang/lang-info.rkt (calling of "configure runtime" handler) /lang/configure-runtime.rkt (the handler itself) Hope this helps. Dmitry On 05/18/2017 06:45 AM, Vityou wrote: I did reprovide all of the #%... forms from racket, and the repl works with base.rkt, it's when I have a reader that the repl doesn't work. -- 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.