Re: [racket-users] Re: Functional object-oriented programming

2017-02-08 Thread Philip McGrath
Note, though, that struct-copy needs to be given the type of the resulting structure statically, at compile time, and "the result of *struct-expr* can be an instance of a sub-type of *id*, but the resulting copy is an immediate instance of *id* (not the sub-type)." [1] If you have a complex

[racket-users] ->* contracts not enforcing #:pre/desc pre-conditions

2017-02-05 Thread Philip McGrath
Contracts created with ->* don't seem to be enforcing their #:pre/desc pre-conditions. Given this program: > #lang racket > (module private racket > (provide get-apples-allowed? >get-apples) > (define get-apples-allowed? > (make-parameter #f)) > (define (get-apples) >

Re: [racket-users] Basic macro question

2017-02-05 Thread Philip McGrath
You need to have the lexical context information of x, y, and z come from stx: otherwise, they will be protected by macro expansion (as a matter of hygiene). Here's one way to do it: > (define-syntax (a stx) > (syntax-parse stx > [(a) > (with-syntax ([x (datum->syntax stx 'x)] >

Re: [racket-users] Client side web applications in Racket

2017-01-22 Thread Philip McGrath
My understanding is that implementation is still lagging, but I believe ES6 specifies proper tail calls, yes? -Philip On Sun, Jan 22, 2017 at 3:17 PM, Neil Van Dyke wrote: > Quoting "https://github.com/vishesh/racketscript/blob/master/README.md": > >> RacketScript

Re: [racket-users] Re: [ANN] Simple, Deterministic Dictionaries (ddict)

2017-01-23 Thread Philip McGrath
Have you considered implementing the gen:dict generic interface? -Philip On Mon, Jan 23, 2017 at 7:58 AM, Greg Trzeciak wrote: > On Monday, January 23, 2017 at 2:18:53 PM UTC+1, Andrew Kent wrote: > > > ddict seeks to mimic Racket's `hash` API as much as possible and is >

Re: [racket-users] Re: Package layout in docs

2017-01-30 Thread Philip McGrath
I was also going to suggest the ring system as a way of giving more information without imposing an unnecessary artificial distinction. In general I'm enthusiastic about the benefits of not having a sharp dividing line, but it would be useful to show more clearly in the documentation which

[racket-users] Deserialization broken for class-based objects with contracted interfaces

2017-01-21 Thread Philip McGrath
Deserialization appears to be broken for class-based objects that implement interfaces with contracted methods. Given this example module: #lang racket (require racket/class racket/serialize) (define foo<%> (interface () [foo-method (->m any/c)])) (define-serializable-class* foo%

Re: [racket-users] IMAP with racket

2017-02-11 Thread Philip McGrath
I have used net/imap with gmail, though it does require enabling "less secure apps" (the link George sent has instructions). I believe the only "less secure" part is that you want to use IMAP for authentication and not OAuth. -Philip On Sat, Feb 11, 2017 at 7:55 AM, George Neuner

Re: [racket-users] scribble defproc?

2017-01-17 Thread Philip McGrath
t; (serial-lambda () > (format "I was run on place ~a." > (current-place)) Then at the REPL, you can do: > > (main) > "I was run on place p." -Philip On Tue, Jan 17,

Re: [racket-users] scribble defproc?

2017-01-17 Thread Philip McGrath
For a quick example (without places), if you enter this in the definitions window of Dr. Racket: > #lang racket > (require web-server/lang/serial-lambda > racket/serialize > ) > (define serialized-proc > (serialize (serial-lambda (x) >(printf "Your number is:

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
Not the question you asked, but instead of with-output-to-string, if you're discarding the output, you might prefer: (parameterize ([current-output-port (open-output-nowhere)]) ...) -Philip On Thu, Jan 19, 2017 at 4:51 PM, Philip McGrath <phi...@philipmcgrath.com> wrote: > I haven

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
I haven't looked in detail, but two quick thoughts: - When I evaluate (find-system-path 'run-file) in Dr. Racket, either inside a module or in the REPL, I get # - Have you looked at (current-directory)? In Dr. Racket, if the file has been saved, that returns the path to the directory

Re: [racket-users] Paths in Dr Racket do not match paths in shell

2017-01-19 Thread Philip McGrath
Assuming I understand it correctly, I think the problem in the original is that, in Dr. Racket, (find-system-path 'run-file) returns the path of Dr. Racket, whereas at the shell it returns the path of the file being run. It's a hack, but I think you could make a quick and dirty solution to

Re: [racket-users] Serializing macro transformer procedures

2017-01-19 Thread Philip McGrath
It might help if you could explain in more detail what you're trying to do: I'm not sure I understand what you mean by "bring macro transformer procedures down to run-time". -Philip On Wed, Jan 18, 2017 at 6:24 PM, Alex Knauth wrote: > I'm trying to use serial-lambda in

Re: [racket-users] How to watch the filesystem

2017-01-19 Thread Philip McGrath
Because you mentioned "the user moved the mouse", note that mouse-event% and other things referred to as "events" in the GUI library are not synchronizable events that can be used with sync. -Philip On Thu, Jan 19, 2017 at 2:58 PM, Neil Van Dyke wrote: > David Storrs

Re: [racket-users] Serializing macro transformer procedures

2017-01-20 Thread Philip McGrath
t; On Jan 19, 2017, at 8:44 PM, Philip McGrath <phi...@philipmcgrath.com> > wrote: > > It might help if you could explain in more detail what you're trying to > do: I'm not sure I understand what you mean by "bring macro transformer > procedures down to run-time". > >

Re: [racket-users] Re: Scrolling in racket/gui

2017-03-01 Thread Philip McGrath
not finding how to change the scrolling position of the panel if I do catch one of those events. (Or maybe there's a way to do it without implementing it myself?) -Philip On Wed, Mar 1, 2017 at 5:39 PM, Alex Harsanyi <alexharsa...@gmail.com> wrote: > On Thursday, March 2, 2017 at 4:16:47 AM UTC+

Re: [racket-users] udelim package -- more parens than you can shake a stick at

2016-09-25 Thread Philip McGrath
I second the idea that the documentation could be clearer on the difference between "#lang scribble/base" and friends and what can be done with the at-reader in general, as shown in languages like "scribble/text" and "scribble/html". Despite having used both "scribble/base"-family languages and

[racket-users] set! in #lang web-server

2016-10-04 Thread Philip McGrath
In #lang web-server, set! seems to behave differently with local vs. top-level variables. For example: > #lang web-server/base (define x 0) > (displayln x) ;; displays 0 > (set! x (add1 x)) > (displayln x) ;; displays 1 > (let () > (define y 0) > (displayln y) ;; displays 0 > (set! y (add1

[racket-users] git-checkout-credentials

2016-10-27 Thread Philip McGrath
I'm excited by the ability to use authentication-required git repositories with the package system. > - The package system supports authentication when installing packages > from git, using the `raco pkg config git-checkout-credentials` > configuration option. > What is the value to be

Re: [racket-users] Putting Racket into the database or, more sanely, storing continuations

2016-10-29 Thread Philip McGrath
If you want to go this way (and I suspect that there may be a better way), rather than using eval, I would look at serial-lambda from web-server/lang/serial-lambda, which lets you create closures (like the values produced by lambda) that could be put into a TEXT field using serialize and write.

Re: [racket-users] Re: Building regexen in at-exp

2016-10-28 Thread Philip McGrath
*@pregexp{^@a}* is read as *(pregexp "^" a)* [you can test this by evaluating the quoted form, '*@pregexp{^@a}* ], but the function pregexp expects a single string as its first argument (and, apparently, a function or #f as its optional second argument). More generally, the body part of an

Re: [racket-users] Funtional programming and the maximum of something

2016-10-22 Thread Philip McGrath
I'm not sure if I understand what you're tying to do correctly, but here's one way to do it (or one way to do something, at least): (define (process-list-of-lists list-of-lists) (apply map (λ args (apply max args)) list-of-lists)) (process-list-of-lists

[racket-users] flat-contract-with-reason (should be flat-contract-with-explanation ?)

2016-10-23 Thread Philip McGrath
The Racket Reference documents a function "flat-contract-with-reason"; however, in #lang racket, I get an unbound identifier error for "flat-contract-with-reason". I noticed that racket/contract/base does export a function

[racket-users] Error ("assignment disallowed") when deserializing class-based objects

2016-10-20 Thread Philip McGrath
I'm looking into whether Racket's class/object system might be useful for one of my projects, and I am stumped by an error when deserializing objects. I've managed to produce the error a few different ways, but here is a fairly minimal example: > (define-serializable-class ok% object%

Re: [racket-users] filesystem-change-evt and thread-suspend

2016-11-14 Thread Philip McGrath
his: > >(define-values (dummy-i dummy-o) (make-pipe)) >(sync dummy-i (wrap-evt s (lambda (v) 'ok))) > > Having a pipe in the set of events sends the scheduler into a path that > doesn't have the bug. > > > At Sun, 13 Nov 2016 17:43:43 -0800 (PST), Philip McGrath wr

Re: [racket-users] raco run but (please) dont process the docs

2016-11-14 Thread Philip McGrath
On the subject of package documentation, http://docs.racket-lang.org/pkg/catalog-protocol.html appears to be incorrect when it says that: The source for the PLT-hosted package catalog is in the (collection-file-path "pkg-catalog" "meta") directory of the full Racket

[racket-users] filesystem-change-evt and thread-suspend

2016-11-13 Thread Philip McGrath
Hi everyone, I've been trying to get to know Racket's threads and particularly filesystem-change-evt, and I've come to a point of confusion. I thought that a filesystem-change-evt's synchronization result was supposed to be the event itself, which it is most of the time, but in combination

Re: [racket-users] When to use functions vs macros

2016-10-11 Thread Philip McGrath
This doesn't address functions vs macros, but have you considered call-with-transaction ? On Tue, Oct 11, 2016 at 1:10 PM Greg Hendershott

Re: [racket-users] Re: Operations that create objects

2016-12-16 Thread Philip McGrath
The outer function must return the inner function (or otherwise make it reachable, perhaps inside some data structure). For example: > (define (make-counter init) (define (counter) (set! init (add1 init)) init) (displayln "Making a counter!") counter) > (define

[racket-users] Scribble equivalent of rowspan

2016-11-29 Thread Philip McGrath
A very rookie question: I am trying to figure out how to specify the equivalent of HTML's rowspan attribute for tabular from scribble/base: that is, to have a cell which spans more than one row. In LaTeX, I think I would use "multirow" (but I'm no LaTeX expert). I know so know about 'cont, but I

[racket-users] Traits, inspectors, and serializable classes

2017-01-02 Thread Philip McGrath
Is there (or, if not, could there be) a way to specify the inspector when working with traits (from racket/trait)? I can write > (mixin () () > (inspect #f) ... ) but "inspect" does not seem a valid clause inside the "trait" form. (I could also imagine that this might need to be determined

Re: [racket-users] Errors in (Dr)Racket

2017-01-02 Thread Philip McGrath
Stephen's mention of web server code reminded of me one of the very few situations when I've struggled with Racket error messages, so I'll both share an example and explain why I haven't complained about it before. Here's a buggy program: > #lang web-server > (require web-server/servlet-env >

Re: [racket-users] Fix Ctr+F search on the new website?

2016-12-29 Thread Philip McGrath
I can confirm that Command F searching for "extensive" with Chrome 55.0.2883.95 on Mac OS Sierra 10.12.1 gives me this problem: it finds one match (under the "Batteries Included") image, but I can't see the highlighting until I hover over the image. -Philip On Thu, Dec 29, 2016 at 11:42 AM, Leif

Re: [racket-users] Errors in (Dr)Racket

2017-01-02 Thread Philip McGrath
azily-enforced "serializable/c", especially as "serializable?" doesn't check the contents of nested values. All just pipe dreams, though! On Mon, Jan 2, 2017 at 9:12 AM, Matthias Felleisen <matth...@ccs.neu.edu> wrote: > > On Jan 2, 2017, at 7:25 AM, Philip McGr

Re: [racket-users] Add fns or at least sample code for getting column names from table?

2016-12-28 Thread Philip McGrath
Something like this would be really good. I also, relatively recently, discovered the "name" fields when I happened to look at a rows-result directly, and being able to work with columns by name rather than by position is much better. I guess I should have realized there was some way of doing

Re: [racket-users] Mobile Friendly HTML in Scribble?

2016-12-27 Thread Philip McGrath
Has something changed recently in the CSS for the Racket documentation? I thought that formerly the phone layout was equivalent to what happens if you manually resize a desktop/laptop browser window to be quite narrow: the sidebar / table of contents goes away and a navigation bar appears at the

[racket-users] Spreadsheet-style tables with Scribble

2017-01-14 Thread Philip McGrath
thing for me to do would be to decide on a maximum number of rows and columns per page and write code to produce multiple tables, but this is far from ideal, especially as the results would make little sense in HTML output. Better work-arounds would also be welcome! Thanks, Philip McGrath --

Re: [racket-users] scribble defproc?

2017-01-15 Thread Philip McGrath
I would strongly consider using serial-lambda (from the web server libraries: http://docs.racket-lang.org/web-server-internal/closure.html?q=serial-lambda), which creates a procedure that can be serialized using racket/serialize and sent to a place, rather than (I assume) relying on eval.

[racket-users] Contracts not enforced with serial-lambda

2017-03-27 Thread Philip McGrath
I've been playing around with trying to attach contracts to serializable procedures created with serial-lambda. What I've been trying to do hasn't been working, and I've also come across some surprising behavior. For example, this program: > #lang racket > (require web-server/lang/serial-lambda >

Re: [racket-users] A new OOP programming construct? [slightly long post]

2017-03-30 Thread Philip McGrath
I also find this problem annoying and would be very interested in a linguistic solution (or alternatively a reason why I shouldn't be getting myself into this problem so often). Recently I've been trying to work this by writing functions like this, which at least abstract out the boilerplate: >

[racket-users] syntax-parse: using expr/c with ~optional

2017-03-20 Thread Philip McGrath
Using expr/c to attach a contract to a macro sub-pattern doesn't seem to work with ~optional, even when the attribute is bound with #:defaults. For example, this program: > #lang racket (require (for-syntax syntax/parse)) > (define-syntax (example stx) > (syntax-parse stx > [(_ (~optional

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-21 Thread Philip McGrath
I would do: (with-input-from-string from-db (λ () (deserialize (read On Tue, Mar 21, 2017 at 4:48 PM Jon Zeppieri wrote: > On Tue, Mar 21, 2017 at 5:44 PM, Jon Zeppieri wrote: > > However, postgres (if that's what you're using) > > has

Re: [racket-users] syntax-parse: using expr/c with ~optional

2017-03-21 Thread Philip McGrath
plicate attribute in: tail". On Mon, Mar 20, 2017 at 1:18 PM Alex Knauth <alexan...@knauth.org> wrote: > > On Mar 20, 2017, at 11:04 AM, Philip McGrath <phi...@philipmcgrath.com> > wrote: > > Using expr/c to attach a contract to a macro sub-pattern doesn

Re: [racket-users] How to store a list (or struct...) in SQL and extract again as original Racket value

2017-03-22 Thread Philip McGrath
To work with strings for the database, do something like this: (define (serialize-to-string v) (with-output-to-string (λ () (write (serialize v) (define (deserialize-from-string str) (with-input-from-string str (λ () (deserialize (read) On Tuesday, March 21, 2017 at 8:52:55 PM

[racket-users] Package documentation link issue

2017-04-11 Thread Philip McGrath
I recently posted a package "recaptcha", and I noticed a problem with the documentation link that I'm not sure how to fix. Google stylizes the name as reCAPTCHA, and I've capitalized it that way in the title of the documentation, but I called the actual package "recaptcha" so that you can "raco

[racket-users] Names for flat-contract-with-explanation contracts

2017-04-11 Thread Philip McGrath
Is it possible to give a name to a contract created with contract-with-explanation? To illustrate, this example: > #lang racket > (define has-explanation/c > (flat-contract-with-explanation >(λ (val) > (λ (blame) >(raise-blame-error blame val >

[racket-users] Scribbling documentation for a module beginning with _

2017-04-13 Thread Philip McGrath
I'm trying to write documentation for a module named _-exp, and I'm running into a problem because (I think) of the way underscores are treated by racketblock . Using

Re: [racket-users] Preventing browser frame from terminating evaluation thread?

2017-04-18 Thread Philip McGrath
t;do more here...\n") > > Or you could make `yield` wait on a semaphore that is never posted, so > that the application doesn't quit until `exit` is called. > > At Mon, 17 Apr 2017 23:53:49 -0500, Philip McGrath wrote: > > It's a little ugly, but you can change the exit h

Re: [racket-users] macro definitions with #lang racket/base vs #lang racket

2017-03-14 Thread Philip McGrath
#lang racket also provides racket/base in the transformer environment. -Philip On Tue, Mar 14, 2017 at 5:45 AM, NeverTooOldToCode wrote: > From Fear of Macros again, all input in the DrRacket definition window. > > This works: > > #lang racket/base > > (require

Re: [racket-users] refactoring help/tools?

2017-03-13 Thread Philip McGrath
raco check-requires might do some of what you want. -Philip On Mon, Mar 13, 2017 at 12:18 PM, Jay McCarthy wrote: > racket-mode in Emacs does this > > Jay > > On Mon, Mar 13, 2017 at 1:17 PM Dan Liebgold > wrote: > >> Hi - >> >> In

Re: [racket-users] Why does 1 count as numeric in xexpr, but 0 does not?

2017-03-13 Thread Philip McGrath
Numbers in x-expressions are interpreted as XML entities, not as the string representation of the number. The value of (xexpr->string '(html 1)), to use your example, is "". The 1 represents the character that Racket would represent as #\u0001, i.e. the value of (integer->char 1). In contrast,

Re: [racket-users] How to build new formlets that allow passing default values (such as hidden)?

2017-03-14 Thread Philip McGrath
In this case it will work despite being a hack, because you know that your id argument affects only the display stage, not the processing stage: however, you can't know in general that this will work for dynamically generated formlets, and personally I would therefore be reluctant to rely on this,

[racket-users] Scrolling in racket/gui

2017-03-01 Thread Philip McGrath
This seems like it should be a simple question, but I can't figure out how to get a scroll bar in a gui application like this one: #lang racket/gui > (define frame > (new frame% [label "Example"])) > (for ([letter '("A" "B" "C" "D")]) > (define grp > (new group-box-panel% >

Re: [racket-users] Preventing browser frame from terminating evaluation thread?

2017-04-17 Thread Philip McGrath
It's a little ugly, but you can change the exit handler: (exit-handler (λ (x) (displayln "Called exit"))) -Philip On Mon, Apr 17, 2017 at 8:57 PM, Matt Jadud wrote: > Hi all, > > I would like to spawn a browser frame, but I'd like it if the frame did > not terminate the

[racket-users] Trouble with "on delete cascade" using sqlite

2017-04-18 Thread Philip McGrath
The following program returns '(#("demo" "j...@example.com")), whereas I think it should return '(), because I expect deleting the row from "tUsers" to delete the corresponding row in "tEmail". Is this a bug in the db library (or elsewhere, or am I doing something wrong)? #lang at-exp racket

Re: [racket-users] Trouble with "on delete cascade" using sqlite

2017-04-18 Thread Philip McGrath
to turn the FKs on before it will work. > > Just add this line before the first 'insert into tUsers' and then it will > work: > > (query-exec db "PRAGMA foreign_keys = ON") > > > On Tue, Apr 18, 2017 at 5:33 PM, Philip McGrath <phi...@philipmcgrath.com> &g

Re: [racket-users] Setting parameters between files does not work as expected

2017-04-24 Thread Philip McGrath
Another thing that might be relevant: > > In contrast, direct assignment to a parameter (by calling the parameter > procedure with a value) changes the value in a thread cell, and therefore > changes the setting only for the current thread. > http://docs.racket-lang.org/reference/parameters.html

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-28 Thread Philip McGrath
Specifically, as Robby said earlier, `list?` is memoized, so e.g. (first (rest (build-list 10 values))) only pays this price once. And `list?` rejects pairs that have cycles. -Philip On Fri, Jul 28, 2017 at 5:51 AM, Matthias Felleisen wrote: > > first and rest were

Re: [racket-users] Menu bar won't show

2017-08-14 Thread Philip McGrath
I suspect the confusion is that on Mac OS, the menu-bar% is drawn at the top of the screen (the same as DrRacket's "File" menu etc.), not inside the window itself. This code is working for me with Racket 6.9 on Mac OS 10.12.5. -Philip On Mon, Aug 14, 2017 at 7:09 PM, James

[racket-users] Adding terms to Scribble table of contents

2017-07-07 Thread Philip McGrath
I am trying to use Scribble to document some things that are not Racket bindings. I can get the linking and typesetting behavior I want by building on top of elemtag and elemref, but I would also like the defining instances to be added to the table of contents in the same way as bindings defined

[racket-users] Pixelated results from pict->bitmap

2017-07-13 Thread Philip McGrath
Bitmaps created using pict->bitmap look pixelated to me on screen (on Mac OS in "Retina" mode, which I suspect might be relevant). I initially discovered this when using picts as labels for message% instances like this: #lang racket/gui (require pict) (define f (new frame% [label

[racket-users] Scribble PDF output breaks when using include-section with scribble/lp2

2017-07-14 Thread Philip McGrath
I have a document written in #lang scribble/manual that used include-section to include a section written in #lang scribble/lp2. It renders perfectly to HTML, and I can render both the literate program and the main document, with the inclusion of the literate program commented out, to PDF

Re: [racket-users] ?

2017-07-16 Thread Philip McGrath
Could you share the code that is producing the error? The following, for example, defines a struct with two fields: (struct point (x y)) -Philip On Sun, Jul 16, 2017 at 7:23 AM, Masto Fine wrote: > i have a problem , i want to define a structure white many fields

Re: [racket-users] Replacing multiple characters in a string?

2017-07-08 Thread Philip McGrath
This works, for instance (and I would much prefer case to hash-ref): #lang typed/racket (regexp-replace* #rx"[ABC]" "ABCABC" (λ ([c : String] . _) (case c [("A") "AC"] [("B") "BA"]

[racket-users] Contracts in interrelated signatures

2017-07-08 Thread Philip McGrath
Working through the chapter on units in the Racket guide, it shows how to translate the comment-specified contracts on toy-factory^ to enforced contracts: (define-signature contracted-toy-factory^ ((contracted [build-toys (-> integer? (listof toy?))] [repaint(-> toy? symbol? toy?)]

[racket-users] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
I'm confused about why the following program is blaming the server for the client's misuse of an applicable struct instance. More generally, I've tried doing this in several different ways, and I can't figure out how to make applicable structs that are still protected by contracts after

Re: [racket-users] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
gt; On Jul 23, 2017, at 8:54 PM, Philip McGrath <philip.mcgr...@gmail.com> > wrote: > > I'm confused about why the following program is blaming the server for the > client's misuse of an applicable struct instance. More generally, I've > tried doing this in several different ways

Re: [racket-users] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
Here is the problem with serialization, without my attempts to mitigate it: #lang racket (module server racket (require racket/serialize) (provide (contract-out [adder (-> natural-number/c (-> natural-number/c natural-number/c))]))

Re: [racket-users] Blame for contracts on applicable serializable structs

2017-07-23 Thread Philip McGrath
` rather than `+`, but (as I now understand) it blamed the `server` module for all violations. -Philip On Sun, Jul 23, 2017 at 9:27 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote: > The original example had an explicit deserializer: > > At Sun, 23 Jul 2017 19:54:43 -0500, Phili

Re: [racket-users] Blame for contracts on applicable serializable structs

2017-07-24 Thread Philip McGrath
2017, at 10:50 PM, Philip McGrath <phi...@philipmcgrath.com> > wrote: > > If I'm following correctly, I think that's what I was trying to do, but > I'm unclear how to give `make-deserialize-info` a variant of `make-adder` > that has a contract. The initial example with `define

Re: [racket-users] [ANN] MessagePack implementation for Racke

2017-07-24 Thread Philip McGrath
You probably want `integer-in` for the contract on `ext`. Have you read about the special treatment of test submodules? https://docs.racket-lang.org/guide/Module_Syntax.html#%28part._main-and-test%29 That is the idiomatic Racket way to write tests that run automatically when you want them and

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-27 Thread Philip McGrath
Eliminating the optional argument and using match-define to avoid any redundant checking on first and rest gets me a significant speedup: #lang racket (collect-garbage) (collect-garbage) (collect-garbage) (define as (build-list 100 (λ (n) (random 100 (define bs (build-list 100 (λ

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-27 Thread Philip McGrath
;2448129646 -Philip On Thu, Jul 27, 2017 at 8:13 PM, Philip McGrath <phi...@philipmcgrath.com> wrote: > Eliminating the optional argument and using match-define to avoid any > redundant checking on first and rest gets me a significant speedup: > > #lang racket > > (col

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-27 Thread Philip McGrath
`match-define` seems to be the real source of the speedup for me: #lang racket (define (as) (build-list 100 (λ (n) (random 100 (define (bs) (build-list 100 (λ (n) (random 100 (define (f as bs [acc 0]) (if (or (null? as) (null? bs)) acc (f (rest as) (rest bs) (+

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-26 Thread Philip McGrath
Re multiple return values, you can write (call-with-values (λ () (values 1 2 3)) list) Because this problem bugs me, I've also written a package adjutor that includes values->list, list->values, and for/fold/define: http://docs.racket-lang.org/adjutor/index.html -Philip On Wed, Jul 26, 2017 at

Re: [racket-users] Custom reader that's a strict subset of racket

2017-06-29 Thread Philip McGrath
I think you might be able to leave the reader as-is and just re-define #%datum to reject whatever kinds of literal data you don't want to allow. -Philip On Thu, Jun 29, 2017 at 9:44 PM, Sam Waxman wrote: > Hello, > > I'm building a #lang, and I don't want it to have a few

[racket-users] Missing request-post-data/raw (from web-server/http)

2017-06-29 Thread Philip McGrath
I'm working on a Racket web application for which I need to proxy certain requests to a non-Racket service over HTTP. I've built a very basic proxy on top of http-sendrecv/url that works quite well for the most part. For POST requests, I pass the request-post-data/raw of the original request as

Re: [racket-users] Missing request-post-data/raw (from web-server/http)

2017-06-29 Thread Philip McGrath
Thanks for your comments. The only legal files to upload in this case are plain text, so I'm not too worried about size. I'm relying on the web-server libraries to deal with any malicious attempts to send overwhelmingly large files (if that's a bad idea, I'd definitely appreciate hearing it!).

Re: [racket-users] Missing request-post-data/raw (from web-server/http)

2017-06-30 Thread Philip McGrath
The logic of the current behavior is that at the > "application" level there is no POST data, but there is only form > data, but because of "transport" level constraints on the length of > URIs it had to be sent in the data part of the transport layer.) > > Jay

Re: [racket-users] can `impersonate-hash` really filter out hash keys?

2017-06-30 Thread Philip McGrath
If it doesn't absolutely have to be a hash, you can definitely make dict-ref and dict-iterate-key etc. work differently. -Philip On Fri, Jun 30, 2017 at 12:15 PM, Matthew Butterick wrote: > > > On Jun 30, 2017, at 10:07 AM, Robby Findler > wrote:

Re: [racket-users] Defining new exception types with guards and default messages

2017-06-29 Thread Philip McGrath
Note, though, (having tried this) that putting a contract on the guard will give you undesirable blame behavior unless you use any/c for all the domain contracts as Matthias did. The guard must be able to accept all arguments, so the server module will be blamed if a client calls the constructor

Re: [racket-users] Catching syntax errors

2017-06-30 Thread Philip McGrath
If testing with parenthetical syntax is sufficient, you might want something like this: #lang racket (with-handlers ([exn:fail:syntax? values]) (eval `(module bad racket (define foo (define bar 1))) (make-base-namespace))) which returns: (exn:fail:syntax "define: not allowed in an

Re: [racket-users] Best way to write run-once-and-cache functions?

2017-04-25 Thread Philip McGrath
In this very simple case, I would probably not define a function at all, just something like (define conf (with-input-from-file "db.conf" read-json)) You may also find yourself wanting define-runtime-path from racket/runtime-path. On Tue, Apr 25, 2017 at 11:12 PM, David Storrs

[racket-users] Lexical context for all-defined-out

2017-04-26 Thread Philip McGrath
I'm working on a #%module-begin variant that provides all module-level bindings, and I'm having trouble finding the right way to give lexical context to all-defined-out. The issue (IIUC) is that all-defined-out only exports identifiers "that have the same lexical context as the (all-defined-out)

Re: [racket-users] Lexical context for all-defined-out

2017-04-26 Thread Philip McGrath
ically, instead of the scopes on the > identifier. > > So, in place of > > (datum->syntax stx '(all-defined-out))) > > you can use > > (datum->syntax stx `(,#'all-defined-out))) > > and then you don't have to export `all-defined-out`. > > At Wed, 26 Ap

Re: [racket-users] Setting parameters between files does not work as expected

2017-04-25 Thread Philip McGrath
that the hash be immutable, though mostly for ease of reasoning. -Philip On Tue, Apr 25, 2017 at 12:48 PM, David Storrs <david.sto...@gmail.com> wrote: > > > On Mon, Apr 24, 2017 at 9:46 PM, Philip McGrath <phi...@philipmcgrath.com> > wrote: > >> Ano

Re: [racket-users] Speeding up graphics / moving away from 2htdp/image

2017-04-29 Thread Philip McGrath
I think that would be because "the *draw* is called during the dynamic extent of the call to dc as part of the contract checking." -Philip On Sat, Apr 29, 2017 at 2:58 AM, Daniel

[racket-users] DrRacket preferences error

2017-04-29 Thread Philip McGrath
After upgrading to 6.9, I'm getting the following "DrRacket Internal Error" when I try to open the preferences menu on MacOS: preferences:get: tried to get a preference but no default set for 'scribble-reindent-paragraph-width context...: /Applications/Racket

Re: [racket-users] DrRacket preferences error

2017-04-29 Thread Philip McGrath
es either one > of the #lang scribble variants or an at-exp before opening the > preferences dialog? > > I believe that if you don't do that before opening the preferences > dialog the first time, you can work around this error. > > Robby > > > On Sat, Apr 29,

Re: [racket-users] Re: table lookup shorthands?

2017-08-07 Thread Philip McGrath
Others have given good reasons to take alternate approaches, but if I were writing your define-lookup-function macro, I would avoid using a dictionary type and have the macro expand to `case`, like this: (define-syntax define-lookup-function (syntax-parser [(_ name:id [lhs:expr

Re: [racket-users] Generate function defintions at compile time

2017-08-22 Thread Philip McGrath
I guess my first question would be where does the hash table in nvim/api/specification.rkt come from, where else is it used, and is it necessary for the format to be what it currently is. For example, the first thing that jumped out at me is that you're using strings for all the hash keys rather

Re: [racket-users] surprising [to me and students] printer behavior with #:transparent

2017-05-16 Thread Philip McGrath
The printer tries to produce an expression that you could copy, paste, and evaluate. Transparent structs aren't quotable but do support constructor-style printing, so the printer uses constructor-style printing for values that contain transparent structs. (Apparently you can configure this in

Re: [racket-users] Naive question on how to capitalize only the first word of a string

2017-06-19 Thread Philip McGrath
I don't think there's a library function that does what you want, so you'd need to define your own. Here's one way to do it: (define (capitalize-first-letter str) (cond [(non-empty-string? str) (define first-letter-str (substring str 0 1)) (define rest-str (substring

[racket-users] Controlling the installation-specific "Racket Documentation" page

2017-06-21 Thread Philip McGrath
Hi everyone, I'm looking for information on how to customize the top-level "Racket Documentation" page generated by Scribble for a particular Racket installation. Specifically, I am working with a group that has now accumulated a few internal Racket packages with documentation, as well as some

[racket-users] Consulting parameters in #lang web-server servlets

2017-06-22 Thread Philip McGrath
I'm encountering some strange behavior when using parameters with my (stateless) web servlets. I want to check the value of a cookie every time a request is made to my server and make a Racket value derived from the cookie's value available for use within the servlet code. Since this value

Re: [racket-users] Consulting parameters in #lang web-server servlets

2017-06-22 Thread Philip McGrath
(wrap-dispatcher (dispatch/servlet start #:stateless? #t))) #:banner? #t) Thanks so much! Philip -Philip On Thu, Jun 22, 2017 at 9:31 AM, Jay McCarthy <jay.mccar...@gmail.com> wrote: > On Thu, Jun 22, 2017 at 10:21 AM, Philip

[racket-users] DrRacket becomes unresponsive when confronted with a long line

2017-06-26 Thread Philip McGrath
When I open the attached file (which contains a very long line) in DrRacket and attempt to type a closing parenthesis (either ")" or "]") on line 4 (i.e. to close the define form), DrRacket becomes unresponsive until forcibly killed (at least for several minutes, and even the caret stops

[racket-users] Re: DrRacket becomes unresponsive when confronted with a long line

2017-06-26 Thread Philip McGrath
ckers onto the screen, but it's gone before I can read it. file->value for me, for now. -Philip On Mon, Jun 26, 2017 at 10:22 PM, Philip McGrath <phi...@philipmcgrath.com> wrote: > When I open the attached file (which contains a very long line) in > DrRacket and attempt to type a cl

Fwd: [racket-users] Racket APIs doesn't strip Byte Order Mark (BOM) when reading strings from UTF-8 files

2017-06-24 Thread Philip McGrath
I'm grateful to have seen this post so that I had some idea what was going on when read-xml just gave me the exception: > > read-xml: parse-error: expected root element - received "\uFEFF" on a file that had been validated by libxml. I confess that this is a bit low-level for my expertise, but I

  1   2   3   4   >