[racket-users] LibreOffice scripts and Racket
Dear list members, Its been a few years since I've used Racket or been on this list so apologies if this is an elementary question. I need to write some scripts for LibreOffice. Has anyone written an interface to LibreOffice that makes this possible. Thanks, Harry Spier -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/18b5ed83-470c-4cea-bf67-a7d63ffab1f1%40googlegroups.com.
Re: [racket] Saving/printing plots
Forget this question. I just see the answer. I didn't read the documentation on plot :-) On Fri, Mar 7, 2014 at 7:48 PM, Harry Spier wrote: > Can you save,print or make images of plots you've created in Racket? > > Thanks, > Harry > Racket Users list: http://lists.racket-lang.org/users
[racket] Saving/printing plots
Can you save,print or make images of plots you've created in Racket? Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
Re: [racket] first vs car ; last vs cdr ; empty? vs null?
See also this previous thread on the Racket list. http://www.mail-archive.com/users%40racket-lang.org/msg12161.html Racket Users list: http://lists.racket-lang.org/users
[racket] Keeping DrRacket from closing plot window
In DrRacket I'm generating some simulations using the random function and plotting the results using the Racket Plot routines. I put the plot results in a new window using "(plot-new-window? #t)". This works fine but everytime I run a new simulation within DrRacket the previous plot window is closed. Is there a way to keep DrRacket from closing the open plot window each time I run a new simulation. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] interfaces in the Racket Guide
I just noticed that in the Racket Guide Chapter 13 "Classes and Objects" where they discuss interfaces they don't use the convention of ending an interface with <%>, i.e. they have "fish-interface", "grower-interface" ... not "fish-interface<%?" etc. The Racket reference chapter 5 does use the convention of ending with <%> but as far as I can see they don't say it is the convention. I vaguely recall that the convention of ending interfaces with <%> was mentioned (still is?) somewhere in the documentation in the past. Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Help with racket/gui and framework
Thanks Robby, When I use (define main-frame (new frame:text%)) case 1 below it gives me save, save all, print etc. in the file menu but now: a) the panel with the buttons I define is at the bottom not the top. b) I can't figure out how to modify the initial editor characteristics when the application starts (different font, different size etc.) or the editor-canvas% characteristics (different background) as I was able to when I used (define main-frame (new frame:standard-menus%)) c) I can't figure out how to now apply set-max-undo-history so I can use the undo feature. How do I get the horizontal-panel with my buttons to display at the top ? How do I access and set the characteristics of the editor% and the editor-canvas% ? How do I set se-max-undo-history ? CASE 1 using (define main-frame (new frame:text%)) Menus OK but issues stated above. #lang racket/gui (require framework) (application:current-app-name "Sanskrit editor") ;;framework (define main-frame (new frame:text% )) (send main-frame show #t) (define main-area (send main-frame get-area-container)) (define h-panel (new horizontal-panel% [parent main-area][stretchable-height #f][alignment '(left top)])) (define msg (new message% [parent main-area][label "NO EVENTS SO FAR... "])) (define button-font (make-object font% 12 "Consolas" 'default 'normal 'bold )) (define button-1 (new button% [parent h-panel][font button-font] [label "Apply Sandhi"] ; Callback procedure for a button click: [callback (lambda (button event) (send msg set-label "TEST Apply Sandhi Test"))])) (define button-2 (new button% [parent h-panel][font button-font] [label "HK-->Unicode"] ; Callback procedure for a button click: [callback (lambda (button event) (send msg set-label "TEST Converted HK-->Unicode"))])) CASE 2 using (define main-frame (new frame:text% )) The panel with my buttons is correctly placed at top and I can change editor% and editor-canvas% properties but no "save" and "save all" and "new" doesn't work correctly in "file" menu. -- #lang racket/gui (require framework) (application:current-app-name "Sanskrit editor") (define main-frame (new frame:standard-menus% [label "Sanskrit editor"])) (send main-frame show #t) (define main-area (send main-frame get-area-container)) (define h-panel (new horizontal-panel% [parent main-area][stretchable-height #f])) (define msg (new message% [parent main-area][label "NO EVENTS SO FAR... "])) (define button-font (make-object font% 12 "Consolas" 'default 'normal 'bold)) (define button-1 (new button% [parent h-panel][font button-font] [label "Apply Sandhi"] ; Callback procedure for a button click: [callback (lambda (button event) (send msg set-label "TEST Apply Sandhi Test"))])) (define button-2 (new button% [parent h-panel][font button-font] [label "HK-->Unicode"] ; Callback procedure for a button click: [callback (lambda (button event) (send msg set-label "TEST Converted HK-->Unicode"))])) (define main-text-editor (new text%)) (define default-delta (make-object style-delta%) ) (send default-delta set-delta-face "Consolas") (send default-delta set-size-add 6) (send main-text-editor change-style default-delta) (send main-text-editor set-max-undo-history 400) (send main-text-editor auto-wrap #t) (define main-canvas (new editor-canvas% [parent main-area])) (define WhiteSmokeColor (send the-color-database find-color "WhiteSmoke")) (send main-canvas set-canvas-background WhiteSmokeColor) (send main-canvas set-editor main-text-editor) --- On Tue, Feb 4, 2014 at 5:41 AM, Robby Findler wrote: > I think you want this for main-frame: > > (define main-frame (new frame:text%)) > > But for the other, it looks not so simple. The framework isn't abstracted > out in the right ways to have two different lists of recently opened files. > It probably should be, tho. Patches welcome! :) > > Robby > > > On Tue, Feb 4, 2014 at 1:25 AM, Harry Spier wrote: > >> A clarification about point 1 below: If I open a file or select "new" in >> the file menu it creates a new window and I'm able to save the text from >> that new window. Its just when I run the program and type text into the >> visible frame of the original window that there are no "save","save >> as","print" etc. menu items in the file menu. >
Re: [racket] Help with racket/gui and framework
A clarification about point 1 below: If I open a file or select "new" in the file menu it creates a new window and I'm able to save the text from that new window. Its just when I run the program and type text into the visible frame of the original window that there are no "save","save as","print" etc. menu items in the file menu. Thanks, Harry On Mon, Feb 3, 2014 at 11:00 PM, Harry Spier wrote: > I'm building a small text editing application based around an editor built > with racket/gui and framework.. The idea is that it has the usual text > editing features but also buttons where I select text and then based on > which button I click on the selected text is manipulated in different ways. > I'm just building the gui part now. I started using just racket/gui but > then tried to implement some things in "framework" but I'm having trouble > with a few things and I can't figure out how to do them from the > documentation. > > In the code below: > 1) How do I add a "Save" feature to the file menu. > 2) The "Open recent" menu item in the file menu opens my DrRacket > "recently opened files". How do I get it to look at its own history > instead of DrRackets. > 3) Where I define main-frame as a frame:standard-menus% object in the code > below, I tried to define it as a frame:editor% object but I couldn't get > that to work. Could someone show me how to do that. > > Thanks, > Harry > - > #lang racket/gui > (require framework) > (application:current-app-name "Sanskrit editor") > > (define main-frame (new frame:standard-menus% [label "Sanskrit editor"])) > > (send main-frame show #t) > (define main-area (send main-frame get-area-container)) > (define h-panel (new horizontal-panel% [parent > main-area][stretchable-height #f])) > (define msg (new message% [parent main-area][label "NO EVENTS SO FAR... > "])) > (define button-font (make-object font% 12 "Consolas" 'default 'normal > 'bold )) > (define button-1 (new button% [parent h-panel][font button-font] > [label "Apply Sandhi"] > ; Callback procedure for a button click: > [callback (lambda (button event) >(send msg set-label "TEST Apply Sandhi Test"))])) > > (define button-2 (new button% [parent h-panel][font button-font] > [label "HK-->Unicode"] > ; [style '(border)] > ; Callback procedure for a button click: > [callback (lambda (button event) >(send msg set-label "TEST Converted HK-->Unicode"))])) > > > (define main-text-editor (new text%)) > > (define default-delta (make-object style-delta%) ) > (send default-delta set-delta-face "Consolas") > (send default-delta set-size-add 4) > (send main-text-editor change-style default-delta) > (send main-text-editor set-max-undo-history 400) > (send main-text-editor auto-wrap #t) > > (define main-canvas (new editor-canvas% [parent main-area])) > (define WhiteSmokeColor (send the-color-database find-color "WhiteSmoke")) > (send main-canvas set-canvas-background WhiteSmokeColor) > (send main-canvas set-editor main-text-editor) > > -- > > > > > > > > > > . > > Racket Users list: http://lists.racket-lang.org/users
[racket] Help with racket/gui and framework
I'm building a small text editing application based around an editor built with racket/gui and framework.. The idea is that it has the usual text editing features but also buttons where I select text and then based on which button I click on the selected text is manipulated in different ways. I'm just building the gui part now. I started using just racket/gui but then tried to implement some things in "framework" but I'm having trouble with a few things and I can't figure out how to do them from the documentation. In the code below: 1) How do I add a "Save" feature to the file menu. 2) The "Open recent" menu item in the file menu opens my DrRacket "recently opened files". How do I get it to look at its own history instead of DrRackets. 3) Where I define main-frame as a frame:standard-menus% object in the code below, I tried to define it as a frame:editor% object but I couldn't get that to work. Could someone show me how to do that. Thanks, Harry - #lang racket/gui (require framework) (application:current-app-name "Sanskrit editor") (define main-frame (new frame:standard-menus% [label "Sanskrit editor"])) (send main-frame show #t) (define main-area (send main-frame get-area-container)) (define h-panel (new horizontal-panel% [parent main-area][stretchable-height #f])) (define msg (new message% [parent main-area][label "NO EVENTS SO FAR... "])) (define button-font (make-object font% 12 "Consolas" 'default 'normal 'bold )) (define button-1 (new button% [parent h-panel][font button-font] [label "Apply Sandhi"] ; Callback procedure for a button click: [callback (lambda (button event) (send msg set-label "TEST Apply Sandhi Test"))])) (define button-2 (new button% [parent h-panel][font button-font] [label "HK-->Unicode"] ; [style '(border)] ; Callback procedure for a button click: [callback (lambda (button event) (send msg set-label "TEST Converted HK-->Unicode"))])) (define main-text-editor (new text%)) (define default-delta (make-object style-delta%) ) (send default-delta set-delta-face "Consolas") (send default-delta set-size-add 4) (send main-text-editor change-style default-delta) (send main-text-editor set-max-undo-history 400) (send main-text-editor auto-wrap #t) (define main-canvas (new editor-canvas% [parent main-area])) (define WhiteSmokeColor (send the-color-database find-color "WhiteSmoke")) (send main-canvas set-canvas-background WhiteSmokeColor) (send main-canvas set-editor main-text-editor) -- . Racket Users list: http://lists.racket-lang.org/users
[racket] Adding "undo" and "redo" to racket/gui menu item
The following code from the racket/gui documentation gives me an "edit" menu with "copy', "cut","paste","select all","delete" working but "redo" and "undo" don't appear to be working. Do I have to add code to get "undo", "redo" to work in the "edit" menu. If so what code do I need to add? Thanks, Harry Spier - #lang racket/gui (define frame (new frame% [label "Example"])) (send frame show #t) (define c (new editor-canvas% [parent frame])) (define t (new text%)) (send c set-editor t) (define mb (new menu-bar% [parent frame])) (define m-edit (new menu% [label "Edit"] [parent mb])) (define m-font (new menu% [label "Font"] [parent mb])) (append-editor-operation-menu-items m-edit #t) (append-editor-font-menu-items m-font) - Racket Users list: http://lists.racket-lang.org/users
[racket] Realm of Racket in Barnes and Noble
I just came back from Barnes and Noble and Real of Racket is now in their Computer books section. Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] GUI buttons with & in label
OK I see whats happening. (windows 7) The button text is "&C" i.e. capital C "C" is not underlined when displayed typing "C" i.e. capital C does not click the button but typing "c" non-capital C does click the button On Mon, Jan 27, 2014 at 10:10 PM, Roman Klochkov wrote: > Windows XP, Racket 5.3.6 x86 > "C" on button is not underlined, but when press "C" on keyboard, button is > pressed. > > > Понедельник, 27 января 2014, 20:06 -08:00 от Danny Yoo < > d...@hashcollision.org>: > > Hi Harry, > > Potential platform-specific behavior? Appears to have expected > behavior on an Ubuntu Linux-based machine. > > Racket Users list: > http://lists.racket-lang.org/users > > > > -- > Roman Klochkov > Racket Users list: http://lists.racket-lang.org/users
[racket] GUI buttons with & in label
I'm using Racket 5.3.6 with windows and ran the following GUI program #lang racket/gui (define frame (new frame% [label "Example"])) (define msg (new message% [parent frame][label "No events so far..."])) (new button% [parent frame] [label "&Click Me"] ; Callback procedure for a button click: [callback (lambda (button event) (send msg set-label "Button click"))]) (send frame show #t) The documentation http://docs.racket-lang.org/gui/button_.html says: If & occurs in label (when label includes a string), it is specially parsed; on Windows and Unix, the character following & is underlined in the displayed control to indicate a keyboard mnemonic. (On Mac OS X, mnemonic underlines are not shown.) The underlined mnemonic character must be a letter or a digit. The user can effectively click the button by typing the mnemonic when the control’s top-level-window contains the keyboard focus. but for the above program "C" in the button label isn't underlined and typing "C" doesn't appear to be working as a keyboard mnemonic. I'm I doing something wrong or is this a bug? Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
[racket] Introduction to Parser Tools library
Dear list members, The documentation to the Parser Tools library assumes familiarity with lex and yacc style lexer and parser generators. Can someone recommend a good on-line tutorial to lex and yacc. Something I could go through but using Racket Parser Tools instead of lex and yacc. Or alternatively an inexpensive book. Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
[racket] Racket FFI to OpenOffice or LibreOffice API
1) Has anyone written a Racket FFI to either the OpenOffice or LibreOffice API ? 2) The interface is called UNO and from a very very brief look at the documentation it appears to be written in C++ but there is a tool that they say "maps all types to their corresponding C type declarations with a full qualified type name", See http://www.openoffice.org/udk/cpp/man/spec/cuno_spec.html Given that information should it be fairly straightforward to write a FFI to the UNO interface or because its written in C++ are there a lot of "gotchas" to look out for. I'm writing a bunch of macros for LibreOffice in Python but if its fairly straightforward to do a FFI (I'd just restrict it to the few interface calls I'm using) I might look at that and do my development in Racket instead of Python. Thanks, Harry . Racket Users list: http://lists.racket-lang.org/users
Re: [racket] s-expression syntax for regular expressions
Found it http://www.ccs.neu.edu/home/shivers/papers/sre.txt On Sun, Dec 29, 2013 at 2:50 PM, Harry Spier wrote: > > A while ago I found a link in a post in the Racket user forum to an > article where a CS prof was describing a suggested a new syntax for regular > expressions based on s-expressions. But I haven't been able to locate it > in the forum again. > > If anyone knows the link I'm talking about could they post it please. > > Thanks, > Harry > Racket Users list: http://lists.racket-lang.org/users
[racket] s-expression syntax for regular expressions
A while ago I found a link in a post in the Racket user forum to an article where a CS prof was describing a suggested a new syntax for regular expressions based on s-expressions. But I haven't been able to locate it in the forum again. If anyone knows the link I'm talking about could they post it please. Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Creating PDF files in Racket
Thanks Jens, Looking at this cairo documentation page I think that Cairo always embeds fonts. https://www.rforge.net/doc/packages/Cairo/Cairo.html .. "Cairo initializes a new graphics device that uses the cairo graphics library for rendering. The current implementation produces high-quality PNG, JPEG, TIFF bitmap files, *high resolution PDF files with embedded fonts*," .. Arguments ... type output type. This version of Cario supports "png", "jpeg" and "tiff" bitmaps (png/tiff with transparent background), "pdf" PDF-file with embedded fonts, .. On Tue, Dec 10, 2013 at 1:10 PM, Jens Axel Søgaard wrote: > 2013/12/10 Harry Spier : > > Thank you John for your example below. I'm still not clear where (if > > possible) the parameter is for whether the font is embedded in the PDF > > document or not. Is the font embedded by default. > > I think it depends on the type of font. I found this in the changelog for > Cairo 1.2.0 (and Racket uses 1.10.x). > > And in the PDF and PostScript backends, both type1 and TrueType fonts > will be directly embedded in the output file. This results in > higher-quality > previews and better performance. > > /Jens Axel > Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Creating PDF files in Racket
Thank you John for your example below. I'm still not clear where (if possible) the parameter is for whether the font is embedded in the PDF document or not. Is the font embedded by default. Thanks, Harry --- Does this get you started? --- #lang racket (require racket/draw) (define (text->pdf text output-file) (define font (make-font #:size 14 #:size-in-pixels? #t #:face "Mono")) (define (up-int x) (inexact->exact (ceiling x))) (define (make-bm w h) (make-object bitmap% w h #f #t)) (define lines (regexp-split "\n" text)) (define dc (new pdf-dc% [ interactive #f ] [ use-paper-bbox #f ] [ width 592 ] [ height 756 ] [ output output-file ])) (send* dc (start-doc "useless string") (start-page)) (send dc set-font font) (let loop ((lines lines) (width 0) (height 0)) (when (pair? lines) (let-values (((w h d v) (send dc get-text-extent (car lines (send dc draw-text (car lines) 0 height) (loop (cdr lines) (max width (up-int w)) (+ 5 height (up-int h)) (send* dc (end-page) (end-doc))) - On Mon, Dec 9, 2013 at 11:58 AM, Harry Spier wrote: > > In Racket is it possible to convert a unicode text file into a PDF file > with an embedded unicode font. This is for an on-line digital library > application where I want to create the PDF file on the fly when the user > requests that output format. > > Thanks, > Harry > Racket Users list: http://lists.racket-lang.org/users
[racket] Creating PDF files in Racket
In Racket is it possible to convert a unicode text file into a PDF file with an embedded unicode font. This is for an on-line digital library application where I want to create the PDF file on the fly when the user requests that output format. Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
Re: [racket] specifying strings without escaping backslash
Thank you Eli that works perfectly. I'm really just playing around getting back into Racket On Thu, Dec 5, 2013 at 5:24 PM, Eli Barzilay wrote: > Yesterday, Laurent wrote: > > Or better here: @values{C:\Users\Harry\SANSKRIT\GRETIL > > ALL\adyappu.htm} to avoid the superfluous ~a operation. > > Using `values' is not a good idea since it works only if you don't use > nested @s or newlines. If these things are included, you'll end up > with a form that is equivalent to (values x y z) and things will > probably break in a confusing way. > > > > I've just surprised myself testing @(...){...} and seeing that it > > works: @(lambda(x)x){C:\Users\Harry\SANSKRIT\GRETIL ALL\adyappu.htm} > > That's intentional, and more than that, any form can be used including > @-forms, which means that to write a function that takes in two blocks > of text you can do something like this: > > @(define ((foo . text1) . text2) ...stuff...) > > @@foo{some text}{some more text} > > (This is a simplified example again, where you just get a single > argument, but in the general case you'd have multiple inputs for both > texts.) > > > Yesterday, Harry Spier wrote: > > > > 2) > > What am I doing wrong here. -- everything :-) > > I'm trying to change the command character from @ to # so that I > > can have raw strings containing both \ and @ looking at the racket > > documentation here: > > http://docs.racket-lang.org/scribble/reader-internals.html?q=at-exp# > > %28def._%28%28lib._scribble%2Freader..rkt%29._make-at-readtable%29%29 > > [...] > > It's possible to do that, though you'll need to implement your own > reader. Not too hard, since the scribble/reader functionality can > build the appropriate table, but two notes before you go that route: > > 1. Overriding "#" is a bad idea, since it has special meaning in >Racket code. Some obvious examples that you'll lose are boolean >literals, vector literals, and the convention that "#<" is an >unreadable value -- a convention that can lead to copy/paste >surprises if broken. > > 2. If you want to include more free-form text, there's a reader >feature that allows you to use customized tokens: > > @foo|{ some text including @s }| > >to use nested forms, you'd need to use "|@". If that's not enough, >then you can also include more things between the braces and the >bars: > > @foo|==!!=={ even more free text, including @|s etc }==!!| > > > Yesterday, Greg Hendershott wrote: > > I have @~a{} in muscle memory because it's handy for a variety of > > purposes, including as an alternative to format/printf. > > > > #lang at-exp racket > > > > (define x 1) > > (define y 10) > > > > (format "x is ~a, y is ~a, and x + y is ~a" x y (+ x y)) > > ;; or > > @~a{x is @x, y is @y, and x + y is @(+ x y)} > > > > ;; both => "x is 1, y is 10, and x + y is 11" > > Allowing such things was very intentional in the design... The > `scribble/text' language goes further in that it allows many more > things in the contents for printing. There's no to-string form for it > though, since I wasn't sure that it's a good idea -- mostly because > people would be tempted to do something like > > (display @to-string{stuff}) > > where a long string gets allocated for no good reason. Using `output' > instead usually looks like this: > > (output @list{ > anything you want > }) > > since lists are just scanned recursively by `output'. As a side note, > this use of lists makes some things very convenient -- instead of > tricky code that uses `append-map' or `format's, `string-append's and > `~a's, you just use lists, nesting them as much as you want. > > > > p.s. I believe > http://www.mail-archive.com/users@racket-lang.org/msg07162.html > > predates `~a` being added to Racket. > > (It does.) > > -- > ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: > http://barzilay.org/ Maze is Life! > Racket Users list: http://lists.racket-lang.org/users
Re: [racket] specifying strings without escaping backslash
On Thu, Dec 5, 2013 at 2:30 AM, Laurent wrote: > On Wed, Dec 4, 2013 at 11:47 PM, Harry Spier wrote: > >> 2) >> What am I doing wrong here. -- everything :-) >> I'm trying to change the command character from @ to # so that I can >> have raw strings containing both \ and @ >> looking at the racket documentation here: >> >> http://docs.racket-lang.org/scribble/reader-internals.html?q=at-exp#%28def._%28%28lib._scribble%2Freader..rkt%29._make-at-readtable%29%29 >> >> I've done this: >> >> #lang at-exp racket >> (require scribble/reader) >> (use-at-readtable #:command-char #\#) >> (define RAW string-append) >> (display #RAW{C:\Users\Harry\SANSKRIT\GRETIL ALL\adyappu.htm}) >> (display #RAW{harrysp...@hotmail.com}) >> > > I don't know enough about readtables to help you here, but it seems that > `use-at-readtable' is only for the REPL: > > http://docs.racket-lang.org/scribble/reader-internals.html?q=use-read-table#%28def._%28%28lib._scribble%2Freader..rkt%29._use-at-readtable%29%29 > > Yes it works with the REPL -- DEFINITIONS WINDOW #lang at-exp racket (require scribble/reader) (use-at-readtable #:command-char #\#) (define RAW string-append) INTERACTIONS WINDOW Welcome to DrRacket, version 5.3.6 [3m]. Language: at-exp racket [custom]; memory limit: 1024 MB. > (display #RAW{harrysp...@hotmail.com}) harrysp...@hotmail.com > - > Someone ought to build the `at-any-exp' language Matthew was talking about > a few days ago, so that one can write > #lang at-any-exp $ racket > $~a{Yay, dollar-exp syntax!} > > Laurent > > Racket Users list: http://lists.racket-lang.org/users
Re: [racket] specifying strings without escaping backslash
Thanks everyone, The @ syntax does what I want. After I asked the question I found the answer on the Racket list. The below based on this http://www.mail-archive.com/users@racket-lang.org/msg07162.html --- #lang at-exp racket (define RAW string-append) (display @RAW{C:\Users\Harry\SANSKRIT\GRETIL ALL\adyappu.htm}) -- 2) What am I doing wrong here. -- everything :-) I'm trying to change the command character from @ to # so that I can have raw strings containing both \ and @ looking at the racket documentation here: http://docs.racket-lang.org/scribble/reader-internals.html?q=at-exp#%28def._%28%28lib._scribble%2Freader..rkt%29._make-at-readtable%29%29 I've done this: #lang at-exp racket (require scribble/reader) (use-at-readtable #:command-char #\#) (define RAW string-append) (display #RAW{C:\Users\Harry\SANSKRIT\GRETIL ALL\adyappu.htm}) (display #RAW{harrysp...@hotmail.com}) On Wed, Dec 4, 2013 at 9:41 AM, Laurent wrote: > > On Wed, Dec 4, 2013 at 1:21 PM, Greg Hendershott < > greghendersh...@gmail.com> wrote: > >> If you don't mind using `#lang at-exp racket`, I think you could write >> >> @~a{C:\Users\Harry\SANSKRIT\GRETIL ALL\adyappu.htm} >> > > Or better here: @values{C:\Users\Harry\SANSKRIT\GRETIL ALL\adyappu.htm} to > avoid the superfluous ~a operation. > Of course if used often, it can be abbreviated. > > I've just surprised myself testing @(...){...} and seeing that it works: > @(lambda(x)x){C:\Users\Harry\SANSKRIT\GRETIL ALL\adyappu.htm} > > Laurent > > Racket Users list: http://lists.racket-lang.org/users
[racket] specifying strings without escaping backslash
Are "here strings" the only way to specify strings that don't escape backslash. Is there a way to do it in one line instead of three like: (string->path #< Racket Users list: http://lists.racket-lang.org/users
[racket] DrRacket Helpdesk
Dear list members, Why in the DrRacket help menu is there both a "helpdesk" and a "Racket Documentation" button. AFAICT they both do the same thing, bring up the Racket documentation webpage. Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Transferring DrRacket preferences
Thanks Robby. Its not 'prefs-file but 'pref-file . I got an error but then clicked on find-system-path in DrRacket which took me to the documentation. Great feature! Cheers, Harry On Mon, Nov 25, 2013 at 6:50 PM, Robby Findler wrote: > You should be able to run > > (find-system-path 'prefs-file) > > on both machines to find the source and destination for the file. > > It is possible that this will cause runtime errors, but those would all be > bugs, so if you let us know about them, we'll fix them (and, in general, it > is easy to remove specific preferences from the file to get back to the > default version of those prefs). > > Robby > > > > On Mon, Nov 25, 2013 at 6:50 PM, Harry Spier > wrote: > > > > > > I've just downloaded Racket to a new laptop and I want to transfer my > DrRacket preferences from my old laptop to the new. The Racket version on > the old laptop is 5.3.3 windows x86-32 bit, on the new one its windows > x86-64. > > > > Is there a preferences file that I can just transfer from the old laptop > to the new to do this. > > > > Thanks, > > Harry Spier > > > > > > Racket Users list: > > http://lists.racket-lang.org/users > > > Racket Users list: http://lists.racket-lang.org/users
[racket] Transferring DrRacket preferences
I've just downloaded Racket to a new laptop and I want to transfer my DrRacket preferences from my old laptop to the new. The Racket version on the old laptop is 5.3.3 windows x86-32 bit, on the new one its windows x86-64. Is there a preferences file that I can just transfer from the old laptop to the new to do this. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] How to read procedure documentation?
Can someone recommend a good book on type systems? Is "The Little MLer" a good place to start and can you do this book with typed Racket rather than ML. Thanks, Harry Spier On Fri, Apr 19, 2013 at 5:27 PM, Matthias Felleisen wrote: > > On Apr 19, 2013, at 4:02 PM, Manfred Lotz wrote: > > > But it is more powerful. > > > [[ This is a quibble that could take you off your chosen path for years. > The words 'more powerful' aren't that easy to agree with. Here are ways > to make them incorrect: > -- in a sound type system, the type signature f : int -> int means that > when you launch your program, f will never, ever be applied to a > bit string that represents a boolean. Our contract cannot guarantee > this much. It will only guarantee that when f is applied to #true, > an exn:fail:contract is signaled. > -- our contract system has a really hard time expressions g : ∀ t : t -> > t. > In a sound type system, assigning this forall type to g means that > for > all possible types T in your module or types in modules linked to > yours, > possibly written in the distant future, the function assumes > signature > T -> T. If you equip g with an analogous contract in our world, the > guarantee you get is that if g tries to misbehave -- by probing the > given argument, it (g) will not behave as you expect. > -- and lastly, you can easily imagine that proof systems can answer much > more complex questions than Turing machines, and that you can > design > a type system that corresponds to such a proof system. Of course, > you > would then not necessarily use algorithms to check your type > correctness. > As I said, studying this question may take you off the beaten track, but I > think > people on this mailing list should be as informed as people on the Haskell > or > ML lists. ]] > > > > > Racket Users list: > http://lists.racket-lang.org/users > Racket Users list: http://lists.racket-lang.org/users
[racket] OFFTOPIC - Quote on Programming
I found this quote on a blog and couldn't help sharing it :-) "Debugging is twice as hard as writing the code in the first place. Therefore if you write the code as cleverly as possible, you are by definition not smart enough to debug it." Brian Kernigan Racket Users list: http://lists.racket-lang.org/users
[racket] parallel-map, for/parallel etc.
This post from May 2011 says: "parallel-for-each, parallel-sort, parallel-filter, for/parallel and the likes for sequences. ... are next on our radar." Are there still plans to develop these parallel processing functions. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Places performance
On Fri, Mar 15, 2013 at 3:31 AM, Tobias Hammer wrote: > I see that you left the placement of (time ...) unchanged in your > with-places code. You should really exclude the (place ..)-call from your > measurement. > It is not fair to compare a simple loop vs. the creation of two full > racket instances + the loop. See my last mail for a 'fairer' version. > I did that to get a feel for the overheads involved with places. My application should be highly parallisable and right now I'm just experimenting to see how best to do that, which also includes looking at the overheads in doing things different ways and experimenting on how best to reduce them. > > In a real program you should recycle places to create them only once (e.g > one per core) and then send them new work items via channels. > I did in fact do that in one of my experiments setting up a for loop that used multiple places to process multiple elements of a sequence in parallel but I found that the overhead of all the place-channel-gets and place-channel-puts made it very very much slower than a regular for loop without places. So I'm also trying to refine the overhead in that scenario. I'm experimenting trying to see how best to get rid of excessive overheads. I find I learn best by making all the naive mistakes and then fixing them. Cheers, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Places performance
On Thu, Mar 14, 2013 at 10:25 PM, Robby Findler wrote: > > > (You may find dynamic-place more useful for larger examples.) > > Given a module "place-caller.rkt" containing the statement (dynamic-place "place-worker.rkt" 'place-main))]) When the dynamic-place is executed and a new racket instance is created is only "place-caller.rkt" required in the new place, or "place-caller" and "place-worker" required in the new instance, or only "place-worker.rkt" required in the new instance. Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Places performance
(define place2 (place ch (begin (place-channel-put ch #t) (place-channel-put ch (test-function test-vector) (place-channel-get place1) (place-channel-get place2) (place-channel-get place1) (place-channel-get place2) (place-wait place1) (place-wait place2) (void)) (define (noplaces-main) (test-function test-vector) (test-function test-vector) (void)) On Thu, Mar 14, 2013 at 8:28 AM, Tobias Hammer wrote: > As Robby said, the time should only include both place-channel-get and > -put calls to make it comparable. > But this is not enough, because the (place ...)-creation seems to be > non-blocking, i.e they might not be started up yet when the codes reached > the first -put. > > This can be solved by explicitly synchronizing the places with the main > program: > > > (define (places-main) > (define place1 >(place ch > (begin > (place-channel-put ch #t) > (place-channel-put ch (test-function (place-channel-get > ch)) > > (define place2 > (place ch >(begin > (place-channel-put ch #t) > (place-channel-put ch (test-function (place-channel-get > ch)) > > (place-channel-get place1) > (place-channel-get place2) > > > (display "With places ") > (time > (place-channel-put place1 test-vector) > (place-channel-put place2 test-vector) > (place-channel-get place1) > (place-channel-get place2)) > > (place-wait place1) > (place-wait place2) > (void)) > > > With this i get the following times > > With places cpu time: 5600 real time: 3199 gc time: 404 > Without places cpu time: 3700 real time: 3678 gc time: 2208 > > Now its at least faster than the sequential version. But the overhead > seems to be still a lot more than i had expected. > > Tobias > > > > > On Thu, 14 Mar 2013 02:23:22 +0100, Harry Spier > wrote: > > Dear members, >> >> I've run the following racket program (as an executable) to test the >> performance of places on a windows dual core pentium machine under Vista. >> I've run this with various sizes for test-vector. Even when the amount >> of >> computation is large (test-vector-size = 500) the performance with the >> computation split over two places takes more than double the time to >> complete as when no places are used. >> >> I'm not clear why on a dual core machine the performance wasn't better >> with >> the computation split over two places than with no places. In fact the >> results are the opposite with the performance for no places always double >> that for two places. >> >> -- >> place-timing-test-executable.rkt >> --- >> #lang racket >> (require "place-timing-test.rkt") >> (printf "test-vector-size ~a" test-vector-size) >> (newline) >> (display "With places ") >> (time (places-main)) >> (display "Without places ") >> (time (noplaces-main)) >> >> (system "PAUSE") >> >> >> --- >> place-timing-test.rkt >> --- >> #lang racket >> (provide places-main noplaces-main test-vector-size) >> (define test-vector (build-vector 500 +)) >> (define test-vector-size (vector-length test-vector)) >> (define (test-function vectr) (apply + (vector->list (vector-map sqrt >> vectr >> >> (define (places-main) >> (define place1 >>(place ch (place-channel-put ch (test-function (place-channel-get >> ch) >> >> (define place2 >> (place ch (place-channel-put ch (test-function (place-channel-get >> ch) >> >> (place-channel-put place1 test-vector) >> (place-channel-put place2 test-vector) >> (place-channel-get place1) >> (place-channel-get place2) >> (place-wait place1) >> (place-wait place2) >> (void)) >> >> (define (noplaces-main) >> (test-function test-vector) >> (test-function test-vector) >> (void) >> --- >> >> These are the results for different sizes of test-vector. The amount of >> computation is linear to the size of test-vector. >> >> test-vector-size 10 >> With places cpu time: 1685 real time: 856 gc time: 0 >> Without places cpu time: 187 real time: 170 gc time: 94 >> Press any key to continue . . . >> - >> test-vector-size 100 >> With places cpu time: 3822 real time: 2637 gc time: 265 >> Without places cpu time: 1201 real time: 1191 gc time: 452 >> Press any key to continue . . . >> --- >> test-vector-size 500 >> With places cpu time: 15787 real time: 23318 gc time: 1373 >> Without places cpu time: 7769 real time: 9456 gc time: 4461 >> Press any key to continue . . . >> -- >> >> Thanks, >> Harry Spier >> > > > -- > - > Tobias Hammer > DLR / Institute of Robotics and Mechatronics > Muenchner Str. 20, D-82234 Wessling > Tel.: 08153/28-1487 > Mail: tobias.ham...@dlr.de > Racket Users list: http://lists.racket-lang.org/users
[racket] Places performance
Dear members, I've run the following racket program (as an executable) to test the performance of places on a windows dual core pentium machine under Vista. I've run this with various sizes for test-vector. Even when the amount of computation is large (test-vector-size = 500) the performance with the computation split over two places takes more than double the time to complete as when no places are used. I'm not clear why on a dual core machine the performance wasn't better with the computation split over two places than with no places. In fact the results are the opposite with the performance for no places always double that for two places. -- place-timing-test-executable.rkt --- #lang racket (require "place-timing-test.rkt") (printf "test-vector-size ~a" test-vector-size) (newline) (display "With places ") (time (places-main)) (display "Without places ") (time (noplaces-main)) (system "PAUSE") --- place-timing-test.rkt --- #lang racket (provide places-main noplaces-main test-vector-size) (define test-vector (build-vector 500 +)) (define test-vector-size (vector-length test-vector)) (define (test-function vectr) (apply + (vector->list (vector-map sqrt vectr (define (places-main) (define place1 (place ch (place-channel-put ch (test-function (place-channel-get ch) (define place2 (place ch (place-channel-put ch (test-function (place-channel-get ch) (place-channel-put place1 test-vector) (place-channel-put place2 test-vector) (place-channel-get place1) (place-channel-get place2) (place-wait place1) (place-wait place2) (void)) (define (noplaces-main) (test-function test-vector) (test-function test-vector) (void) --- These are the results for different sizes of test-vector. The amount of computation is linear to the size of test-vector. test-vector-size 10 With places cpu time: 1685 real time: 856 gc time: 0 Without places cpu time: 187 real time: 170 gc time: 94 Press any key to continue . . . - test-vector-size 100 With places cpu time: 3822 real time: 2637 gc time: 265 Without places cpu time: 1201 real time: 1191 gc time: 452 Press any key to continue . . . --- test-vector-size 500 With places cpu time: 15787 real time: 23318 gc time: 1373 Without places cpu time: 7769 real time: 9456 gc time: 4461 Press any key to continue . . . -- Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Places crashing DrRacket
Apologies again, Section 18.13 guide explains this: " ; Don't do this! (define p (place ch (place-channel-get ch))) " Harry Spier On Wed, Mar 13, 2013 at 5:56 PM, Harry Spier wrote: > Dear list members, > > This minimal code snippet crashes DrRacket. > -- > #lang racket > (define test-vector #(0 1 2 3 4 5 6 7 8 9)) > (define (test-function vectr) (apply + (vector->list (vector-map sqrt > vectr > > (define place1 > (place ch (place-channel-put ch (test-function (place-channel-get ch) > > > When run in DrRacket (windows Vista Pentium dual core) it executes, the > prompt appears in the interactions window and then about 5 or 10 seconds > later I get a "program terminated .... ran out of memory" DrRacket popup > window. > > Thanks, > Harry Spier > Racket Users list: http://lists.racket-lang.org/users
[racket] Places crashing DrRacket
Dear list members, This minimal code snippet crashes DrRacket. -- #lang racket (define test-vector #(0 1 2 3 4 5 6 7 8 9)) (define (test-function vectr) (apply + (vector->list (vector-map sqrt vectr (define place1 (place ch (place-channel-put ch (test-function (place-channel-get ch) When run in DrRacket (windows Vista Pentium dual core) it executes, the prompt appears in the interactions window and then about 5 or 10 seconds later I get a "program terminated ran out of memory" DrRacket popup window. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Places and submodules
Apologies, I see the problem now. I missed where it says in the documentation for dynamic-places. "The module-path argument must not be a module path of the form (quote sym) unless the module is predefined (see module-predefined?)." Harry Spier On Tue, Mar 12, 2013 at 12:33 AM, Harry Spier wrote: > Dear list members, > > I'm going through the documentation on "places". The example in the > reference manual 10.5 works as described but when instead of having the > code in two modules in separate files as in the example, I use submodules > as follows, > -- > #lang racket > (module temp2 racket > (provide place-main) > > (define (place-main pch) > (place-channel-put pch (format "Hello from place ~a" > (place-channel-get pch) > > (require 'temp2) > > (let ([pls (for/list ([i (in-range 2)]) > (dynamic-place 'temp2 'place-main))]) > (for ([i (in-range 2)] > [p pls]) > (place-channel-put p i) > (printf "~a\n" (place-channel-get p))) > (map place-wait pls)) > > - > > I get the following error message. > > standard-module-name-resolver: collection not found > collection: "temp2" > in collection directories: > C:\Users\Harry\AppData\Roaming\Racket\5.3.3\collects > C:\Program Files\Racket\collects > context...: > standard-module-name-resolver > standard-module-name-resolver: collection not found > collection: "temp2" > in collection directories: > C:\Users\Harry\AppData\Roaming\Racket\5.3.3\collects > C:\Program Files\Racket\collects > context...: > standard-module-name-resolver > > Can someone explain why this error? > > Thanks, > Harry Spier > > Racket Users list: http://lists.racket-lang.org/users
[racket] Places and submodules
Dear list members, I'm going through the documentation on "places". The example in the reference manual 10.5 works as described but when instead of having the code in two modules in separate files as in the example, I use submodules as follows, -- #lang racket (module temp2 racket (provide place-main) (define (place-main pch) (place-channel-put pch (format "Hello from place ~a" (place-channel-get pch) (require 'temp2) (let ([pls (for/list ([i (in-range 2)]) (dynamic-place 'temp2 'place-main))]) (for ([i (in-range 2)] [p pls]) (place-channel-put p i) (printf "~a\n" (place-channel-get p))) (map place-wait pls)) - I get the following error message. standard-module-name-resolver: collection not found collection: "temp2" in collection directories: C:\Users\Harry\AppData\Roaming\Racket\5.3.3\collects C:\Program Files\Racket\collects context...: standard-module-name-resolver standard-module-name-resolver: collection not found collection: "temp2" in collection directories: C:\Users\Harry\AppData\Roaming\Racket\5.3.3\collects C:\Program Files\Racket\collects context...: standard-module-name-resolver Can someone explain why this error? Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Realm of Racket
These videos are great!! Cheers, Harry On Fri, Feb 8, 2013 at 8:10 AM, Matthias Felleisen wrote: > > > NoStarch and O'Reilly agreed to take our cover and use it for advertising. > In celebration, we released another video: > > http://realmofracket.com/videos.html > > Enjoy! -- Matthias > > > > Racket Users list: > http://lists.racket-lang.org/users > Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Visitor Pattern and Racket
Good point! I missed that. Cheers, Harry On Sun, Jan 20, 2013 at 8:39 PM, Stephen Bloch wrote: > > On Jan 20, 2013, at 7:55 PM, Harry Spier wrote: > >> Example 1: gives correct answer >> (define shish-c (new onion% [sh (new onion% [sh (new lamb% [sh (new >> skewer%)])])])) >> (send shish-c only-onions? ) >> >> Example 2: gives incorrect answer >> (define shish-c (new onion% [sh (new onion% [sh (new skewer% [sh (new >> lamb%)])])])) >> (send shish-c only-onions? ) >> >> Is it possible to make a contract that will flag example 2 as a >> contract violation? > > Doesn't the constructor for lamb% expect an argument? In this data > structure, the only base case is skewer%, so the only legal way to build a > shish-kebab is with a skewer at the end. > > > Stephen Bloch > sbl...@adelphi.edu > Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Visitor Pattern and Racket
On Sun, Jan 20, 2013 at 6:25 PM, Matthias Felleisen wrote: > > Normal OOPLs suffer from a lack of expressiveness. > OO programmers make up for this lack with programming > patterns. If you don't have first-class functions, > simulate them with the command pattern. If you don't > have functions but you want to emphasize functional > style, use the visitor pattern. > > The extensible visitor pattern is the only contribution > in the book that is of some interest to Racket programmers. > But we have units and mixins, and we can do this thing > even better. > > Once we have types for these, the question becomes whether > the type system will be strong enough to get away without > the one ugly cast. > Many thanks Matthias. 1) What I found useful in the book is the way it shows recursion with OOP, I had never seen this before. About the recursion in the book. The examples so far all depend on the last object in the recursion being a particular class to end the recursion. For example to use the shish-kabob example, I can construct the following two shish-kabob but only the first gives the correct answer because the recursion ends in skewer%, Example 1: gives correct answer (define shish-c (new onion% [sh (new onion% [sh (new lamb% [sh (new skewer%)])])])) (send shish-c only-onions? ) Example 2: gives incorrect answer (define shish-c (new onion% [sh (new onion% [sh (new skewer% [sh (new lamb%)])])])) (send shish-c only-onions? ) Is it possible to make a contract that will flag example 2 as a contract violation? 2) Regarding types, I see that "The Little MLer" is about types. Would it be useful for a Racket programmer who only knows C types, to go through "the little MLer" but using typed Racket instead of ML. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Is this a bug in contracts?
On Wed, Jan 16, 2013 at 8:49 PM, Matthias Felleisen wrote: > First, you mistakenly have the class inherit from itself. You want object% in the super-class position in both cases. > Sorry I meant object% as superclass' > Second, you don't get to formulate contracts like that. We have flat-rec-contracts but a class contract is a higher-order contract because a class is like a function. > I'm not clear Is this contract still wrong? #lang racket (define/contract pizza-D% (class/c [init-field (p (is-a?/c pizza-D%))]) (class object% (super-new) (init-field p))) Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Is this a bug in contracts?
On Mon, Jan 14, 2013 at 9:27 AM, Matthias Felleisen wrote: > > And Harry, do define certain contracts separately, e.g., > > (define shish/c (is-a?/c shish-D%)) > If my class has a field of the same class is there a way to do that? I.e. both case 1 and case 2 fail on undefined identifier Case 1 #lang racket (define pizza-D%/c (is-a?/c pizza-D%)) (define/contract pizza-D% (class/c [init-field (p pizza-D%/c)]) (class pizza-D% (super-new) (init-field p))) Case 2 #lang racket (define/contract pizza-D% (class/c [init-field (p pizza-D%/c)]) (class pizza-D% (super-new) (init-field p))) (define pizza-D%/c (is-a?/c pizza-D%)) Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Is this a bug in contracts?
Thanks, you guys are great! On Mon, Jan 14, 2013 at 9:27 AM, Matthias Felleisen wrote: > > And Harry, do define certain contracts separately, e.g., > > (define shish/c (is-a?/c shish-D%)) > > > > On Jan 14, 2013, at 12:24 AM, Asumu Takikawa wrote: > >> On 2013-01-13 22:02:44 -0500, Harry Spier wrote: >>> Is this a bug in contracts? When I ran the following code the >>> contract in onion% didn't give me an error, yet the contract is on an >>> "init sh" but the class doesn't have an "init sh" it has an >>> "init-field sh". See the line with the comment ;THIS LINE SHOULD >>> USE init-field not init >> >> No, this should be correct. An `init` specifies a subset of `init-field` >> (it's not mutually exclusive with it). >> >>> (define/contract onion% >>> (class/c [init (sh (is-a?/c shish-D%))]) ;THIS LINE SHOULD USE >>> init-field not init >>> (class shish-D% (super-new) >>>(init-field sh) >>>(define/override (only-onions?) >>> (and (send sh only-onions?) #t >>> >>> (send (new onion% [sh (new onion% [sh (new skewer%)])]) only-onions?) >> >> Notice here that if we change this to: >> >> (send (new onion% [sh 5]) only-onions?) >> >> A contract error is raised appropriately because the init argument was >> wrong, so the contract is clearly protecting the init argument. This is >> the correct behavior, because an `init-field` clause just defines both >> an init argument and a field. The class system doesn't track a separate >> `init-field` thing. If you only specify the init contract, it only >> protects the init part. >> >> If you set the field like this: >> >> (set-field! sh (new onion% [sh (new onion% [sh (new skewer%)])]) 5) >> >> It does not raise a contract error. If you want to protect both, you >> either need to revise the contract to >> >> (class/c [init-field (sh (is-a?/c shish-D%))]) >> >> or >> >> (class/c [init (sh (is-a?/c shish-D%))] >> [field (sh (is-a?/c shish-D%))]) >> >> Cheers, >> Asumu >> >> Racket Users list: >> http://lists.racket-lang.org/users > Racket Users list: http://lists.racket-lang.org/users
[racket] Is this a bug in contracts?
Is this a bug in contracts? When I ran the following code the contract in onion% didn't give me an error, yet the contract is on an "init sh" but the class doesn't have an "init sh" it has an "init-field sh". See the line with the comment ;THIS LINE SHOULD USE init-field not init Thanks, Harry #lang racket (define shish-D% (class object% (super-new) (abstract only-onions?))) (define skewer% (class shish-D% (super-new) (define/override (only-onions?) #t))) (define/contract onion% (class/c [init (sh (is-a?/c shish-D%))]) ;THIS LINE SHOULD USE init-field not init (class shish-D% (super-new) (init-field sh) (define/override (only-onions?) (and (send sh only-onions?) #t (send (new onion% [sh (new onion% [sh (new skewer%)])]) only-onions?) Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Typed Racket and classes and objects
Thanks Matthias. BTW I find changing the Java examples to Racket very instructive and makes me appreciate the clarity of Racket. Cheers, Harry On Sun, Jan 13, 2013 at 12:14 PM, Matthias Felleisen wrote: > > Not yet. We are in the process of adding a gradual type system that deals > with our classes, but we're not beyond the paper design phase. You can do one > of two things: > > (1) use define/contract for the classes and formulate the types as contracts. > You don't get compile-time checking but run-time checking then. > > (2) Use comments to write down the types and forgo any checking whatsoever. > > Your milage will vary. I think I'd go for option 1 even if this is a lot of > keyboard-typing. -- Matthias > > > > On Jan 12, 2013, at 7:49 PM, Harry Spier wrote: > >> I've started going through "A Little Java a Few Patterns" to learn >> some basic OOP techniques and patterns but I've been using Racket >> instead of Java (I don't know Java so I'd prefer to stick with >> Racket). Is it possible to use Typed Racket instead of Racket with >> classes and objects, so I can put types on the class arguments and >> values the methods return, similar to what the Java based examples do? >> >> Thanks, >> Harry Spier >> >> Racket Users list: >> http://lists.racket-lang.org/users > Racket Users list: http://lists.racket-lang.org/users
[racket] Typed Racket and classes and objects
I've started going through "A Little Java a Few Patterns" to learn some basic OOP techniques and patterns but I've been using Racket instead of Java (I don't know Java so I'd prefer to stick with Racket). Is it possible to use Typed Racket instead of Racket with classes and objects, so I can put types on the class arguments and values the methods return, similar to what the Java based examples do? Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] Declaring methods and fields with internal and external names
The Racket reference says: 5.2.3.3 Internal and External Names Each method declared with public, override, augment, pubment, overment, augride, public-final, override-final, augment-final, inherit, inherit/super, inherit/inner, rename-super, and rename-inner can have separate internal and external names when (internal-id external-id) is used for declaring the method. The internal name is used to access the method directly within the class expression (including within super or inner forms), while the external name is used with send and generic (see Field and Method Access). If a single id is provided for a method declaration, the identifier is used for both the internal and external names. ... ... Each init, init-field, field, or inherit-field variable similarly has an internal and an external name. --- I'm still unclear how to do this. If a list member could show me a simple example of declaring a method and also a field with separate internal and external names I'd greatly appreciate it. Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] OFF TOPIC - article in NY Times - programming errors in stock exchange software
http://www.nytimes.com/2013/01/11/business/in-new-year-errors-mount-at-high-speed-exchanges.html?hpw Racket Users list: http://lists.racket-lang.org/users
Re: [racket] init and init-field
Thanks Asumu. Thats clear now. I'm wondering if it might be a good idea to make a small side note stating this in the Racket Guide where it has the first example at the start of Classes and Objects where it uses "init". Cheers, Harry On Wed, Jan 9, 2013 at 4:45 PM, Asumu Takikawa wrote: > On 2013-01-09 16:37:17 -0500, Asumu Takikawa wrote: > To be a bit more precise, a field declared with `field`/`init-field` is > always public. A field declared with `define` is private. > > Cheers, > Asumu Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Overriding methods in Racket classes
Sorry -- typo in my code, my last email should read: OK using define-local-member-name works, see case 1 below, but it seems it would be much simpler if there was a form define/inheritable which made the method accessable within the class body where it was defined and in the sub-class bodies only. (see case 2 below) i.e. no wrapping in a let that returned multiple values etc. Is there some reason there isn't such a form define/inheritable ? === Case 1 (using define-local-member-name) = #lang racket (define-values (fish% picky-fish%) (let () (define-local-member-name grow) (define fish% (class object% (init size); initialization argument (define current-size size) ; field (super-new); superclass initialization (define/public (get-size) current-size) (define/public (grow amt) (set! current-size (+ amt current-size))) (define/public (eat other-fish) (grow (send other-fish get-size) (define picky-fish% (class fish% (super-new) (define/override (grow amt) (super grow (* 3/4 amt) (values fish% picky-fish%))) (define joe-the-minnow (new fish% [size 2])) (define bud-the-minnow (new fish% [size 2])) (define big-al-the-pike (new fish% [size 10])) (define picky-selma (new picky-fish% [size 5])) (send picky-selma eat joe-the-minnow) (send picky-selma get-size) ;;this now correctly fails ;(send bud-the-minnow grow 5) (Case 2 using a hypothetical define/inheritable) #lang racket (define fish% (class object% (init size) (define current-size size) (super-new) (define/public (get-size) current-size) (define/inheritable (grow amt) ;;;hypothetical define/inheritable (set! current-size (+ amt current-size))) (define/public (eat other-fish) (grow (send other-fish get-size) (define picky-fish% (class fish% (super-new) (define/override (grow amt) (super grow (* 3/4 amt) (define joe-the-minnow (new fish% [size 2])) (define bud-the-minnow (new fish% [size 2])) (define big-al-the-pike (new fish% [size 10])) (define picky-selma (new picky-fish% [size 5])) (send picky-selma eat joe-the-minnow) (send picky-selma get-size) Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Overriding methods in Racket classes
OK using define-local-member-name works, see case 1 below, but it seems it would be much simpler if there was a form define/inheritable which made the method accessable within the class body where it was defined and in the sub-class bodies only. (see case 2 below) i.e. no wrapping in a let that returned multiple values etc. Is there some reason there isn't such a form define/inheritable ? === Case 1 (using define-local-member-name) = #lang racket (define-values (fish% picky-fish%) (let () (define-local-member-name grow) (define fish% (class object% (init size); initialization argument (define current-size size) ; field (super-new); superclass initialization (define/public (get-size) current-size) (define/public (grow amt) (set! current-size (+ amt current-size))) (define/public (eat other-fish) (grow (send other-fish get-size) (define picky-fish% (class fish% (super-new) (define/override (grow amt) (super grow (* 3/4 amt) (values fish% picky-fish%))) (define joe-the-minnow (new fish% [size 2])) (define bud-the-minnow (new fish% [size 2])) (define big-al-the-pike (new fish% [size 10])) (define picky-selma (new picky-fish% [size 5])) (send picky-selma eat joe-the-minnow) (send picky-selma get-size) ;;this now correctly fails ;(send bud-the-minnow grow 5) (Case 2 using a hypothetical define/inheritable) #lang racket (define fish% (class object% (init size) (define current-size size) (super-new) (define/public (get-size) current-size) (define/public (grow amt) (set! current-size (+ amt current-size))) (define/inheritable (eat other-fish) ;;;hypothetical define/inheritable (grow (send other-fish get-size) (define picky-fish% (class fish% (super-new) (define/override (grow amt) (super grow (* 3/4 amt) (define joe-the-minnow (new fish% [size 2])) (define bud-the-minnow (new fish% [size 2])) (define big-al-the-pike (new fish% [size 10])) (define picky-selma (new picky-fish% [size 5])) (send picky-selma eat joe-the-minnow) (send picky-selma get-size) Thanks, Harry Spier On 1/3/13, Asumu Takikawa wrote: > On 2013-01-03 17:01:54 -0500, Harry Spier wrote: >> In Racket is it possible to override a non-public method? >> >> [...] >> >> Apologies if I've missed something obvious but I've just started going >> through the Classes and Objects documentation. I can see where you >> can declare a method public and overridable, or public and not >> overridable, but I don't see a declaration for a method to be private >> to the outside world but public and overridable to its sub-classes. > > You can use local member names to accomplish this. It effectively makes > certain method names lexically scoped. Here is an example: > > #lang racket > > (define-values (bomb% detonator%) > (let () > ;; lexically scoped method name > (define-local-member-name detonate) > (values >(class object% > (super-new) > ;; public only while the name is in scope > (define/public (detonate) >(displayln "boom!"))) >(class object% > (super-new) > (init-field bomb) > (define/public (trigger) >(send bomb detonate)) > > ;; error since `detonate` not in scope > ;(send (new bomb%) detonate) > > ;; works > (send (new detonator% [bomb (new bomb%)]) trigger) > > Using local member names, the "outside world" is wherever the name is > not bound. If it is in scope, you can invoke it, override it, etc and > your method declarations are done normally. > > Cheers, > Asumu > Racket Users list: http://lists.racket-lang.org/users
[racket] Overriding methods in Racket classes
Dear list members, In Racket is it possible to override a non-public method? For example in the Racket Guide section 13 and 13.1 it gives this example: (class object% (init size); initialization argument (define current-size size) ; field (super-new); superclass initialization (define/public (get-size) current-size) (define/public (grow amt) (set! current-size (+ amt current-size))) (define/public (eat other-fish) (grow (send other-fish get-size . . . . . . (define picky-fish% (class fish% (super-new) (define/override (grow amt) (super grow (* 3/4 amt) which works fine but some entity can still tell a fish to "grow" outside the context of telling it to "eat" another fish. Apologies if I've missed something obvious but I've just started going through the Classes and Objects documentation. I can see where you can declare a method public and overridable, or public and not overridable, but I don't see a declaration for a method to be private to the outside world but public and overridable to its sub-classes. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Math library ready for testing
Neil Toronto wrote: >The maximum number of threads a parallelized math function will use. > The default value is (max 1 (processor-count))." Pierpaolo replied:: >Isn't (max 1 (processor-count)) the same as (processor-count) ? >Or does Racket runs on machines with less than 1 processors? 8^) For Quantum computers where the number of processors is a probability function between 0 and n . :-) Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Whats the difference between a predicate and a flat contract?
Are flat-contract and flat-contract-predicate equivalent? > ((flat-contract 'x) 'x) #t > ((flat-contract-predicate 'x) 'x) #t > ((flat-contract 'x) 'y) #f > ((flat-contract-predicate 'x) 'y) #f > Harry On Tue, Dec 4, 2012 at 9:41 PM, Robby Findler wrote: > It does that for symbols, but not everything. > > This is the place you should be looking, I think. > > http://docs.racket-lang.org/reference/contracts.html > > Robby > > On Tue, Dec 4, 2012 at 8:38 PM, Harry Spier wrote: >> OK I see the docs to flat-contract? but not flat-contract >> http://docs.racket-lang.org/reference/contract-utilities.html#(def._((lib._racket/contract/private/misc..rkt)._flat-contract~3f)) >> mention that flat-contracts are more than predicates. Those docs >> don't mention it, but it appears from experimentation that >> (flat-contract something) produces a procedure such that >> ((flat-contract something) x) is #t if something eq? x . >> >> Harry Spier >> >> On Tue, Dec 4, 2012 at 8:57 PM, Robby Findler >> wrote: >>> On Tue, Dec 4, 2012 at 7:28 PM, Carl Eastlund wrote: >>>> On Tue, Dec 4, 2012 at 7:49 PM, Robby Findler >>>> wrote: >>>>> >>>>> Flat contracts includes more things than contracts. For example: >>>>> >>>>> [robby@yanpu] ~/git/plt/collects/scribblings/reference$ racket >>>>> Welcome to Racket v5.3.1.9. >>>>> > (flat-contract? 'x) >>>>> #t >>>>> > (procedure? 'x) >>>>> #f >>>>> >>>>> The flat-contract function is a holdover from the days when flat contracts >>>>> weren't able to be used directly as predicate functions. >>>>> >>>>> >>>>> I'll push a clarification to the docs for flat-contract. >>>> >>>> >>>> Isn't that the wrong way around? The flat-contract function lets you use a >>>> predicate as a contract, not a contract as a predicate. Presumably it's >>>> from before predicates could be used as contracts, although I hadn't >>>> realized there was such a time. >>> >>> There was a time when you had to call 'flat-contract' to turn a >>> predicate into a contract, yep. There was a housecleaning (anyone >>> remember the days when there were multiple suffixes (not just "/c") on >>> the combinators?) and I probably should have gotten rid of it at that >>> time, but I didn't. >>> >>> (Oh and I mean "contracts" where I wrote "preducate functions" above. Oops.) >>> >>> Robby Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Whats the difference between a predicate and a flat contract?
OK I see the docs to flat-contract? but not flat-contract http://docs.racket-lang.org/reference/contract-utilities.html#(def._((lib._racket/contract/private/misc..rkt)._flat-contract~3f)) mention that flat-contracts are more than predicates. Those docs don't mention it, but it appears from experimentation that (flat-contract something) produces a procedure such that ((flat-contract something) x) is #t if something eq? x . Harry Spier On Tue, Dec 4, 2012 at 8:57 PM, Robby Findler wrote: > On Tue, Dec 4, 2012 at 7:28 PM, Carl Eastlund wrote: >> On Tue, Dec 4, 2012 at 7:49 PM, Robby Findler >> wrote: >>> >>> Flat contracts includes more things than contracts. For example: >>> >>> [robby@yanpu] ~/git/plt/collects/scribblings/reference$ racket >>> Welcome to Racket v5.3.1.9. >>> > (flat-contract? 'x) >>> #t >>> > (procedure? 'x) >>> #f >>> >>> The flat-contract function is a holdover from the days when flat contracts >>> weren't able to be used directly as predicate functions. >>> >>> >>> I'll push a clarification to the docs for flat-contract. >> >> >> Isn't that the wrong way around? The flat-contract function lets you use a >> predicate as a contract, not a contract as a predicate. Presumably it's >> from before predicates could be used as contracts, although I hadn't >> realized there was such a time. > > There was a time when you had to call 'flat-contract' to turn a > predicate into a contract, yep. There was a housecleaning (anyone > remember the days when there were multiple suffixes (not just "/c") on > the combinators?) and I probably should have gotten rid of it at that > time, but I didn't. > > (Oh and I mean "contracts" where I wrote "preducate functions" above. Oops.) > > Robby Racket Users list: http://lists.racket-lang.org/users
[racket] Whats the difference between a predicate and a flat contract?
Dear list members, I'm a little confused about the difference between the definition of a predicate and the definition of a flat contract. If someone could clear that up I'd appreciate it. 1) AT ALL PLACES in the documentation where it uses the term "predicate" does that mean a procedure that takes a single value and returns a boolean? I inferred that from: http://docs.racket-lang.org/reference/function-contracts.html#(def._((lib._racket/contract/base..rkt)._predicate/c)) But from the section of the Racket Guide "Rolling your own contracts" http://docs.racket-lang.org/guide/contract-func.html#(part._contracts-own) I inferred that a procedure that takes a value and returns a boolean can be used as a contract, so is a predicate always a flat-function? If thats so, then what does (flat-contract predicate) do? http://docs.racket-lang.org/reference/data-structure-contracts.html#(def._((lib._racket/contract/private/misc..rkt)._flat-contract)) Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Contracts and submodules
One thing I would find very useful is a blog post giving an overview of where its more appropriate to use Racket without using contracts,or Racket using contracts or Typed Racket. Also an overview of the speed issues would be very useful.. For example I know there is a cost to contracts, but I'm not clear how Typed Racket compares in efficiency to Racket with contracts. And also I've seen posts where a member said he didn't use Typed Racket for his customer applications because of efficiency, but I also vaguely recall seeing a post where a user said that because of the type information given that a certain program was compiled more efficiently than if it hadn't been given the type information, so I'm unclear about the efficiency issues with Typed Racket. Thanks, Harry Spier On Fri, Nov 30, 2012 at 9:33 AM, Matthias Felleisen wrote: > > On Nov 29, 2012, at 10:29 PM, Greg Hendershott wrote: > >> AFIK these subtleties of contracts and modules arise with >> `provide/contract' -- by saying that the function should only use a >> contract outside the module (or submodule). >> >> But I prefer to use `define/contract'. For one thing, I think it's >> easier and more-maintainable to group the contract near/with its >> function in the source. But I also prefer it on the starting >> assumption that if a procedure is worth contracting at all, it's worth >> contracting all the time -- inside the module as well as outside. > > > This is a complete misunderstanding. Contracts are specifications > that govern the flow of values across boundaries. We call this boundary > a 'module' but for several years now, module and #lang have been two > distinct terms. In this spirit, > > -- #lang with provide contract-out is a module > -- define/contract is a module > -- internal modules are modules but watch out for module+ > > In contrast, > -- units and classes are values and we have contracts for them > but they do NOT establish contract boundaries, they are > NOT modules. > > In your specific case, define/contract splits an existing 'module' > into two pieces. > > ;; --- > > As I have said many times, your use of contract is likely to be > much better satisfied with the use of Typed Racket. I doubt that > many of your contracts are checking more than constructors, which > roughly corresponds to type checking. For the remaining ones, Sam > will provide > > provide/typed with contract-out > require/typed with contract-in > > ANY TIME SOON NOW. > > ;; --- > > > As for performance of contracts: > > On Nov 29, 2012, at 11:47 PM, Harry Spier wrote: > >> And then to enable/disable contracts you can use the method Mathias >> pointed out here. >> http://www.mail-archive.com/users@racket-lang.org/msg12281.html > > > Thanks for reminding the list of this post. I should write this > out as a blog post or an entry into our Contract Guide. > > > > > > Racket Users list: > http://lists.racket-lang.org/users > Racket Users list: http://lists.racket-lang.org/users
[racket] Contracts: combining case-> and ->i
In building contracts is it possible (or will it in the future be possible) to use case-> with ->i instead of -> Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Contracts and submodules
On Fri, Nov 30, 2012 at 9:33 AM, Matthias Felleisen wrote: > > On Nov 29, 2012, at 11:47 PM, Harry Spier wrote: > >> And then to enable/disable contracts you can use the method Mathias >> pointed out here. >> http://www.mail-archive.com/users@racket-lang.org/msg12281.html > > > Thanks for reminding the list of this post. I should write this > out as a blog post or an entry into our Contract Guide. > I think this would also be an excellent example in the Guide under submodules as an example of a use of submodules. I only found this post by lucky chance but it was exactly what I needed. Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Contracts and submodules
Thanks Robby, Do I need to submit a bug report. Harry On Thu, Nov 29, 2012 at 8:32 PM, Robby Findler wrote: > That looks like a bug to me. > > Robby > > On Thu, Nov 29, 2012 at 6:59 PM, Harry Spier > wrote: >> Dear list members, >> >> Case 1 below doesn't give a contract violation but case 2 does. Is >> this desired behavour or is it a bug? >> >> In DrRacket >> Case 1 >> - >> #lang racket >> (provide (contract-out [ident-number (-> number? number?)])) >> (define (ident-number x) x) >> (module+ main >> (ident-number 'a)) >> >>> 'a >> >> >> Case 2 >> >> #lang racket >> (provide (contract-out [ident-number (-> number? number?)])) >> (define (ident-number x) x) >> (module+ main >> (require (submod "..")) >> (ident-number 'a)) >> >>> >> ident-number: contract violation >> expected: number? >> given: 'a >> in: the 1st argument of >> (-> number? number?) >> contract from: >> c:\users\harry\ocr_project\test2.rkt >> blaming: >> (c:\users\harry\ocr_project\test2.rkt main) >> at: c:\users\harry\ocr_project\test2.rkt:2.24 >> >> Thanks, >> Harry Spier >> >> Racket Users list: >> http://lists.racket-lang.org/users Racket Users list: http://lists.racket-lang.org/users
[racket] Problem with posting to Racket users list
My last two posts to the users list have shown up on the gmane mirror and the google groups mirror but not on the mail archive. My original posts didn't show up on the mail archive but my subsequent reply did. I think this has happened to me once or twice in the past also. Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] rackunit messages
Thanks Danny. I see that now. Harry On Tue, Nov 27, 2012 at 1:13 AM, Danny Yoo wrote: > > > > A test suite is a value, and you're seeing that value since it's a toplevel > expression. That is, nothing's being run. You'll probably want to amend to > something like this: > > ;;; > > (module+ main > (require rackunit rackunit/text-ui) > ;;make-byte-array tests > (define 2-3-0-barry (make-byte-array 2 3 )) > (define 2-3-λ-barry (make-byte-array 2 3 #o377)) > > (define my-test-suite > (test-suite > "Testing make-byte-array" > (check equal? (byte-array-string 2-3-0-barry) #"\0\0\0\0\0\0") > (check equal? (byte-array-string 2-3-λ-barry) > #"\377\377\377\377\377\377") > (check equal? (byte-array-row-count 2-3-0-barry) 2) > (check equal? (byte-array-column-count 2-3-0-barry) 3))) > > (run-tests my-test-suite)) > > ;;; > > > For more information, take a look near the end of > http://docs.racket-lang.org/rackunit/quick-start.html, where the example > organizes the checks into a "suite". > > > Best of wishes! Racket Users list: http://lists.racket-lang.org/users
[racket] Making a contract between a function and "the world in general" AGAIN
About a year ago, there was a discussion on the list about "provide" propagating existing contracts. (See: http://www.mail-archive.com/users@racket-lang.org/msg08623.html ) suggested by Neil Toronto for this reason: "...define/contract has a huge advantage that contract-out doesn't have: it puts all the invariants at the function definition, right before the code that relies on them. " and with this suggested form: -- (provide (contract-out real-id)) ; ... more code ... (define/contract (real-id x) (real? . -> . real?) x) Or (provide (lift-contract real-id)) might be even better. AFAICT the discussion seemed somewhat favorable to this. What is the status of this? Are there any plans to implement this (or something like this)? Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] provide and require in submodules
Thanks Matthew, Is this also the same/similar bug but with submodule path as filename? This works: - #lang racket ;; client.rkt (require (submod "things.rkt" extra-things)) (displayln thing-a) #lang racket ;; things.rkt (provide thing-a thing-b) (define thing-a 'thing-a) (define thing-b 'thing-b) (module+ extra-things (provide (all-from-out (submod ".."))) (provide all-defined-out) (define extra-thing-c 'extra-thing-c) (define extra-thing-d 'extra-thing-d)) RUNNING client.rkt GIVES: > thing-a -- BUT #lang racket ;; client.rkt (require (submod "things.rkt" extra-things)) (displayln thing-a) #lang racket ;; things.rkt (provide thing-a thing-b) (define thing-a 'thing-a) (define thing-b 'thing-b) (module+ extra-things (provide (all-from-out "things.rkt")) ;;CHANGED (submod "..") ;;TO "things.rkt" (provide all-defined-out) (define extra-thing-c 'extra-thing-c) (define extra-thing-d 'extra-thing-d)) RUNNING client.rkt GIVES ERROR things.rkt:8:25: all-from-out: no corresponding require in: "things.rkt" Thanks, Harry Spier On Fri, Nov 23, 2012 at 10:31 AM, Matthew Flatt wrote: > That's a bug. I've pushed a repair to the git repo. > > Thanks for the report! > > At Tue, 20 Nov 2012 23:19:30 -0500, Harry Spier wrote: > > Dear list members, > > > > This works in DrRacket: > > definitions window > > - > > #lang racket > > (module+ server > > (provide a-from-server) > > (define a-from-server 'a-from-server)) > > > > (module+ client > > (module server2 racket > > (provide b-from-server2) > > (define b-from-server2 'b-from-server2)) > > > > (require (submod ".." server)) > > (provide (all-from-out (submod ".." server))) > > > > (require 'server2) > > (provide (all-from-out (submod "." server2 > > > > (module+ main > > (require (submod ".." client)) > > a-from-server > > b-from-server2) > > > > Results in interactions window > > --- > > > > > 'a-from-server > > 'b-from-server2 > > > > BUT the following gives me the error: "all-from-out: no corresponding > > require in: (quote server2)" > > Could someone explain why I'm getting this error. > > > > Definitions window > > -- > > #lang racket > > (module+ server > > (provide a-from-server) > > (define a-from-server 'a-from-server)) > > > > (module+ client > > (module server2 racket > > (provide b-from-server2) > > (define b-from-server2 'b-from-server2)) > > > > (require (submod ".." server)) > > (provide (all-from-out (submod ".." server))) > > > > (require 'server2) > > (provide (all-from-out 'server2))) ;;;CHANGED (submod "." server2) TO > > 'server2 > > > > (module+ main > > (require (submod ".." client)) > > a-from-server > > b-from-server2) > > > > Thanks, > > Harry Spier > > > > Racket Users list: > > http://lists.racket-lang.org/users > > Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Survey for DrRacket users related to automatic parentheses behavior
On Thu, Nov 22, 2012 at 7:20 PM, Nadeem Abdul Hamid wrote: 1. Do you use the automatic parentheses feature of DrRacket? > Yes > > 2a. If yes, does the proposal above resonate well with you? > I would prefer the following. On my computer (windows) when auto-inserted closing parenthesis is enabled, if I type ctrl [ then no closing bracket is inserted but ctrl ( inserts a closing bracket and ctrl { does nothing. I would prefer ctrl-( , ctrl-[ and ctrl-{ all don't insert a closing bracket and also use ctrl-), ctrl-} and ctrl-] for the behavour you describe. > 2b. And, do you think this "smart skipping" of auto-inserted closing > parentheses should become the intrinsic behavior of the automatic > parentheses mode, or should it be a separate preference? > I would like a separate preference. Thanks, Harry Spier > > > > Racket Users list: > http://lists.racket-lang.org/users > > Racket Users list: http://lists.racket-lang.org/users
[racket] provide and require in submodules
Slight correction. Comment line was too long and wrapped over. -- Forwarded message -- From: Harry Spier Date: Tue, Nov 20, 2012 at 11:19 PM Subject: provide and require in submodules To: users Dear list members, This works in DrRacket: definitions window - #lang racket (module+ server (provide a-from-server) (define a-from-server 'a-from-server)) (module+ client (module server2 racket (provide b-from-server2) (define b-from-server2 'b-from-server2)) (require (submod ".." server)) (provide (all-from-out (submod ".." server))) (require 'server2) (provide (all-from-out (submod "." server2 (module+ main (require (submod ".." client)) a-from-server b-from-server2) Results in interactions window --- > 'a-from-server 'b-from-server2 BUT the following gives me the error: "all-from-out: no corresponding require in: (quote server2)" Could someone explain why I'm getting this error. Definitions window -- #lang racket (module+ server (provide a-from-server) (define a-from-server 'a-from-server)) (module+ client (module server2 racket (provide b-from-server2) (define b-from-server2 'b-from-server2)) (require (submod ".." server)) (provide (all-from-out (submod ".." server))) (require 'server2) (provide (all-from-out 'server2))) ;;;CHANGED (submod "." server2) ;TO 'server2 (module+ main (require (submod ".." client)) a-from-server b-from-server2) Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] provide and require in submodules
Dear list members, This works in DrRacket: definitions window - #lang racket (module+ server (provide a-from-server) (define a-from-server 'a-from-server)) (module+ client (module server2 racket (provide b-from-server2) (define b-from-server2 'b-from-server2)) (require (submod ".." server)) (provide (all-from-out (submod ".." server))) (require 'server2) (provide (all-from-out (submod "." server2 (module+ main (require (submod ".." client)) a-from-server b-from-server2) Results in interactions window --- > 'a-from-server 'b-from-server2 BUT the following gives me the error: "all-from-out: no corresponding require in: (quote server2)" Could someone explain why I'm getting this error. Definitions window -- #lang racket (module+ server (provide a-from-server) (define a-from-server 'a-from-server)) (module+ client (module server2 racket (provide b-from-server2) (define b-from-server2 'b-from-server2)) (require (submod ".." server)) (provide (all-from-out (submod ".." server))) (require 'server2) (provide (all-from-out 'server2))) ;;;CHANGED (submod "." server2) TO 'server2 (module+ main (require (submod ".." client)) a-from-server b-from-server2) Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] submodule paths and DrRacket
Dear list members, Can someone explain the following behavior Case 1 as follows works in the DrRacket Definitions window but doesn't work in the Interactions window #lang racket (module m racket (provide color) (define color "blue")) (module n racket (require (submod ".." m)) (printf "my favorite color is ~a\n" color)) Case 2 as follows works in the DrRacket Interactions window but doesn't work in the Definitions window > (module m racket (provide color) (define color "blue")) (module n racket (require 'm) (printf "my favorite color is ~a\n" color)) (require 'n) I'm clear why in case 1(submod ".." m) resolves to submodule m when the code is in the definitions window, but I'm not clear why it doesn't do so when the code is in the Interactions window. I'm also not clear why case 2 works in the Interactions window. I.e. I'm not clear why in case 2 in the interactions window (require 'm), which according to the Racket Guide expands to (require (submod "." m) works and (require (submod ".." m) doesn't work for this case. Also is there a way to have #lang racket (module m racket (provide color) (define color "blue")) in the definitions window but the following in the interactions window >(module n racket (require SOME SUBMODULE PATH TO m) (printf "my favorite color is ~a\n" color)) (require 'n) and have it work. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Why this contract violation behaviour?
Thanks Matthias. Why does the first case which doesn't cross a module boundary cause a contract violation. #lang racket (provide/contract (amount positive?)) (define amount -7) On Fri, Nov 16, 2012 at 8:24 PM, Matthias Felleisen wrote: > > Contracts really are like business contracts. They are between two > distinct parties; they are not by a party on itself. > > On occasion, you really do want to wish to break the contract inside a > module. This is well-known in the OO world, and it is often called the > re-entrance problem. Say you want a balanced tree object. Imagine it has a > method with a contract that requires 'balanced'ness but is also called > internally. Perhaps you don't need/wish to balance for internal calls. So > you do -- and you don't get caught. > > Contracts impose a run-time cost. To make the cost reasonable, we trust > the programmer and we let the programmer know that we trust him. > > > > > > > > > > On Nov 16, 2012, at 7:52 PM, Galler wrote: > > >> > >> Even if you use define/contract, you may violate the contract on > recursive > > calls. This is intentional. > >> > > > > Thanks. > > > > I hadn't run into that behavior before and wasn't aware. > > > > Could you possibly elaborate on the thinking wrt this design choice? > > > > (define/contract (my-natural-number n) > > (-> exact-positive-integer? any/c) > > (print n) (newline) > > (my-natural-number (sub1 n))) > > > > (my-natural-number 1) > > 1 > > 0 > > -1 > > -2 > > -3 > > -4 > > > > > > > > > > Racket Users list: > > http://lists.racket-lang.org/users > > > > Racket Users list: > http://lists.racket-lang.org/users > > Racket Users list: http://lists.racket-lang.org/users
[racket] Why this contract violation behaviour?
Dear list members, Can someone explain why in the following cases only two out of the three cases and not all of them cause a contract violation. Thanks, Harry Spier #lang racket (provide/contract (amount positive?)) (define amount -7) > contract promised: positive? produced: -7 in: positive? contract from: anonymous-module blaming: anonymous-module BUT-- #lang racket (provide/contract [amount (-> positive?)]) (define (amount) -7) (amount) > No contract violation AND--- #lang racket (provide/contract [amount (-> positive?)]) (define (amount) -7) (module* main racket (require (submod "..")) (amount)) > amount: broke its contract promised: positive? produced: -7 in: the range of (-> positive?) contract from: c:\users\harry\ocr_project\contract-test.rkt blaming: c:\users\harry\ocr_project\contract-test.rkt at: c:\users\harry\ocr_project\contract-test.rkt:3.20 Racket Users list: http://lists.racket-lang.org/users
[racket] Racket error reporting and the console window
1) Is there some way to keep the console window open when a racket executable reports an error? (I'm a Windows user) For this example, the racket console window closes before I can read the contract violation message: #lang racket (provide/contract [amount positive?]) (define amount 0) This also doesn't stay open for me to read the error message as the contract violation is only displayed after I enter a character to continue. #lang racket (provide/contract [amount positive?]) (define amount 0) (system "PAUSE") 2) The reason I was doing this little test was that I thought from the Racket Guide documentation sections 7.1 and 7.1.1 which used this example, that provide/contract only did a contract check when the module was required, and I was checking this both in DrRacket and as an executable. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] Performance of Racket on Linux and Windows
Dear list members, Has anyone compared the performance of a cpu intensive + large vectors Racket application on a machine with on of the newer multicore processors (i5 or i7 etc) with lots of memory (6 or 8 Gbytes or more) on Linux versus Windows. Should the real-time execution time (all others things equal other than operating system) be more or less the same. Many thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] monochrome bitmaps
To clarify one point: Is a monochrome bitmap a greyscale bitmap or a black and white bitmap? I see from the documentation that the form (make-object bitmap% bits width height) produces a black and white bitmap but for the form I asked about (shown again below) subject to the restriction Matthew described (i.e. png or xbm file format) will that produce a greyscale bitmap or a strictly black and white bitmap? (make-object bitmap% in ;path to greyscale image files [ kind bg-color complain-on-failure?]) Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] monochrome bitmaps
Matthew Flatt wrote: > A monocrhome bitmap doesn't have an alpha channel, but it you ask for > its pixels in `just-alpha?' mode, then while pixels generate a 0 alpha > and black pixels generate a 255 alpha. > Thanks Matthew. What confused me was that for: (send a-dc set-alpha opacity) opacity is a value between 0 and 1 (not a value between 0 and 255) and I didn't realize this method acts as a multiplier of each pixels alpha channel and doesn't set the value of the alpha channel directly. So I incorrectly assumed each pixels alpha channel has a value between 0 and 1 not between 0 and 255. Cheers, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] Typed racket in DrRacket
When I run the simplest possible racket program in DrRacket definitions window #lang racket 1 the result 1 and the prompt appear instantaneously in the interactions window, but when I change this to typed racket #lang typed/racket 1 it takces two seconds before the result 1 and the prompt are displayed in the interactions window also #lang typed/racket (time 1) gives the expected result of: cpu time: 0 real time: 0 gc time: 0 but this still takes two seconds to appear in the interactions window. Why with a simple program like this does the result take so much longer for typed racket compared to racket to be displayed in the interactions window. thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] Macros for continuation forms
To help myself understand continuations I created some macros to simplify the syntax and to simulate keyword type arguments to make whats happening more explicit. I'm not sure the simulated keyword type arguments are good Racket style but they helped me see what was going on, by making things more explicit. The forms are mainly let type forms but there are some others There are also some examples that helped my imperatively trained brain wrap around continuations. For example I can now have this: -- (define saved-continuation #f) (define x 10) (let/set-prompt ([prompt: prompt-1]) (+ 4 (+ 3 (+ 2 (save-this-continuation upto: prompt-1 in: saved-continuation return: 0) x (saved-continuation 0) (set! x 100) (saved-continuation 0) - Instead of: ((define saved-k #f) (call-with-continuation-prompt (lambda () (+ 4 (+ 3 (+ 2 (call-with-composable-continuation (lambda (k) ; k is the captured continuation (set! saved-k k) 0) prompt-1) x prompt-1) (saved-k 0) (set! x 100) (saved-k 0) I thought others might find these macros useful so I uploaded the macros and examples to Github: https://github.com/harryspier/CONTINUATION-MACROS-1 Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Saved continuations
Thanks Daniel but the question I was trying to find out was: Is there a way to save any valid continuation and be guaranteed that nothing that happens in the program between the time the continuation was saved and the time the saved continuation was invoked will alter the results of invoking the continuation. Harry - D. Herring wrote: Does an extra (let ...) do what you want, or do you want new bindings for *all* variables that are used in the continuation? Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Saved continuations
Is it possible in Racket to make a kind of copy of a saved continuation with its environment at the time it was saved, so that no mutation of variables between the time the copy of the saved continuation was made and the time the copy is invoked can possible have any affect on the values the copy of the saved continuation produces? I thought this would work but it didn't, it still captured the mutation of x and returned: 10 100 -- #lang web-server (require racket/serialize) (define saved-k #f) (define x 10) (call-with-web-prompt (λ() (+ (call-with-serializable-current-continuation (lambda (k) (set! saved-k k) 0)) x ))) ; continuation is (+ [] x) (define serialized-k (serialize saved-k)) (call-with-web-prompt (thunk (saved-k 0))) (set! x 100) (call-with-web-prompt (thunk ((deserialize serialized-k) 0))) -- RETURNS: 10 100 On Tue, Sep 4, 2012 at 3:33 PM, Matthew Flatt wrote: > At Tue, 4 Sep 2012 15:25:32 -0400, Harry Spier wrote: >> I did this experiment with saved continuations in DrRacket >> -- >> > (define saved-k #f) >> (define (save-it) (call-with-composable-continuation >>(lambda (k) >>(set! saved-k k) >> 0))) >> >> (define x 10) >> (call-with-continuation-prompt >> (lambda() >>(+ (save-it) x ))) ; continuation is (+ [] x)) >> >> (saved-k 0) >> (set! x 100) >> (saved-k 0) >> >> --- >> GIVES RESULTS >> 10 >> 100 >> >> Is this a querk of Dr. Racket or does this mean that if within a saved >> continuation, a variable has not yet been reduced to a value at the >> time the continuation was saved, that variable can be mutated changing >> the behavior of the saved continuation? > > ; continuation is (+ [] x) > > `x' is not evaluated until the continuation is > applied, and that's why it can "see" mutation of `x'. > Racket Users list: http://lists.racket-lang.org/users
[racket] Saved continuations
I did this experiment with saved continuations in DrRacket -- > (define saved-k #f) (define (save-it) (call-with-composable-continuation (lambda (k) (set! saved-k k) 0))) > (define x 10) (call-with-continuation-prompt (lambda () (+ x (save-it) ))) ; continuation is (+ x [])) (saved-k 0) (set! x 100) (saved-k 0) - GIVES RESULTS 10 10 --- (define x 10) (call-with-continuation-prompt (lambda() (+ (save-it) x ))) ; continuation is (+ [] x)) (saved-k 0) (set! x 100) (saved-k 0) --- GIVES RESULTS 10 100 Is this a querk of Dr. Racket or does this mean that if within a saved continuation, a variable has not yet been reduced to a value at the time the continuation was saved, that variable can be mutated changing the behavior of the saved continuation? Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Problem with macro
Thanks Danny, I've changed the syntax of the macro as follows by faking keyword arguments prompt: and handler: and it works now as far as I can tell. I saw some discussion on the dev list about keyword parameters and syntax but I didn't quite follow it, so I wasn't sure if it was saying that keyword parameters in macros wll or won't be implemented. ;let/set-prompt is let type syntax for call-with-continuation-prompt procedure. ;(let/set-prompt ([prompt: prompt] [handler: handler] args) body) ; prompt and handle are optional ; Examples: ; (let/set-prompt () (+ 1 2 3 4)) ; (let/set-prompt ([prompt: prompt-1]) (+ 1 2 3 4)) ; (let/set-prompt ([prompt: prompt-1] [handler: handler-1]) (+ 1 2 3 4)) ; (let/set-prompt ([prompt: prompt-1] [handler: handler-1] [val 4]) (+ 1 2 3 val)) (define-syntax let/set-prompt (syntax-rules (prompt: handler:) [(_ ((prompt: PROMPT) (handler: HANDLER) ARGS ...) BODY ...) (call-with-continuation-prompt (let (ARGS ...) (λ () BODY ...)) PROMPT HANDLER)] [(_ ((handler: HANDLER) (prompt: PROMPT) ARGS ...) BODY ...) (call-with-continuation-prompt (let (ARGS ...) (λ () BODY ...)) PROMPT HANDLER)] [(_ ((prompt: PROMPT)ARGS ...) BODY ...) (call-with-continuation-prompt (let (ARGS ...) (λ () BODY ...)) PROMPT)] [(_ ((handler: HANDLER) ARGS ...) BODY ...) (call-with-continuation-prompt (let (ARGS ...) (λ () BODY ...)) PROMPT)] [(_ ( ARGS ...) BODY ...) (call-with-continuation-prompt (let (ARGS ...) (λ () BODY ...)))])) (define-syntax abort-to-prompt (syntax-rules () [(_ VAL) (abort-current-continuation (default-continuation-prompt-tag) (thunk VAL))] [(_ PROMPT-TAG VAL) (abort-current-continuation PROMPT-TAG (thunk VAL))])) (define prompt-1 (make-continuation-prompt-tag)) (define prompt-2 (make-continuation-prompt-tag)) (define prompt-3 (make-continuation-prompt-tag)) (define (play-with-prompts [p (default-continuation-prompt-tag)]) (+ 1 (let/set-prompt ([prompt: prompt-1] [val 10] ) (+ val (let/set-prompt ([prompt: prompt-2] [val 100]) (+ val (let/set-prompt ([prompt: prompt-3] [val 1000]) (+ val (abort-to-prompt p 0) 2000)) 200)) 20 (play-with-prompts prompt-1) (play-with-prompts prompt-2) (play-with-prompts prompt-3) (play-with-prompts) On Sun, Sep 2, 2012 at 12:27 AM, Danny Yoo wrote: >> (let/set-prompt prompt-3 () >> (+ 1000 >>(abort-to-prompt p 0) >>2000)) >> >> ==> >> >> (call-with-continuation-prompt >> (let () (λ () >>+ >>1000 >>(abort-to-prompt p 0) >>2000)) >> prompt-3) >> >> >> >> And whoops! That's where we're getting the funky values back: the use >> of + just got ripped apart by the macro, by accident. We popped its >> bubble, and the components just spilled out into the body of the let. > > > Doh. Typo. I meant to say: "... and the components just spilled out > into the body of the λ". Sorry about the confusion! Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Problem with macro
Thanks Danny, Its obvious now that you point it out. On Sun, Sep 2, 2012 at 12:27 AM, Danny Yoo wrote: >> (let/set-prompt prompt-3 () >> (+ 1000 >>(abort-to-prompt p 0) >>2000)) >> >> ==> >> >> (call-with-continuation-prompt >> (let () (λ () >>+ >>1000 >>(abort-to-prompt p 0) >>2000)) >> prompt-3) >> >> >> >> And whoops! That's where we're getting the funky values back: the use >> of + just got ripped apart by the macro, by accident. We popped its >> bubble, and the components just spilled out into the body of the let. > > > Doh. Typo. I meant to say: "... and the components just spilled out > into the body of the λ". Sorry about the confusion! Racket Users list: http://lists.racket-lang.org/users
[racket] Problem with macro
Dear list members, I'm trying to work my way through Racket continuations by going through the Guide and Reference. And as part of that I set up small examples and sometimes macros to simplify the syntax so I can see more clearly whats going on. So I made a let type form of call-with-continuation-prompt called let/set-prompt as follows and a small example as follows: ;(let/set-prompt prompt handler body) ; prompt and handler are optional ; Examples: ; let/set-prompt () (+ 1 2 3 4)) ; let/set-prompt prompt-1 () (+ 1 2 3 4)) ;let/set-prompt prompt-1 handler-1 () (+ 1 2 3 4)) (define-syntax let/set-prompt (syntax-rules () [(_ARGS BODY) (call-with-continuation-prompt (let ARGS (λ () BODY)))] [(_ PROMPT ARGS BODY) (call-with-continuation-prompt (let ARGS (λ () BODY)) PROMPT)] [(_ PROMPT HANDLER ARGS BODY) (call-with-continuation-prompt (let ARGS (λ () BODY)) PROMPT HANDLER)])) (define-syntax abort-to-prompt (syntax-rules () [(_ VAL) (abort-current-continuation (default-continuation-prompt-tag) (thunk VAL))] [(_ PROMPT-TAG VAL) (abort-current-continuation PROMPT-TAG (thunk VAL))])) (define prompt-1 (make-continuation-prompt-tag)) (define prompt-2 (make-continuation-prompt-tag)) (define prompt-3 (make-continuation-prompt-tag)) (define (play-with-prompts [p (default-continuation-prompt-tag)]) (+ 1 (let/set-prompt prompt-1 () (+ 10 (let/set-prompt prompt-2 () (+ 100 (let/set-prompt prompt-3 () (+ 1000 (abort-to-prompt p 0) 2000)) 200)) 20 (play-with-prompts prompt-1) (play-with-prompts prompt-2) (play-with-prompts prompt-3) (play-with-prompts) - This works fine for this example but the let/set-prompt macro has problems. It can only take a single body so it can mimic (let ()(+ 1 2 3)) but it can't mimic (let () 1 2 3) etc. So I tried modifying the macro to the following. ;(let/set-prompt args prompt (body ...)) (define-syntax let/set-prompt (syntax-rules () [(_ARGS (BODY ...)) (call-with-continuation-prompt (let ARGS (λ () BODY ...)))] [(_ PROMPT ARGS (BODY ...)) (call-with-continuation-prompt (let ARGS (λ () BODY ...)) PROMPT)] [(_ PROMPT HANDLER ARGS (BODY ...)) (call-with-continuation-prompt (let ARGS (λ () BODY ...)) PROMPT HANDLER)])) but then when I execute: (play-with-prompts prompt-1) (play-with-prompts prompt-2) (play-with-prompts prompt-3) (play-with-prompts) I no longer get the correct results of 1 31 331 but I get this instead. 1 21 21 Any suggestions of what the problem could be. (I haven't had great success using the macro stepper up till now.. Does anyone have any documentation on its use with some simple examples.) Also I'm a little familiar with syntax-id-rules but not syntax-case. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] call-with-composable-continuation and DrRacket
OK I think I grok it. When I write in the definitions window of DrRacket #lang racket (+ 100 (call-with-composable-continuation (λ (k) (+ (k 1) 1000 what actually gets executed is at least: (call-with-values (+ 100 (call-with-composable-continuation (λ (k) (+ (k 1) 1000 print-values) and the continuation captured by cwcc is at least: (λ (x) (call-with-values (lambda () (+ 100 x)) print-values)) so what gets executed is: ((call-with-values (+ 100 (+ 1000 (call-with-values ((λ (x) (+ 100 x)) 1) print-values))) print-values) printing out 101 1201 When I actually tried to execute this, I got an unbound identifier error for print-values and I couldn't find a reference to print-values in the racket reference manual. Harry Spier On Thu, Aug 30, 2012 at 6:11 PM, Matthias Felleisen wrote: > > On Aug 30, 2012, at 5:48 PM, Harry Spier wrote: > >> When I run this in the definitions window of DrRacket >> #lang racket >> (+ 100 >> (call-with-composable-continuation >>(λ (k) (+ 1000 (k 1) >> >> it prints >> 101 >> 1201 >> in the interactions window. >> Why doesn't it just print 1201 ? > > > As John says, the meaning of this program isn't "on its sleeve" as > semanticists used to say in the 1980s. If you use the Macro Stepper to expand > the above program (- racket, -library), you get > > (module anonymous-module racket > (#%module-begin >(#%app > call-with-values > (lambda () > (#%app >+ >(quote 100) >(#%app call-with-composable-continuation (lambda (k) (#%app + (quote > 1000) (#%app k (quote 1))) > print-values))) > > The key is to note that an expression is wrapped in a (call-with-values . > print-values), plus an outer #%module-begin. Hence the meaning of cwcc is (at > least) > > (lambda (x) (call-with-values (lambda () (+ 100 x)) print-values)) > > ;; --- > > In contrast, the same expression in the repl gets expanded via #%top, which > does not wrap the print-values around it -- after all the "printer" is a part > of the REPL. > > ;; --- > > Perhaps this is somewhat ironic, because the idea is really that each > expression in the def window should be wrapped in a "prompt" -- but it means > only "control delimiter". Something to consider is that we take the meaning > of the word "prompt" literally and have the two areas behave identically. > > -- Matthias > > > > Racket Users list: http://lists.racket-lang.org/users
[racket] call-with-composable-continuation and DrRacket
When I run this in the definitions window of DrRacket #lang racket (+ 100 (call-with-composable-continuation (λ (k) (+ 1000 (k 1) it prints 101 1201 in the interactions window. Why doesn't it just print 1201 ? Executing it in the interactions window gives the expected result of 1201. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Enhancing a macro
I've just come across Jay McCarthy's blog series on continuation marks where he uses this exact problem (keeping track of indentation level) to illustrate the use of dynamic-wind, parameters, and continuation marks. http://jeapostrophe.github.com/blog/2012/07/16/cont-marks/ http://jeapostrophe.github.com/blog/2012/07/25/cont-marks2/ http://jeapostrophe.github.com/blog/2012/07/30/cont-marks3/ Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] Performance difference write, display, print and pretty-print
I pretty-printed a data structure to a file to analyse it, and it seemed to take a long time to print so I did a timing comparison between write, display, print and pretty-print using the same data which was a vector of lists of structs. The structs were small 4 numbers and two very short lists (2 or 3 members). There were about 27000 lines in the pretty-printed file. The timing results for write, display, print and pretty-print this data structure was: write cpu time: 188 real time: 232 gc time: 0 display cpu time: 328 real time: 324 gc time: 78 print cpu time: 10593 real time: 10585 gc time: 218 pretty-print cpu time: 15288 real time: 15687 gc time: 547 Why this big difference between the performance of write and display to print and pretty-print. The performance difference (cpu time) between write and pretty-print is 82 to 1. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Enhancing a macro
Thanks Jeremiah! I took your idea and modified it slightly so that the let**-debug is in the body of the parameterize. It works great. Cheers, Harry (define indent-size (make-parameter 0)) (define-syntax let**-debug (syntax-rules () [(let**-debug tmp a ...) (parameterize ([indent-size (+ (indent-size) 5)]) (let**-dbg tmp a ...))])) (define-syntax let**-dbg (syntax-rules () [(_ tmp body) (begin (display (make-string (indent-size) #\space)) (displayln 'body) (time (begin0 body (display (make-string (indent-size) #\space)) )))] [(_ tmp a b ... body) (let ([tmp (begin (display (make-string (indent-size) #\space)) (displayln 'a) (time (begin0 a (display (make-string (indent-size) #\space)]) (let**-dbg tmp b ... body))])) On Wed, Aug 22, 2012 at 8:57 PM, Jeremiah Willcock wrote: > On Wed, 22 Aug 2012, Harry Spier wrote: > >> I have a macro let**-debug (based on the let** macro from Matthias >> Felliesen) which gives me timing information. >> >> (define-syntax let**-debug >> (syntax-rules () >>[(_ tmp body) (begin (displayln 'body) (time body))] >>[(_ tmp a b ... body) (let ([tmp (begin (displayln 'a) (time a))]) >> (let**-debug tmp b ... body))])) >> >> It works fine. The idea is that I tune using the form let**-debug and >> when I'm happy with the results I change let**-debug to let** which >> still works the same without printing the timing information. > > > What about using a parameter: > > (define timing-indent-level (make-parameter 0)) > > > (define-syntax let**-debug > (syntax-rules () > [(_ tmp body) > (begin (displayln 'body) > (time (begin0 (display (make-string (timing-indent-level) > #\space)) body)))] > > [(_ tmp a b ... body) > (let ([tmp (begin (displayln 'a) >(time (begin0 >(parameterize ([timing-indent-level (+ 2 > (timing-indent-level))]) a) >(display (make-string (timing-indent-level) > #\space)]) > >(let**-debug tmp b ... body))])) > > This assumes that the operation that you're timing is cheap compared to > printing things out and modifying parameters. If it's not, you may need to > use time-apply and print out the results yourself. > > -- Jeremiah Willcock Racket Users list: http://lists.racket-lang.org/users
[racket] Enhancing a macro
I have a macro let**-debug (based on the let** macro from Matthias Felliesen) which gives me timing information. (define-syntax let**-debug (syntax-rules () [(_ tmp body) (begin (displayln 'body) (time body))] [(_ tmp a b ... body) (let ([tmp (begin (displayln 'a) (time a))]) (let**-debug tmp b ... body))])) It works fine. The idea is that I tune using the form let**-debug and when I'm happy with the results I change let**-debug to let** which still works the same without printing the timing information. For example: (define (image-file->vectorof-rowlistof-black-strip-ranges image-file-path) (let**-debug tmp (MagickReadImage image-file-path) (begin (set-image-background-white tmp) tmp) (begin (MagickThresholdImage tmp 3) tmp) (begin (MagickDeskewImage tmp 26000) tmp) (begin (MagickThresholdImage tmp 62000) tmp) (begin (MagickWriteImage tmp (put-devanagari-page-dialog))tmp) (MagickExportImagePixels tmp 0 (MagickGetImageWidth tmp) (MagickGetImageHeight tmp) "I") (for/vector ( [rowof-intensities (in-vector tmp)]) (bytestring-intensities->listof-ranges-of-black-pixels rowof-intensities) ))) gives the output: (MagickReadImage image-file-path) cpu time: 62 real time: 54 gc time: 0 . . . . . . (for/vector ((rowof-intensities (in-vector tmp))) (bytestring-intensities->listof-ranges-of-black-pixels rowof-intensities)) cpu time: 31 real time: 27 gc time: 0 - But the above function containing the let**-debug macro is called from another let-debug** form I.e. (let**-debug page (path-to-image-of-page) (image-file->vectorof-rowlistof-black-strip-ranges page) (vectorof-rowlistof-black-strip-ranges->vectorof-strip-nodes page) (vectorof-strip-nodes->vectorof-blobs page))) So the output is: - (path-to-image-of-page) cpu time: 890 real time: 5964 gc time: 0 (image-file->vectorof-rowlistof-black-strip-ranges page) (MagickReadImage image-file-path) cpu time: 62 real time: 54 gc time: 0 . . . . . . (for/vector ((rowof-intensities (in-vector tmp))) (bytestring-intensities->listof-ranges-of-black-pixels rowof-intensities)) cpu time: 31 real time: 27 gc time: 0 cpu time: 3744 real time: 8018 gc time: 0 (vectorof-rowlistof-black-strip-ranges->vectorof-strip-nodes page) cpu time: 687 real time: 745 gc time: 187 (vectorof-strip-nodes->vectorof-blobs page) cpu time: 140 real time: 130 gc time: 0 -- But what would be more convenient is if the output was indented for each nested let**-debug so the output would look like this. -- (path-to-image-of-page) cpu time: 890 real time: 5964 gc time: 0 (image-file->vectorof-rowlistof-black-strip-ranges page) (MagickReadImage image-file-path) cpu time: 62 real time: 54 gc time: 0 . . . . . . (for/vector ((rowof-intensities (in-vector tmp))) (bytestring-intensities->listof-ranges-of-black-pixels rowof-intensities)) cpu time: 31 real time: 27 gc time: 0 cpu time: 3744 real time: 8018 gc time: 0 (vectorof-rowlistof-black-strip-ranges->vectorof-strip-nodes page) cpu time: 687 real time: 745 gc time: 187 (vectorof-strip-nodes->vectorof-blobs page) cpu time: 140 real time: 130 gc time: 0 Can someone show me how to enhance the let**-debug macro so that if a let**-debug form is in a procedure called from within another let**-debug form its output will be indented from the output of the calling let**-debug form. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] Regex's and utf-8
Would it be possible (or would it be a good idea) for character regex's to have a mode option "strict" or "not-strict" that would throw an error if its input character stream contained non utf-8 characters when in strict mode. One possible use is this. Its real easy to accidently apply a character regex to a bytestring (when you meant to apply a byte-string regex to a bytestream) and run test cases and think its working OK. I.e. to write: (regexp-match-positions* #rx"[^ÿ]+" #"...input byte string...") when you meant (regexp-match-positions* #rx#"[^ÿ]+" #". . . input byte string...") For example this appears to work: > (integer->char 255) #\ÿ > (regexp-match-positions* #rx"[^ÿ]+" #"abcÿabc") '((0 . 3) (4 . 7)) BUT > (regexp-match-positions* #rx"[^k]+" #"abcÿabc") '((0 . 3) (4 . 7)) > (regexp-match-positions* #rx".+" #"abcÿabc") '((0 . 3) (4 . 7)) > (regexp-match-positions* #rx"[^k]+" #"abcÿabc") '((0 . 3) (4 . 7)) > Having a "strict" mode would show up this error. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] FFI require statement
Thanks Eli, I'm using version 6.7.3 Q16 and it covers the functions I need with the exception of one but using your FFI example it was easy to create an FFI call to that function. There are a fair number of new functions since your FFI was written. I believe version 7 is going to change the API significantly for certain functions. At some point in time I think I will update your ImageMagick FFI to cover all of the functions but that could be several years in the future. Cheers, Harry Spier I think it should be easy to modify your On Fri, Jul 27, 2012 at 8:23 AM, Eli Barzilay wrote: > Two days ago, Harry Spier wrote: >> The FFI require statement for the ImageMagick FFI is >> "(require mzlib/foreign) (unsafe!)" > > Those examples are pretty old, and since then we switched away from > using the `unsafe!' declaration to a module with `unsafe' in its name. > I'll fix that -- but in the case of the magick interface a more > serious problem you have is that the library has (AFAICT) evolved > significantly since then. > > -- > ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: > http://barzilay.org/ Maze is Life! Racket Users list: http://lists.racket-lang.org/users
[racket] FFI require statement
The FFI require statement for the ImageMagick FFI is "(require mzlib/foreign) (unsafe!)" mzlib/foreign.rkt contains: --- (module foreign racket/base (require scheme/foreign) (provide (all-from-out scheme/foreign))) --- The FFI documentation says to use: "(require ffi/unsafe)" Can (should?) "(require mzlib/foreign) (unsafe!)" be changed to "(require ffi/unsafe)" in the ImageMagick FFI . Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
[racket] Garbage collection in Racket
1) If a data structure is out of scope and is not closed over by a closure, does that always ensure that doing a (collect-garbage) will reclaim the memory? 2) What triggers automatic garbage collection. Thanks, Harry Racket Users list: http://lists.racket-lang.org/users
[racket] FFI and Intels "Integrated Performance Primitives" library
Intel has an "integrated Performance Primitives" library see: http://software.intel.com/en-us/articles/intel-ipp/ which is optimized for intel processors and has a C interface. Can the FFI interface to this? Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Racket Virtual Machine runs out of memory
1) I've changed my data representation of the output of MagickExportImagePixels from a binary matrix of 0's and 1's to a representation of just the black pixels as a list of rows, the black pixels in each row represented by a pair giving the start and end column positions of a contiguous black pixel strip. I.e. '((row (black-pixel-strip-start-pos . black-pixel-strip-end-pos) ... ) ...) This cuts the memory usage down immensely (at least 30 to 1) and in fact simplifies my code, since I eventually produce a graph of connected pixel strips with the pixel strips represented as above with pointers added to other connected black pixel strips. So Pierpaolo thank you, but I wont be needing a bit vector package after all. 2) On Fri, Jul 20, 2012 at 10:53 PM, Eli Barzilay wrote: >you can just create a > byte string of the appropriate size, then use it directly. For > example, I added this: > > (defmagick* MagickExportImagePixels : > _MagickWand (x : _long) (y : _long) (width : _ulong) (height : _ulong) > (map : _string = "I") (storage-type : _StorageType = 'CharPixel) > (block : _bytes = (make-bytes (* width height))) > -> _status > -> block) > > (It's a bad hack, since it calls the function > `MagickExportImagePixels' but it really hard-wires the `map' and > `storage-type' arguments...) Yes, MagickExportImagePixels uses the exact same interface as "MagickGetImagePixels" and again yes it is the intensities and only the intensities I export. Is this slightly less of a hack but more importantly will it work. If I add this to the ImageMagick FFI (defwand* MagickExportImagePixels : _MagickWand (x : _long) (y : _long) (width : _ulong) (height : _ulong) (map : _string) (storage-type : _StorageType) ;; create the block, remember size and type (size : _? = (* width height (string-length map))) (type : _? = (StorageType->type storage-type)) (block : _pointer = (malloc size type)) -> _status -> block) So I can use it to produce the byte-string of intensities for this application, but also leave its generality for other applications and if I need to for other applications I can then also create a wrapper function that calls this but takes its output and produces a list of lists as you originally had it do. Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Racket Virtual Machine runs out of memory
Thank you Pierpaolo I am very interested in seeing your boolean vectors library. Thank you Jon for the suggestion of bitwise operations. Danny I'll look at Racket-bitsyntax. Thank you Eli for the suggestion of using a big byte-string. And thank you Matthias for showing how to ensure the GC . Cheers, Harry Spier On Fri, Jul 20, 2012 at 4:14 PM, Pierpaolo Bernardi wrote: > Btw, I have a boolean vectors library that you can use as is or as a > starting point. I cannot send it to you until monday, but you can find > an old copy in the archives of this ml, googling for my name + boolean > vector. > > > > 2012/7/20, Harry Spier : >> Thanks Eli, >> >> I probably have to go the route you and others suggest. But I think I >> still have a problem. Even the single operation of MagickExportPIxels >> to export the pixel data of this page to manipulate fills at least 4/7 >> of the memory before failure. And there is no guarantee that pages >> wont have more pixel data. They probably will. And as Matthias says >> the list doesn't seem "that large". >> >> Also I have 4 or 5 transformation stages of the pixel data. Will >> putting in Garbage Collection commands to get rid of transformations >> of the data I've already used help? >> >> What sets the amount of memory the Racket virtual machine uses. Is it >> a Racket parameter, Is it a function of the amount of RAM in the >> machine? Is this more a Windows problem and will switching to Linux >> help etc.? >> >> Harry Spier >> >> On Fri, Jul 20, 2012 at 1:09 PM, Eli Barzilay wrote: >>> 10 minutes ago, Harry Spier wrote: >>>> #lang racket >>>> (define l (time (build-list (* 7091 5023) (λ (x) 1 >>>> (system "PAUSE") >>>> >>>> ABORTS with Racket Virtual Machine run out of memory >>> >>> IME, the exact size where things fail is not important -- if you're >>> getting anywhere close to it, then you should revise the code to use >>> less memory. >>> >>> There was the option that was raised for using integers, which might >>> be inconvenient -- even with one (huge) integer for each row. >>> Instead, I think that it would be convenient to use one big byte >>> string for the whole array, and write some accessor functions to >>> address the contents as a matrix. The exact format of the byte string >>> can be one byte per 1/0 pixel or even more compactly, one bit per >>> pixel. The choice should depend on whatever libraries you're using >>> with the same data, to minimize translation work. (Dealing with bits >>> will make the access code a bit more complicated.) >>> >>> Currently, you're using one cons cell for each number, which is >>> probably somewhere around 3 pointers -- which is about 12 bytes per >>> bit. So just a one byte for each number would be a 12x factor, with >>> one bit per 1/0, you're at ~100x saving, which would be significant >>> enough to reduce other processing times. >>> >>> -- >>> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: >>> http://barzilay.org/ Maze is Life! >> >> >> Racket Users list: >> http://lists.racket-lang.org/users >> > > -- > Inviato dal mio dispositivo mobile Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Racket Virtual Machine runs out of memory
Thanks Eli, I probably have to go the route you and others suggest. But I think I still have a problem. Even the single operation of MagickExportPIxels to export the pixel data of this page to manipulate fills at least 4/7 of the memory before failure. And there is no guarantee that pages wont have more pixel data. They probably will. And as Matthias says the list doesn't seem "that large". Also I have 4 or 5 transformation stages of the pixel data. Will putting in Garbage Collection commands to get rid of transformations of the data I've already used help? What sets the amount of memory the Racket virtual machine uses. Is it a Racket parameter, Is it a function of the amount of RAM in the machine? Is this more a Windows problem and will switching to Linux help etc.? Harry Spier On Fri, Jul 20, 2012 at 1:09 PM, Eli Barzilay wrote: > 10 minutes ago, Harry Spier wrote: >> #lang racket >> (define l (time (build-list (* 7091 5023) (λ (x) 1 >> (system "PAUSE") >> >> ABORTS with Racket Virtual Machine run out of memory > > IME, the exact size where things fail is not important -- if you're > getting anywhere close to it, then you should revise the code to use > less memory. > > There was the option that was raised for using integers, which might > be inconvenient -- even with one (huge) integer for each row. > Instead, I think that it would be convenient to use one big byte > string for the whole array, and write some accessor functions to > address the contents as a matrix. The exact format of the byte string > can be one byte per 1/0 pixel or even more compactly, one bit per > pixel. The choice should depend on whatever libraries you're using > with the same data, to minimize translation work. (Dealing with bits > will make the access code a bit more complicated.) > > Currently, you're using one cons cell for each number, which is > probably somewhere around 3 pointers -- which is about 12 bytes per > bit. So just a one byte for each number would be a 12x factor, with > one bit per 1/0, you're at ~100x saving, which would be significant > enough to reduce other processing times. > > -- > ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: > http://barzilay.org/ Maze is Life! Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Racket Virtual Machine runs out of memory
I took Matthias's test, compiled it from DrRacket "create executable" option and ran it on my machine: Inspiron 1525 3Gbyte dual core about 6 years old. #lang racket (define l (time (build-list (* 4091 5023) (λ (x) 1 (system "PAUSE") WORKS #lang racket (define l (time (build-list (* 7091 5023) (λ (x) 1 (system "PAUSE") ABORTS with Racket Virtual Machine run out of memory Thanks, Harry On Fri, Jul 20, 2012 at 9:51 AM, Matthias Felleisen wrote: > > On Jul 20, 2012, at 9:38 AM, Harry Spier wrote: > >> Dear list members, >> >> As part of my application I create a list of lists of 1's and 0's >> from an image file. >> When the size of the list of lists is: 1055 x 1066 it works fine, >> but when the size of the list of lists is: 4091 x 5023 then the >> program aborts with the error message: >> Racket Virtual Machine run out of memory: Aborting >> >> I've narrowed the error down to where I create the l create the list. >> I.e. the error occurs during creation of the list and not during use >> of the list. >> I compiled the program with no debugging information using the >> DrRacket "create executable" option and then ran the executable. >> >> Any suggestions of what I can do to get around this? >> >> Thanks, >> Harry Spier >> >> Racket Users list: >> http://lists.racket-lang.org/users > > I just ran the below inside of DrRacket on a 2-year old MacMini: > > Welcome to DrRacket, version 5.3.0.16--2012-07-18(b111241a/d) [3m]. > Language: racket. >> (define l (time (build-list (* 4091 5023) (λ (x) 1 > cpu time: 19862 real time: 163710 gc time: 12883 >> (length l) > 20549093 >> (* 4091 5023) > 20549093 > > > So creating this list takes a while in DrRacket with the standard > configuration but traversing it is lighting fast, as you'd expect. Is it > possible that you have set a memory limit or that you are creating other > large data structures that consume space? The list is large but not that > large. > > -- Matthias > Racket Users list: http://lists.racket-lang.org/users
Re: [racket] Racket Virtual Machine runs out of memory
I've commented everything out except the calls to FFI to ImageMagick that create the imput for the procedure that creates the list and the procedure that creates the list. Basicallya: MagickReadImage MagickDeskewImage MegickExportPixels The MagickExportPixels does create another list as long as the one blowing up. But I've isolated the running out of memory as past that function call. So AFAICT the memory abort occurs when there already is a list of lists of about 20M x 1 (created by ImageMagick) and then when I try to create mine of (4091 x 5023). I'm running this on an inspiron 1525 about 6 years old with dual core and 3Gbytes. Thanks, Harry On Fri, Jul 20, 2012 at 9:51 AM, Matthias Felleisen wrote: > > On Jul 20, 2012, at 9:38 AM, Harry Spier wrote: > >> Dear list members, >> >> As part of my application I create a list of lists of 1's and 0's >> from an image file. >> When the size of the list of lists is: 1055 x 1066 it works fine, >> but when the size of the list of lists is: 4091 x 5023 then the >> program aborts with the error message: >> Racket Virtual Machine run out of memory: Aborting >> >> I've narrowed the error down to where I create the l create the list. >> I.e. the error occurs during creation of the list and not during use >> of the list. >> I compiled the program with no debugging information using the >> DrRacket "create executable" option and then ran the executable. >> >> Any suggestions of what I can do to get around this? >> >> Thanks, >> Harry Spier >> >> Racket Users list: >> http://lists.racket-lang.org/users > > I just ran the below inside of DrRacket on a 2-year old MacMini: > > Welcome to DrRacket, version 5.3.0.16--2012-07-18(b111241a/d) [3m]. > Language: racket. >> (define l (time (build-list (* 4091 5023) (λ (x) 1 > cpu time: 19862 real time: 163710 gc time: 12883 >> (length l) > 20549093 >> (* 4091 5023) > 20549093 > > > So creating this list takes a while in DrRacket with the standard > configuration but traversing it is lighting fast, as you'd expect. Is it > possible that you have set a memory limit or that you are creating other > large data structures that consume space? The list is large but not that > large. > > -- Matthias > Racket Users list: http://lists.racket-lang.org/users
[racket] Racket Virtual Machine runs out of memory
Dear list members, As part of my application I create a list of lists of 1's and 0's from an image file. When the size of the list of lists is: 1055 x 1066 it works fine, but when the size of the list of lists is: 4091 x 5023 then the program aborts with the error message: Racket Virtual Machine run out of memory: Aborting I've narrowed the error down to where I create the l create the list. I.e. the error occurs during creation of the list and not during use of the list. I compiled the program with no debugging information using the DrRacket "create executable" option and then ran the executable. Any suggestions of what I can do to get around this? Thanks, Harry Spier Racket Users list: http://lists.racket-lang.org/users