[racket-users] Re: Escape continuations for fussy code

2021-10-21 Thread Ryan Kramer
Good question. I know I have done exactly that in the past, but I guess I 
just forgot about that pattern in my more recent code. Other possible 
reasons include "because I don't like the unnecessary parens around a 
single id" and "because I like the indentation of let* (4 chars) much 
better than let*-values (11 chars) and want to delay introducing 
let*-values until it becomes necessary."

On Wednesday, October 20, 2021 at 7:54:37 PM UTC-5 gneuner2 wrote:

> On Wed, 20 Oct 2021 09:44:42 -0700 (PDT), Ryan Kramer
>  wrote:
>
> > :
> >The other feature of let++ is that it also supports let-values. (Having 
> to 
> >nest "let, then let-values, then let again" was another reason my code 
> >would get too indented for my taste.)
> > :
>
> Possibly a stupid question, but ...
>
> What causes you to /have to/ 'nest "let, then let-values, then let
> again"'? Assuming no intervening body code, a single let*-values
> could cover all of it (with the same semantics).
>
>

-- 
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/f7839fa2-c355-4165-bbe0-49e3e028ebd5n%40googlegroups.com.


Re: [racket-users] Re: Escape continuations for fussy code

2021-10-20 Thread Ryan Kramer
 I guess I'll pile on too. My approach was `let++` which I rename to `let*` 
because (I think) it is backwards compatible. The pattern for early exit is 
`#:break (when test-expr result-expr)` so the previous example would look 
like this:

(let* (#:break (when (not (foo? x))
 #f)
   [y (bar x)]
   [z (jazz x y)]
   #:break (when (not (loopy? z))
 #f)
   [a (yowza z)]
   #:break (when (not (string? a))
 'ugh)
   [b (bonkers a)]
   #:break (when (not (number? (hoop x b)))
 'um))
  (list x y z a b))

In practice, this allowed me to rewrite a lot of functions that were highly 
nested into a single let++ form.

The other feature of let++ is that it also supports let-values. (Having to 
nest "let, then let-values, then let again" was another reason my code 
would get too indented for my taste.)

Implementation: https://github.com/default-kramer/fission-flare/blob/
master/src/util/let%2B%2B.rkt
Example: https://github.com/default-kramer/fission-flare/blob/
d6e71353dbd53e0d00d71e0e7911caca6455c4db/src/core/state.rkt#L266


On Sunday, October 3, 2021 at 9:45:28 AM UTC-5 laurent...@gmail.com wrote:

> Oh well, since everyone is at it, here's my version that no-one asked for. 
> It's similar to parendown, but uses a more standard (but also specific) 
> macro `cond/else` from 
> https://github.com/Metaxal/bazaar/blob/master/cond-else.rkt :
>
> (*cond/else*
>  [(*not* (foo? x)) #f]
>  #:else
>
>  (*define* y (bar x))
>  (*define* z (jazz x y))
>  #:cond
>  [(*not* (loopy? z)) #f]
>  #:else
>  (*define* a (yowza z))
>  #:cond
>  [(*not* (string? a))
>   (error 'ugh)]
>  #:else
>  (*define* b (bonkers a))
>  #:cond
>  [(number? (hoop x b))
>   (*define* ...)]
>  #:else
>  (*error* 'um))
>
> I find the different coloration of the keywords helpful to parse the code 
> too.
>
> Now waiting for more original solutions to this problem :-)
>
>
> On Sat, Oct 2, 2021 at 9:09 PM jackh...@gmail.com  
> wrote:
>
>> Here's my solution:
>>
>> (define/guard (f x)
>>   (guard (foo? x) else
>> #false)
>>   (define y (bar x))
>>   (define z (jazz x y))
>>   (guard (loopy? z) else
>> #false)
>>   (define a (yowza z))
>>   (guard (string? a) else
>> (error 'ugh))
>>   (define b (bonkers a))
>>   (guard (number? (hoop x b)) else
>> (error 'um))
>>   (define ...))
>>
>> It uses a `guard` macro I wrote and talked about in this thread 
>> .
>> On Friday, October 1, 2021 at 12:53:25 PM UTC-7 hen...@topoi.pooq.com 
>> wrote:
>>
>>> On Fri, Oct 01, 2021 at 02:32:52PM -0400, David Storrs wrote: 
>>> > On Fri, Oct 1, 2021 at 11:58 AM Hendrik Boom  
>>> wrote: 
>>> > 
>>> > > On Fri, Oct 01, 2021 at 02:22:14PM +, Jesse Alama wrote: 
>>> > > > Hello, 
>>> > > > 
>>> > > > Have you ever wished you could do a C-style return in the middle 
>>> > > > of a block of Racket code? When you're in the heat of things with 
>>> > > > a complicated problem where input values need a fair amount of 
>>> > > > multi-stage extraction and validation, using cond quickly pulls 
>>> > > > code to the right. My procedure is: 
>>> > > > 
>>> > > > * cond/case. In each branch: 
>>> > > > * Define some new values safe in the knowledge of where you are 
>>> > > > (extract) and perhaps check them, if necessasry (validate) 
>>> > > > * Make sure you have an else branch. 
>>> > > > * return to 1 and repeat as many times as necessary. 
>>> > > > 
>>> > > > The result: 
>>> > > > 
>>> > > > (cond [(foo? x) 
>>> > > > (define y (bar x)) 
>>> > > > (define z (jazz x y)) 
>>> > > > (cond [(loopy? z) 
>>> > > > (define a (yowza z)) 
>>> > > > (cond [(string? a) 
>>> > > > (define b (bonkers a)) 
>>> > > > (cond [(number? (hoop x b)) 
>>> > > > (define ...)] 
>>> > > > [else 
>>> > > > (error 'um)])] 
>>> > > > [else 
>>> > > > (error 'ugh)])] 
>>> > > > [else #f])] 
>>> > > > [else #f]) 
>>> > > 
>>> > > 
>>> > I'm presuming that this code should either return #f, return a 
>>> calculated 
>>> > value, or raise an exception. If so, here's a version that runs in 
>>> plain 
>>> > racket that I find pretty easy to read. It has the advantage that the 
>>> > 'return #f' parts aren't way far away from what causes them. 
>>> > 
>>> > (with-handlers ([false? identity] ; return #f 
>>> > [any/c raise]) ; re-raise everything else 
>>> > (let* ([x (if (foo? x) 
>>> > x 
>>> > (raise #f))] 
>>> > [z (jazz x (bar x))] 
>>> > [a (if (loopy? z) 
>>> > (yowza z) 
>>> > (raise #f))] 
>>> > [b (if (string? a) 
>>> > (bonkers a) 
>>> > (error 'ugh))]) 
>>> > (if (number? (hoop x b)) 
>>> > 'all-good 
>>> > (error 'um 
>>>
>>> Yes. But different semantics if bar, yowza, and bonkers have side 
>>> effects. 
>>> If they don't, they're quite equivalent. 
>>>
>>> -- hendrik 
>>>
>>> > 
>>> > If instead you want to return the exn that comes from error instead of 
>>> > re-raising it then you can do that by removing the false? clause from 

[racket-users] Announcing Fission Flare, a falling block video game

2021-09-23 Thread Ryan Kramer
I've just released v0.1 of a falling block video game: 
https://github.com/default-kramer/fission-flare It draws a lot of 
inspiration from Dr Mario but I don't like to advertise that since my game 
has plenty of unique ideas. And although the patent on Dr Mario has 
expired, I'm not a lawyer and I don't want to invite trouble.

The game is 100% Racket, most of it Typed. The graphics are all done using 
pict. Perhaps I'll start a blog and write up some of the more interesting 
things I learned, but not today. 

Warning - it can be pretty addicting! Well over 90% of my "development" 
time was just me playing the game.

-- 
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/d4c9e068-a44f-41bd-854a-ee7c286b98fbn%40googlegroups.com.


Re: [racket-users] Is there an easy way to disable a GUI element?

2021-09-03 Thread Ryan Kramer
Perfect, thanks. I thought I explored all the relevant interfaces but I 
must have overlooked window<%>.

On Friday, September 3, 2021 at 1:00:37 AM UTC-5 gneuner2 wrote:

>
>
> On 9/2/2021 5:39 PM, Ryan Kramer wrote:
>
> I see that button% has an `enabled` field, but I'm not seeing anything for 
> slider%, text-field%, and choice%. If I want to disable these elements, do 
> I have to roll my own enable/disable logic? Also, is there a way to change 
> a button's `enabled` status after it is created? Thanks.
>
>
> All the controls respond to window<%> messages: e.g., (send *mybutton*  
> enable #t)
> https://docs.racket-lang.org/gui/window___.html
>
> Whenever possible, you should try to use object messaging / method calls 
> rather than directly messing with fields in the objects (even if the fields 
> are public).
> https://docs.racket-lang.org/reference/ivaraccess.html
>
>
>
>

-- 
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/35e042ba-c3d4-4d77-807f-6f4ee4965ba0n%40googlegroups.com.


[racket-users] Is there an easy way to disable a GUI element?

2021-09-02 Thread Ryan Kramer
I see that button% has an `enabled` field, but I'm not seeing anything for 
slider%, text-field%, and choice%. If I want to disable these elements, do 
I have to roll my own enable/disable logic? Also, is there a way to change 
a button's `enabled` status after it is created? Thanks.

-- 
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/82ede02f-577a-4f93-bb70-ef28f65c6f84n%40googlegroups.com.


Re: [racket-users] Re: Is this "inside out" macro technique common?

2021-08-17 Thread Ryan Kramer
Thank you! `splice` is indeed the essential primitive here, so it's nice to 
see it extracted and named properly.

The difference between eval-syntax and syntax-local-eval is good to know 
also. I think there is a bug in the documentation (or maybe in Racket) 
because when I try `(syntax-local-eval #'(begin e ...) #f)` I get 

..\..\Program Files\Racket-8.0.0.11\collects\racket\syntax.rkt:234:0: 
syntax-local-bind-syntaxes: contract violation
  expected: (or/c internal-definition-context? (listof 
internal-definition-context?))
  given: #f

No big deal, the empty list works, but the documentation says #f should be 
accepted too.

> Without the whole picture of the problem you're trying to solve, it's 
hard to evaluate how splices compare to those alternatives, though. 

When choosing how to implement a macro, my first thought is "can I make 
define-syntax-rule work?" And if the answer is yes, then I use it -- I 
won't need the documentation and probably won't make a mistake. On the 
other end of the spectrum is syntax-parse which is way more powerful, but I 
will certainly need the documentation and mistakes are more likely. When I 
stumbled upon my splice variant, it seemed to be only slightly more complex 
than define-syntax-rule while enabling a much wider range of usage 
patterns. Or so I thought at the time, but now I'm less sure. I'll have to 
see how it plays out.
On Monday, August 16, 2021 at 12:22:02 PM UTC-5 Michael Ballantyne wrote:

> The essential primitive here seems to me to be:
>
> (define-syntax (splice stx)
>   (syntax-case stx ()
> [(_ e ...)
>  (eval-syntax #'(begin e ...))]))
>
> With with-quasisyntax being:
>
> (define-syntax-rule
>   (with-quasisyntax ([a b] ...) template)
>   (splice (with-syntax ([a b] ...) (quasisyntax template
>
> Forms like splice appear in the metaprogramming systems of other 
> programming languages such as Template Haskell (
> https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/exts/template_haskell.html)
>  
> and Converge (https://convergepl.org/) but I haven't seen the pattern 
> widely used in Racket.
>
> I think this comes from a different philosophy. Systems like Template 
> Haskell think of metaprogramming as a way to automatically generate code. 
> From "Template Meta-programming for Haskell" (
> https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/meta-haskell.pdf
> ):
>   The purpose of the extension is to allow programmers to compute some 
> parts of their program
>rather than write them, and to do so seamlessly and conveniently
> In Racket we generally think instead about creating either language 
> extensions or new sub-languages. Code generation happens to be the way we 
> implement the extensions or sub-languages, but the focus is on the new 
> syntax we are defining. If we find repeated patterns of code we start by 
> thinking about the language or language feature we wish was there, and then 
> implement that. Within those implementations we use abstractions like 
> syntax-parse, syntax classes, and syntax-parse template metafunctions.
>
> Without the whole picture of the problem you're trying to solve, it's hard 
> to evaluate how splices compare to those alternatives, though.
>
> That said, here are two alternative implementations of splice:
>
> (define-syntax (splice2 stx)
>   (syntax-case stx ()
> [(_ e ...)
>  #`(let-syntax ([m (lambda (stx) e ...)]) (m))]))
>
> (require (for-syntax racket/syntax))
> (define-syntax (splice3 stx)
>   (syntax-case stx ()
> [(_ e ...)
>  (syntax-local-eval #'(begin e ...))]))
>
> Whereas eval-syntax only allows access to the module-level expander 
> environment, these can access the local environment. That might matter if 
> you need to use syntax-local-value to access information from syntax 
> bindings. The following works with splice2 and splice3, but not splice:
>
> (let-syntax ([x 'foo])
>   (splice3
>(displayln (syntax-local-value #'x))
>#'(void)))
>
> I recommend using splice3 because it avoids the intermediate expansion 
> step of the let-syntax .
> On Friday, August 13, 2021 at 9:19:51 PM UTC-4 Ryan Kramer wrote:
>
>> The name `with-quasisyntax` is not very good, because it is not simply a 
>> quasi version of `with-syntax`. The most interesting part is that it calls 
>> `eval-syntax` up front. The result feels like a "universal macro" -- it can 
>> be used to implement both foo->assoc and assoc->foo which look like they 
>> would traditionally need separate macros (or one large macro that handles 
>> both).
>>
>> I am noticing that this use of `eval-syntax` can cause error messages to 
>> be less good, but I still think it's OK for "

Re: [racket-users] Re: Is this "inside out" macro technique common?

2021-08-13 Thread Ryan Kramer
The name `with-quasisyntax` is not very good, because it is not simply a
quasi version of `with-syntax`. The most interesting part is that it calls
`eval-syntax` up front. The result feels like a "universal macro" -- it can
be used to implement both foo->assoc and assoc->foo which look like they
would traditionally need separate macros (or one large macro that handles
both).

I am noticing that this use of `eval-syntax` can cause error messages to be
less good, but I still think it's OK for "private" code.

On Fri, Aug 13, 2021 at 2:45 PM D. Ben Knoble  wrote:

> Ah, I'm now seeing that with-quasi implicitly #`s the body; I believe with
> syntax-parse, #:with, and #' + template vars + #` when needed you might be
> ok.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Racket Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/racket-users/61cQImHJfZI/unsubscribe.
> To unsubscribe from this group and all its topics, 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/2ede4034-80ec-49ad-9782-8883f8d47085n%40googlegroups.com
> 
> .
>

-- 
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/CAJYF1yu4FsOowfbfV%3DP%3D_fZHzJCAtgK8SNBb4nSNQmF1A%3DfvxA%40mail.gmail.com.


[racket-users] Is this "inside out" macro technique common?

2021-08-12 Thread Ryan Kramer
A shortcut to answering my question would be to tell me that 
`with-quasisyntax` in the following paste already exists: 
http://pasterack.org/pastes/48885

== Context ==
In my current project, I have a macro that is doing a lot of work. (It is 
Typed Racket, but my question applies equally to untyped Racket.) This 
macro takes in a struct id, field ids, and field types. It generates the 
struct definition along with some serialization and deserialization 
machinery.

Then I encounter a new requirement: I want to be able to convert at least 
one these structs to an association list. (This differs from 
serialization.) The most obvious way to me is to add that functionality to 
my already-large macro. But it is getting difficult to maintain, and it 
feels like there should be a better way.

== Solution? ==
I came up with the approach in this paste, and it seems to work great: 
http://pasterack.org/pastes/48885 (Of course, if I had more structs I would 
make certain things reusable, it just demonstrates the concept.)

Custom syntax transformers also came to mind, but they seem a bit 
cumbersome for something that I don't intend to expose to external code.

I'm kind of surprised that it took me so long to discover this approach. 
Unless there is some nasty footgun that I haven't hit yet, I expect I'll be 
using this approach a lot in the future. But if it feels so right, then why 
haven't I seen it until now?

-- 
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/fb025d15-f0f6-4955-957e-b5576fca3f96n%40googlegroups.com.


[racket-users] Re: get-scaled-client-size and high-DPI on Windows

2021-07-24 Thread Ryan Kramer
Wow, how did I write that much and not notice `get-client-size`, which is 
exactly what I want? The documentation is fine, apparently I just can't 
read today!

On Saturday, July 24, 2021 at 10:55:58 AM UTC-5 Ryan Kramer wrote:

> The following program looks "correct" when my Windows display scaling is 
> set to 100%, and looks "wrong" when set to anything higher than 100%. By 
> "correct" I mean that the 4 squares meet in the center of the canvas, 
> stretched to the maximum size possible that the canvas width and height 
> will allow.
>
> What is interesting is that I can make the program look correct by 
> immediately scaling the values returned from `get-scaled-client-size`. For 
> example, if my display is set to 150%, I can make the program look correct 
> by immediately multiplying the returned width and height by 2/3, because 
> 100% is 2/3 of 150%. But right now I have to hard-code the 2/3 factor. Is 
> there a way to get that 2/3 factor programmatically in Racket? Or (even 
> better), is there something else I should be calling instead of 
> `get-scaled-client-size` that would return the dimensions I want?
>
> This is Racket CS 8.0.0.11 on Windows. Let me know if you want 
> screenshots. Thanks in advance.
>
>
> #lang racket/gui
>
> (require pict)
>
> (define frame
>   (new frame%
>[label "Scale Test"]))
>
> (define (paint canvas dc)
>   (define-values (w h) (send canvas get-scaled-client-size))
>   (define-values (size x-offset y-offset)
> (if (> w h)
> (values h (/ (- w h) 2) 0)
> (values w 0 (/ (- h w) 2
>   (println (list w h size x-offset y-offset))
>   (for ([x (list x-offset (+ x-offset (/ size 2)))]
> #:when #t
> [y (list y-offset (+ y-offset (/ size 2)))])
> (send dc draw-rectangle x y (/ size 2) (/ size 2
>
> (define canvas
>   (new canvas%
>[parent frame]
>[paint-callback paint]))
>
> (send frame show #t)
>
>

-- 
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/31a9adf4-c257-4871-88a5-6a01e9857f43n%40googlegroups.com.


[racket-users] get-scaled-client-size and high-DPI on Windows

2021-07-24 Thread Ryan Kramer
The following program looks "correct" when my Windows display scaling is 
set to 100%, and looks "wrong" when set to anything higher than 100%. By 
"correct" I mean that the 4 squares meet in the center of the canvas, 
stretched to the maximum size possible that the canvas width and height 
will allow.

What is interesting is that I can make the program look correct by 
immediately scaling the values returned from `get-scaled-client-size`. For 
example, if my display is set to 150%, I can make the program look correct 
by immediately multiplying the returned width and height by 2/3, because 
100% is 2/3 of 150%. But right now I have to hard-code the 2/3 factor. Is 
there a way to get that 2/3 factor programmatically in Racket? Or (even 
better), is there something else I should be calling instead of 
`get-scaled-client-size` that would return the dimensions I want?

This is Racket CS 8.0.0.11 on Windows. Let me know if you want screenshots. 
Thanks in advance.


#lang racket/gui

(require pict)

(define frame
  (new frame%
   [label "Scale Test"]))

(define (paint canvas dc)
  (define-values (w h) (send canvas get-scaled-client-size))
  (define-values (size x-offset y-offset)
(if (> w h)
(values h (/ (- w h) 2) 0)
(values w 0 (/ (- h w) 2
  (println (list w h size x-offset y-offset))
  (for ([x (list x-offset (+ x-offset (/ size 2)))]
#:when #t
[y (list y-offset (+ y-offset (/ size 2)))])
(send dc draw-rectangle x y (/ size 2) (/ size 2

(define canvas
  (new canvas%
   [parent frame]
   [paint-callback paint]))

(send frame show #t)

-- 
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/ef44708d-8938-4a57-b2d7-576b02bdd8f3n%40googlegroups.com.


Re: [racket-users] Could Racket be used as a "frontend" for a non-Racket language?

2021-06-20 Thread Ryan Kramer
Thanks everyone for the good reading. I haven't fully digested it all yet, 
but Alexis' blog is extremely relevant and shows that this approach is not 
as close to a "free lunch" as I thought it might be.

On Monday, June 7, 2021 at 10:07:56 AM UTC-5 Stephen Foster wrote:

> This is one of the main ways I use Racket -- but as a front-end for 
> JavaScript, not C#.
>
> On Sunday, June 6, 2021 at 9:47:38 PM UTC-7 Philip McGrath wrote:
>
>> I haven't done much with this personally, but a few pointers in Racket:
>>
>>- Urlang uses Racket's macro system as a front-end for JavaScript (in 
>>the way you discuss with C#, not compiling Racket to JavaScript): 
>>https://github.com/soegaard/urlang
>>- Alexis King's Hackett is an experimental Haskell-like `#lang`: 
>>https://lexi-lambda.github.io/hackett/ While it currently only runs 
>>on the Racket runtime system, Alexis' blog post, "Reimplementing 
>> Hackett’s 
>>type language: expanding to custom core forms in Racket", discusses the 
>>possibility of an alternate backend targeting GHC and goes into extremely 
>>useful detail about implementation techniques that can help: 
>>
>> https://lexi-lambda.github.io/blog/2018/04/15/reimplementing-hackett-s-type-language-expanding-to-custom-core-forms-in-racket/
>>- The recent paper "Macros for Domain-Specific Languages" (
>>https://dl.acm.org/doi/pdf/10.1145/3428297) presents a high-level API 
>>for doing many of the things the aforementioned blog post implements by 
>>hand. (Alexis is a co-author on the paper.)  The `ee-lib` library 
>> provides 
>>the API discussed in the paper: 
>>https://docs.racket-lang.org/ee-lib/index.html (I have done the 
>>by-hand approach to custom core forms, and I'm excited to try the new 
>>library.)
>>
>> -Philip
>>
>>
>> On Sun, Jun 6, 2021 at 11:35 PM Robert Calco  wrote:
>>
>>> Check out IronScheme <https://github.com/IronScheme/IronScheme>... it 
>>> may be just what you're looking for.
>>>
>>> - Bob
>>>
>>> On Sun, Jun 6, 2021 at 10:02 PM Ryan Kramer  
>>> wrote:
>>>
>>>> I have no plans to work on this, but I am curious if this has been 
>>>> discussed or attempted...
>>>>
>>>> Motivation: My job has been C# for many years and while C# is very 
>>>> appropriate for most of the problems I encounter at work, sometimes a 
>>>> problem comes along that makes me want more power. In those situations, I 
>>>> think the language I want is "C# except now it's S-expressions and it has 
>>>> Racket's macro system."
>>>>
>>>> And then I wonder if an alternate version of C# could be implemented 
>>>> this way:
>>>> 1) Create a new grammar for what a fully-expanded C# AST is. This will 
>>>> be in terms of Racket syntax objects, just like Racket's definition of a 
>>>> Fully Expanded Program.
>>>> 2) Write a compiler that generates CIL (the bytecode) given a 
>>>> fully-expanded C# AST.
>>>> 3) Use Racket's #lang mechanism and macro system to implement the 
>>>> surface language.
>>>>
>>>> Now this new C# could borrow a lot of power from Racket, right? For 
>>>> example, I could make all of Racket available during expansion! Even if I 
>>>> don't want C#-the-surface-language to have macros at all, why shouldn't I 
>>>> keep the Racket-powered backdoor open? As long as you generate a valid C# 
>>>> AST, I should be able to compile it for you.
>>>>
>>>> The #lang mechanism and Scribble are two other nice things that could 
>>>> probably be adapted into the new C# if desired.
>>>>
>>>> I can understand why Microsoft wouldn't do this. But I've seen enough 
>>>> hobby languages, and I'm surprised that none of them do this. Reusing a 
>>>> backend (like dotnet or the JVM) is common, reusing a "frontend" is 
>>>> something I've never seen. Is Racket's macro system too specific to 
>>>> Racket's definition of a fully-expanded program? (The little bit I've done 
>>>> with local-expand and stop-ids makes me think it would work fine.) Is 
>>>> there 
>>>> something else that would make this approach more trouble than it's worth?
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Racket 

[racket-users] Could Racket be used as a "frontend" for a non-Racket language?

2021-06-06 Thread Ryan Kramer
I have no plans to work on this, but I am curious if this has been 
discussed or attempted...

Motivation: My job has been C# for many years and while C# is very 
appropriate for most of the problems I encounter at work, sometimes a 
problem comes along that makes me want more power. In those situations, I 
think the language I want is "C# except now it's S-expressions and it has 
Racket's macro system."

And then I wonder if an alternate version of C# could be implemented this 
way:
1) Create a new grammar for what a fully-expanded C# AST is. This will be 
in terms of Racket syntax objects, just like Racket's definition of a Fully 
Expanded Program.
2) Write a compiler that generates CIL (the bytecode) given a 
fully-expanded C# AST.
3) Use Racket's #lang mechanism and macro system to implement the surface 
language.

Now this new C# could borrow a lot of power from Racket, right? For 
example, I could make all of Racket available during expansion! Even if I 
don't want C#-the-surface-language to have macros at all, why shouldn't I 
keep the Racket-powered backdoor open? As long as you generate a valid C# 
AST, I should be able to compile it for you.

The #lang mechanism and Scribble are two other nice things that could 
probably be adapted into the new C# if desired.

I can understand why Microsoft wouldn't do this. But I've seen enough hobby 
languages, and I'm surprised that none of them do this. Reusing a backend 
(like dotnet or the JVM) is common, reusing a "frontend" is something I've 
never seen. Is Racket's macro system too specific to Racket's definition of 
a fully-expanded program? (The little bit I've done with local-expand and 
stop-ids makes me think it would work fine.) Is there something else that 
would make this approach more trouble than it's worth?

-- 
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/cc7c1792-ba59-400f-856a-3bb02a6096fbn%40googlegroups.com.


[racket-users] Re: scribble: referencing two identifiers with the same name?

2021-05-01 Thread Ryan Kramer
Using the prefix should still link correctly. When I run the following 
program, it links to section 3.9 of the Racket Reference where `let` is 
defined. Does your link go somewhere else?

```
#lang scribble/manual

@(require (prefix-in racket: (for-label racket/base)))

@defform[(let ([id expr] ...) body ...)]{
 The same behavior as @(racket racket:let).
}
```

If you really want to remove the prefix, I don't know of any easier way 
than what you've already found. However, as a reader of the documentation I 
don't mind seeing the prefix. In fact, I think I would prefer to see it 
because then I can make a very good guess that it is talking about Racket's 
`let` without hovering or clicking the link.

On Friday, April 30, 2021 at 11:01:20 AM UTC-5 sa...@ccs.neu.edu wrote:

> Is there an easy way to refer to two different identifiers with the same 
> name when writing scribble documentation?
>
> For example, let's say I have a language with a `let` binding that 
> operates more or less the same as racket's `let`. I wanted to write 
> something like this:
>
> ```
> @(require (prefix-in racket: (for-label racket/base)))
>
> @defform[(let ([id expr] ...) body ...){
> The same behavior as @racket[racket:let].
> }
> ```
>
> This doesn't seem to work; the reference to racket's `let` ends up 
> including the `racket:` prefix and doesn't seem to resolve to the 
> appropriate link.
>
> I looked at Typed Racket's docs to see how it manages this problem, and 
> found the following pattern:
>
> ```
> @(module def-racket racket/base
>(require (for-label racket/base) scribble/manual)
>(define let-id (racket let))
>(provide let-id))
>
> @(require 'def-racket)
>
> @defform[(let ([id expr] ...) body ...){
> The same behavior as @|let-id|.
> }
> ```
>
> source: 
> https://github.com/racket/typed-racket/blob/master/typed-racket-doc/typed-racket/scribblings/reference/special-forms.scrbl
>
> So my question is, is there an easier/more direct way to accomplish this 
> (perhaps since these typed racket docs were written)?
>
> It also looks like this pattern could be captured by a macro---has someone 
> written that already?
>
> Thanks,
> Sam Caldwell
>

-- 
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/334007f4-0632-4814-8d22-9ad56f650d21n%40googlegroups.com.


[racket-users] Re: How do I debug this performance problem?

2021-04-05 Thread Ryan Kramer
It turns out that a chaperone introduced at the typed-untyped boundary was 
causing a certain important function to run at least 20x slower. I've added 
prop:authentic to all my structs and am updating the code so that Typed 
Racket no longer tries to create chaperones.

I've noticed that Typed Racket adds seemingly unnecessary chaperones when 
the Any type is involved, but maybe they are necessary for some reason? The 
following code tries to create a chaperone that I don't think is necessary.

#lang racket

(module m typed/racket
  (provide f)
  (: f (-> Any Any))
  (define (f x) x))
(require 'm)

(struct s (a b) #:transparent #:authentic)
(f (s 1 2))

Is there a reason for the chaperone? Should I report this and similar 
situations as Github issues?
On Sunday, April 4, 2021 at 7:11:02 PM UTC-5 Ryan Kramer wrote:

> I either forgot or never learned that the profile functionality is 
> available programmatically. And `create-sampler` can track a single thread 
> which is exactly what I want (the UI thread). The profile results are 
> surprising, but at least I have some ideas to try now.
>
> On Sunday, April 4, 2021 at 12:55:32 PM UTC-5 Ryan Kramer wrote:
>
>> I am working on prototyping a video game. I have a function `state->pict` 
>> that takes a game state and creates a pict to be drawn on a canvas. When I 
>> `time` this function I get nice low numbers like "cpu time: 0 real time: 2 
>> gc time: 0"
>>
>> The problem occurs when I am running a networked multiplayer game. The 
>> size and complexity of the state remains the same (a "state" represents 
>> only one player's state). But the mere presence of other threads doing 
>> network IO somehow slows down `state->pict` which is strange because it is 
>> a pure function. I get timing results like "cpu time: 78 real time: 71 gc 
>> time: 0". If I stop the network activity mid-game, after a few seconds it 
>> will start running quickly again.
>>
>> This makes me think that other threads are interrupting state->pict and 
>> that this interruption is being captured by `time`. Is that plausible?
>>
>> Do I need to use a separate place for the network request/response queue? 
>> Right now, I am just using `thread` like this:
>>
>> ; (-> request (evtof response))
>> (define/public (sendrq rq)
>>   (let ([result (box #f)])
>> (wrap-evt (thread (lambda () (set-box! result (send/recv rq
>>   (lambda args (unbox result)
>>
>> There is one other area that concerns me: I am using `read` on the 
>> input-port returned by `tcp-connect`. I was hoping that `read` would yield 
>> while it is waiting for the datum to arrive on the port, but maybe it spins 
>> instead which would explain the elevated CPU usage.
>>
>> I tried `raco profile my-game.rkt` but that only profiles the time it 
>> takes to show the initial frame. Is there some other technique I can use to 
>> profile the game while it is running?
>>
>> Thanks in advance for any suggestions.
>>
>

-- 
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/c4a87899-25c1-4095-b3d7-309007386ffen%40googlegroups.com.


[racket-users] Re: How do I debug this performance problem?

2021-04-04 Thread Ryan Kramer
I either forgot or never learned that the profile functionality is 
available programmatically. And `create-sampler` can track a single thread 
which is exactly what I want (the UI thread). The profile results are 
surprising, but at least I have some ideas to try now.

On Sunday, April 4, 2021 at 12:55:32 PM UTC-5 Ryan Kramer wrote:

> I am working on prototyping a video game. I have a function `state->pict` 
> that takes a game state and creates a pict to be drawn on a canvas. When I 
> `time` this function I get nice low numbers like "cpu time: 0 real time: 2 
> gc time: 0"
>
> The problem occurs when I am running a networked multiplayer game. The 
> size and complexity of the state remains the same (a "state" represents 
> only one player's state). But the mere presence of other threads doing 
> network IO somehow slows down `state->pict` which is strange because it is 
> a pure function. I get timing results like "cpu time: 78 real time: 71 gc 
> time: 0". If I stop the network activity mid-game, after a few seconds it 
> will start running quickly again.
>
> This makes me think that other threads are interrupting state->pict and 
> that this interruption is being captured by `time`. Is that plausible?
>
> Do I need to use a separate place for the network request/response queue? 
> Right now, I am just using `thread` like this:
>
> ; (-> request (evtof response))
> (define/public (sendrq rq)
>   (let ([result (box #f)])
> (wrap-evt (thread (lambda () (set-box! result (send/recv rq
>   (lambda args (unbox result)
>
> There is one other area that concerns me: I am using `read` on the 
> input-port returned by `tcp-connect`. I was hoping that `read` would yield 
> while it is waiting for the datum to arrive on the port, but maybe it spins 
> instead which would explain the elevated CPU usage.
>
> I tried `raco profile my-game.rkt` but that only profiles the time it 
> takes to show the initial frame. Is there some other technique I can use to 
> profile the game while it is running?
>
> Thanks in advance for any suggestions.
>

-- 
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/58d34d1e-d2d2-445b-a1d6-40fb814e7e55n%40googlegroups.com.


[racket-users] How do I debug this performance problem?

2021-04-04 Thread Ryan Kramer
I am working on prototyping a video game. I have a function `state->pict` 
that takes a game state and creates a pict to be drawn on a canvas. When I 
`time` this function I get nice low numbers like "cpu time: 0 real time: 2 
gc time: 0"

The problem occurs when I am running a networked multiplayer game. The size 
and complexity of the state remains the same (a "state" represents only one 
player's state). But the mere presence of other threads doing network IO 
somehow slows down `state->pict` which is strange because it is a pure 
function. I get timing results like "cpu time: 78 real time: 71 gc time: 
0". If I stop the network activity mid-game, after a few seconds it will 
start running quickly again.

This makes me think that other threads are interrupting state->pict and 
that this interruption is being captured by `time`. Is that plausible?

Do I need to use a separate place for the network request/response queue? 
Right now, I am just using `thread` like this:

; (-> request (evtof response))
(define/public (sendrq rq)
  (let ([result (box #f)])
(wrap-evt (thread (lambda () (set-box! result (send/recv rq
  (lambda args (unbox result)

There is one other area that concerns me: I am using `read` on the 
input-port returned by `tcp-connect`. I was hoping that `read` would yield 
while it is waiting for the datum to arrive on the port, but maybe it spins 
instead which would explain the elevated CPU usage.

I tried `raco profile my-game.rkt` but that only profiles the time it takes 
to show the initial frame. Is there some other technique I can use to 
profile the game while it is running?

Thanks in advance for any suggestions.

-- 
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/87d2b914-2b9e-4d27-9ea9-739df42adb36n%40googlegroups.com.


Re: [racket-users] Is it safe to `read` untrusted input?

2021-02-28 Thread Ryan Kramer
Thanks everyone. I feel fine to use `read` for this use case now. I 
overlooked `call-with-default-reading-parameterization` which specifically 
mentions "reading from untrusted sources" so that is very reassuring.

On Sunday, February 28, 2021 at 3:36:29 PM UTC-6 John K wrote:

>
>
> On Feb 28, 2021, at 2:50 PM, Ryan Kramer  wrote:
>
>
> […]
>
>
> I could use JSON or XML, but that just seems silly when you have a Racket 
> client talking to a Racket server.
>
> Are my concerns founded? Are there any existing solutions? Thanks for any 
> advice.
>
>
> I don’t think this necessarily answers your question, at least not 
> directly, but receiving code from a remote client is certainly a potential 
> security risk. 
>
> Fortunately, Racket is well-adapted to writing (and parsing) a language 
> (DSL) inside of the language. 
>
> Personally I’m a fan of object capability mechanisms. In Scheme and 
> Racket, some interesting places to start might be 
>
> * Jonathan Rees’ Scheme-based “security kernel” paper: 
> http://mumble.net/~jar/pubs/secureos/secureos.html 
> * Marketplace by Tony Garnock-Jones: http://tonyg.github.io/marketplace/
>
> Christoper Lemmer Webber (may be on this list even?) is working on 
> something called Spritely Goblins, an implementation, in Racket, of the 
> CapTP/VatTP protocols that were invented by Mark Miller and others in the E 
> language (http://www.erights.org/elib/capability/ode/ode-capabilities.html) 
> and now being used in Javascript/SES.
>
> * https://docs.racket-lang.org/goblins/index.html
>
> And finally, for serializing object (capabilities), the other piece of 
> relevant interesting work is CapnProto by Kenton Varda: 
> https://capnproto.org/
>
> Have fun :)
>
> - johnk 
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/a2580765-3cc2-482b-8d20-f62dc1e1dc91n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/racket-users/a2580765-3cc2-482b-8d20-f62dc1e1dc91n%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>
>

-- 
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/cf2a07a1-adff-4a4b-9856-679c98c797cfn%40googlegroups.com.


[racket-users] Is it safe to `read` untrusted input?

2021-02-28 Thread Ryan Kramer
I want to send some Racket structs across a network. I know that I can use 
prefab structs, serializable-structs, or even `eval` with a carefully 
curated namespace. I was trying to think of security problems with the eval 
approach and now I've become more afraid of `read` than I am of eval. And 
read seems necessary for all 3 approaches.

The first concern I thought of was cyclic data. My code assumes there are 
no cycles; if an attacker can get me to process cyclic data my server will 
probably loop forever or crash. This can be solved by setting 
`read-accept-graph` to #f... I think. Right? (I guess another solution is 
"you need to validate the input" which is fair, but it's easy to forget or 
make a mistake.)

This caused me to notice other `read-accept-***` parameters that looked 
scary (-lang, -reader, -compiled). I don't know if there is an attack 
vector here, but I felt safer turning them off also.

Now I'm thinking that even if I can get it working safely today, Racket 
would be well within its rights to make enhancements to the reader in the 
future. So someday there might be new parameters that I would want to turn 
off to preserve my definition of "safe", and I have to remember this when I 
upgrade.

All this makes me think that `read` is not quite the right tool for the 
job. But it's close. If there were a version of read that accepts nothing 
by default and requires the caller to opt-in to everything they want, that 
would probably be perfect.

I could use JSON or XML, but that just seems silly when you have a Racket 
client talking to a Racket server.

Are my concerns founded? Are there any existing solutions? Thanks for any 
advice.

-- 
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/a2580765-3cc2-482b-8d20-f62dc1e1dc91n%40googlegroups.com.


[racket-users] Re: [scribble] code:hilite for binders

2020-08-23 Thread Ryan Kramer
You might also be able to use make-element-id-transformer 

 
like this

#lang scribble/manual

@(begin
   (require scribble/racket
scribble/eval
(for-syntax racket/base))

   (define-syntax FOO (make-element-id-transformer
   (lambda arglist #'(racket (code:hilite foo)
   (interaction
(let ([FOO 41])
  (add1 FOO


On Saturday, August 22, 2020 at 5:15:17 PM UTC-5, Éric Tanter wrote:
>
> Hi, 
>
> From the doc: `(code:hilite datum)` typesets like `datum`, but with a 
> background highlight. 
> However, it does not work to highlight a binder, eg: `(letrec 
> ([(code:hilite self) …]) …)` 
> Is there another way to highlight a binder? 
>
> Thanks, 
>
> — Éric 
>
>
>
>
>

-- 
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/a4bb9d79-5f2a-4317-82f9-0d4de630af10o%40googlegroups.com.


[racket-users] Announce: Plisqin 0.4

2020-08-09 Thread Ryan Kramer
I've just finished some final cleanup and testing of Plisqin and am ready 
to call it "stable, but incomplete".

https://docs.racket-lang.org/plisqin/index.html

Plisqin's semantics are similar to SQL but there are some key differences. 
Perhaps the most significant is that joins are values, not language 
constructs.

Plisqin is incomplete in that it still lacks first-class 
Insert/Update/Delete support. However, it is easy to mix in arbitrary SQL 
pretty much anywhere you want, so this might not be a problem depending on 
your use case.

With this release I will be taking a break from any major work on Plisqin. 
Bugfixes and small enhancements should be no problem though.

If you decide to try Plisqin from source, be aware that a few tests will 
fail on Racket CS due to differences in the Printer. As long as your code 
does not depend on any printable representations it will be fine.

A big "Thank You!" to everyone who has made the Racket ecosystem so great, 
and special thanks to everyone who helped me with my questions.

- Ryan Kramer

-- 
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/24be7b61-3719-405b-9966-920fd55792aco%40googlegroups.com.


Re: [racket-users] How can I increase expansion+compilation speed?

2020-07-20 Thread Ryan Kramer
Thanks Ryan, the macro profiler is great! It quickly identified a macro 
that I was able to convert to a procedure. (I'm not sure why I made it a 
macro in the first place.) And the .zo file decreased from about 910KB to 
130KB, and the compilation speed went from 40 seconds to about 8 seconds 
(with debugging). I can probably do even better, but fixing this first big 
problem was quite a relief!

On Monday, July 20, 2020 at 8:42:57 AM UTC-5, Ryan Culpepper wrote:
>
> One thing to check is the size of the resulting bytecode file. When I 
> compiled it, I got a 911 KB .zo file. So the most likely reason is that 
> your macros are just producing a lot of code.
>
> You can run the macro profiler (eg, `raco macro-profiler aw-schema.rkt`) 
> to get a summary of what macros contribute most to the compiled code size. 
> See 
> https://docs.racket-lang.org/macro-debugger/index.html#(part._.Macro_.Profiler)
>  
> for more details. I also gave a talk about the macro profiler called "The 
> Cost of Sugar" a few years ago at RacketCon. The slides are at 
> http://www.ccs.neu.edu/home/ryanc/talks/racket18-sugar.pdf, and there 
> should be a recording online somewhere.
>
> The usual fix is to use helper functions. There are some examples in the 
> slides.
>
> Ryan
>

-- 
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/1b403370-3382-42a4-9ce1-8a168e3121cao%40googlegroups.com.


[racket-users] Re: How can I increase expansion+compilation speed?

2020-07-20 Thread Ryan Kramer
Thanks to both of you.

It does expand to a reasonably large amount of code, a small example is 
below. The processing that define-schema does shouldn't be worse than 
O(N*M) where N is the number of tables and M is the number of unique 
procedure names. Which is not linear, but also probably not large enough to 
be the main culprit. I added `(println stx-being-returned)` to 
define-schema and it gets printed relatively quickly. So probably the size 
of the generated code is the main culprit. I'll try Ryan C's tips as soon 
as I have time; they look promising.

(define-schema $$
  (table A
 #:property
 [foo (%%scalar "foo-given-A" this)])
  (table B
 #:property
 [foo (%%scalar "foo-given-B" this)]
 [bar (%%scalar "bar-given-B" this)]))

; Approximately expands to
#;(begin
(define A (make-table 'A))
(define B (make-table 'B))
(define (foo x)
  (cond
[((instanceof A) x)
 (%%scalar "foo-given-A" x)]
[((instanceof B) x)
 (%%scalar "foo-given-B" x)]
[else (error "expected instanceof A or B, got" x)]))
(define (bar x)
  (cond
[((instanceof B) x)
 (%%scalar "bar-given-B" x)]
[else (error "expected instanceof B, got" x)])))

-- 
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/9900daba-8dd8-4e46-88ef-84fdeb53f11fo%40googlegroups.com.


[racket-users] How can I increase expansion+compilation speed?

2020-07-19 Thread Ryan Kramer
Using DrRacket, the following file takes 18 seconds to compile without 
debugging, or about 40 seconds to compile with 
debugging: 
https://raw.githubusercontent.com/default-kramer/plisqin-tutorials/e844825b48137553246c64e73516d880b9068825/define-schema-answer-key/aw-schema.rkt

When I say "compile", I mean that I click "Run" in DrRacket and wait for it 
to give me REPL access. But that file just defines and provides a slew of 
functions, it doesn't really do anything at runtime.

(Using the command-line `racket that-file.rkt` takes only 7 seconds, which 
is OK. But many people, myself included, primarily use DrRacket.)

Admittedly, this is 612 dense lines of code. So it might just be a case of 
"yeah, that's about how long it takes." But it's also possible (or 
probable?) that I have some inefficient macros somewhere. Are there any 
tools/techniques I can use to help me reduce the compilation time?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/40e40eff-a0be-4850-9360-c9648cb5b8d9o%40googlegroups.com.


[racket-users] Re: Scribble: customizing table borders

2020-07-19 Thread Ryan Kramer
This isn't the most ideal way, but it might work for you:

CSS:

.LongMult td[data-underline="yes"] { border-bottom: 1px solid red; }

Code:

#lang scribble/manual

@(require scribble/core
  scribble/html-properties)

@(tabular
  #:sep @hspace[2]
  #:style (style "LongMult" null)
  #:row-properties (list (list)
 (attributes '((data-underline . "yes")))
 (list))
  (list (list @para{a1} @para{a2})
(list @para{b1} @para{b2})
(list @para{c1} @para{c2})))



On Sunday, July 19, 2020 at 2:10:03 PM UTC-5, Shriram Krishnamurthi wrote:
>
> It *appears* that in Scribble, the color of a table's borders (e.g., 
> bottom-border) is fixed: e.g.,
>
> 5
>
> generated from a program such as
>
> @tabular[#:sep @hspace[2]
>  #:row-properties '(() () bottom-border ())
> #:style (style "LongMult" null)
>
> I haven't had any luck coming up with the right CSS incantation that would 
> let me override exactly that black and not change anything else.
>
> Yes, I can tag these with a style, as above, which translates into a class 
> name. But because the black setting is most deeply nested, I can't seem to 
> change it at all. For instance,
>
> .LongMult {
> border-bottom: 1px solid red;
> }
>
> *adds* a new red bottom border for the whole table while leaving the 
> intermediate black one intact, while 
>
> .LongMult td {
> border-bottom: 1px solid red;
> }
>
> adds a red bottom border to every row *except* the one that is black 
> (since the generated code presumably overrides the outer CSS). It feels 
> like perhaps this should have been a named and modifiable class in 
> scribble.css rather than a hard-coded constant?
>
> (My central problem is I have a site that is in "dark mode", so the black 
> essentially disappears against the background. So the need to change this 
> color is a functional one, not just aesthetic.)
>
> Any ideas? Thanks!
>
> Shriram
>

-- 
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/5277d6fe-29a2-41d2-8ead-042307c7e40eo%40googlegroups.com.


[racket-users] Re: scribble: how to put a bar above text?

2020-06-16 Thread Ryan Kramer
Oh my gosh, I almost forgot about Unicode tricks! (I wish I knew more about 
Unicode). Here is a macron: ā. And it seems there's a lot more you can do: 
https://qualityandinnovation.com/2014/11/22/typing-x-bar-y-bar-p-hat-q-hat-and-all-that/

These will work just fine inside a Racket source file.

On Tuesday, June 16, 2020 at 7:41:08 AM UTC-5, jos.koot wrote:

>  
>
> Hi,
>
> Using scribble when writing a text containing Boolean expressions it would 
> be nice to write ‘not(A+B)’ as ‘A+B’ with a bar above it. An expression 
> like not(not(A)+not(B)) would need bars above the A and the B as well above 
> the whole. Is this possible? I have found no solution in the scribble docs. 
> I have looked into some HTML tutorials too, but did not find what I want. I 
> am an ignorant with respect to HTML. And even when I would know how to do 
> it in HTML, I also would need to know how to transfer the tool to scribble.
>
> Thanks, Jos
>

-- 
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/f5b741c7-e793-47ec-be30-a16d5223f5c4o%40googlegroups.com.


[racket-users] Re: scribble: how to put a bar above text?

2020-06-16 Thread Ryan Kramer
Something things in scribble have a `#:style` argument. And most things in 
scribble can be contained inside a `nested` or `elem`, to which you could 
apply your custom #:style. You can use this as a hook to a custom CSS file, 
where you could maybe use "text-decoration: overline;" if that looks good 
to you. (Although if you anticipate needing more math typesetting 
capabilities, HTML+CSS will probably fail you. Mathjax sounds good.)

Basically, if you can hand-write HTML that looks good to you, you can 
probably get Scribble to do what you want. The relevant reading, I believe, 
is "styles" and `make-css-addition`, starting here: 
https://docs.racket-lang.org/scribble/config.html

Or, if you want to see a real example, I just did one: 
https://docs.racket-lang.org/plisqin/Refactoring_Recipes.html This uses a 
custom "PGreen" CSS class. You might be able to see how it all gets wired 
up by looking at these files: 
https://github.com/default-kramer/plisqin/search?q=PGreen_q=PGreen

Hope this helps! But there no way to explain this with a little 10-line 
example, unfortunately.


On Tuesday, June 16, 2020 at 7:41:08 AM UTC-5, jos.koot wrote:
>
>  
>
> Hi,
>
> Using scribble when writing a text containing Boolean expressions it would 
> be nice to write ‘not(A+B)’ as ‘A+B’ with a bar above it. An expression 
> like not(not(A)+not(B)) would need bars above the A and the B as well above 
> the whole. Is this possible? I have found no solution in the scribble docs. 
> I have looked into some HTML tutorials too, but did not find what I want. I 
> am an ignorant with respect to HTML. And even when I would know how to do 
> it in HTML, I also would need to know how to transfer the tool to scribble.
>
> Thanks, Jos
>

-- 
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/9fa457fc-3f5a-4277-8ca8-2841d7a7b6bdo%40googlegroups.com.


Re: [racket-users] Re: local variables are hyperlinkedinscribble/manual

2020-06-13 Thread Ryan Kramer
That was actually Ryan Culpepper. Sorry for the noise, but I can't 
implicitly take credit for something that I didn't do.

By the way, thank you Ryan C for both of those techniques. I've already 
happily used `make-element-id-transformer`

On Saturday, June 13, 2020 at 4:07:06 PM UTC-5, jos.koot wrote:
>
> defaul...@gmail.com  gave me a clear and usable answer.
>
> His email follows below.
>
> Best wishes, Jos
>
>  
>
>  
>
>  
>
> From Ryan Kramer
>
> You can also use make-element-id-transformer, like this:
>
>  
>
> (define-syntax SET
>   (make-element-id-transformer
>(lambda _ #'(racketvarfont "set"
>
>  
>
> Then Scribble will automatically replace SET within rendered code with the 
> element expression above.
>
>  
>
> Another trick is to break the for-label binding by introducing a local 
> binding that shadows it. For example, if you write
>
>
> (let ([set #f])
>   (racket set))
>
>  
>
> then the occurrence of `set` within the `racket` form isn't linked to 
> `set` from racket/set. This trick relies on being able to put a let around 
> the occurrences you don't want linked but not the ones that you do want 
> linked, so it might not work in all cases.
>
>  
>
> Ryan
>
>  
>
>  
>
>  
>

-- 
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/f7162464-1d7b-4113-8883-03f022f0cf5fo%40googlegroups.com.


[racket-users] How can source-omit-files exclude a directory?

2020-05-27 Thread Ryan Kramer
I have a multi-collection package and I wanted to exclude a certain 
directory (plisqin-test) from being a package. I found the relevant 
documentation here: https://docs.racket-lang.org/pkg/strip.html.

The first thing I tried was simply adding a `~` to the end of the 
directory. This worked. Then I kept reading and found `source-omit-files` 
which sounds like a better way, but I couldn't get it to work. I tried 
adding the following to the info.rkt of the multi-collection package (and 
maybe a few more), but none of them worked:

(define source-omit-files
  '("plisqin-test"
"plisqin-test/"
"plisqin/plisqin-test"
"plisqin/plisqin-test/"))

Is it possible to exclude an entire collection using the info.rkt of a 
multi-collection package? (For reference, this is the package in question: 
https://github.com/default-kramer/plisqin/tree/d44effd731b1c6d8c924ec311da43d8755f07049)

-- 
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/fe6eac50-19c9-4501-803b-9335e4bee682%40googlegroups.com.


[racket-users] Re: local variables are hyperlinked in scribble/manual

2020-05-25 Thread Ryan Kramer
My favorite way to avoid this problem is simply to choose another name, or 
use `except-in` to avoid importing `set` for-label. But if you must use the 
name `set` and you want it linking to racket/set most of the time (but not 
this time), here is a technique I've used in the past:

#lang scribble/manual

@(require (for-label racket) scribble/eval
  (for-syntax racket
  syntax/parse))

@(define-for-syntax (replace-helper stx orig-sym new-sym)
   (let ([content (syntax-e stx)])
 (cond
   [(list? content)
(datum->syntax stx
   (map (λ (child) (replace-helper child orig-sym 
new-sym))
content)
   stx stx)]
   [(equal? orig-sym content)
(datum->syntax #f new-sym stx #f)]
   [else
stx])))

@(define-syntax (replace stx)
   (syntax-parse stx
 [(_ [orig:id new:id] body:expr)
  (replace-helper #'body (syntax-e #'orig) (syntax-e #'new))]))

@(replace
  [SET set]
  @interaction[
 (let ((SET 1)) (add1 SET))])


On Sunday, May 24, 2020 at 11:26:54 AM UTC-5, jos.koot wrote:
>
> Hi,
>
> I have:
>
>  
>
> #lang scribble/manual
>
> @(require (for-label racket) scribble/eval)
>
> @interaction[
>
> (let ((set 1)) (add1 set))]
>
>  
>
> I prepare a HTML document with DrRacket (in Windows 10).
>
> Works, but local variable set is hyperlinked to procedure set in the 
> documents (racket/set). I would like this variable to be typeset as any 
> other local variable. How can I do that without loosing the hyperlink where 
> I do mean the procedure from racket/set ?
>
>  
>
> Thanks, Jos
>

-- 
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/ffd4f155-ee18-409d-b92f-9450d976220f%40googlegroups.com.


[racket-users] Re: New week, new Racket! What are you folks up to?

2020-04-21 Thread Ryan Kramer
I'm finally finishing up a major overhaul of Plisqin, my alternative to 
SQL. I don't think I will consider it "stable" just yet, but it is getting 
much closer. The biggest new feature is a type system that prevents the 
three-valued logic mistakes that are too easy to make in SQL. I also hope 
to write better documentation this time around thanks to a better example 
database. (I've ported the AdventureWorks schema and some of the data to 
SQLite.)

I also think I can add basic Typed Racket support pretty easily. If I know 
the names and types of each column that a query will produce, I can expose 
this to Typed Racket as, for example:

(: get-users (-> DbConnection
 (Sequenceof (Object (field [first-name String]
[last-name String]
[age Number])

Will this actually be useful? I'm not sure, but at this point it doesn't 
seem like much more work than the untyped version. I'd welcome advice here. 
Is "fields vs methods" worth thinking about? Or maybe Object isn't the best 
type to use. But Object seems like the best way to get structural-ish 
typing, which is probably better than (Sequenceof get-users-result) or 
something like that.


On Sunday, April 19, 2020 at 12:04:18 PM UTC-5, Stephen De Gabrielle wrote:
>
> New week, new Racket! What are you folks up to? 
>
> Answer here or on 
> - https://racket.slack.com/ (Sign up at 
> https://racket-slack.herokuapp.com/ ) 
> - `#racket` IRC on freenode.net https://botbot.me/freenode/racket/ 
> - Tweet @racketlang on Twitter 
> - Racket discord https://discord.gg/6Zq8sH5 
> - [r/racket](https://www.reddit.com/r/Racket) 
>
> Don’t forget to sign up for, and contribute to Racket News at 
> https://racket-news.com/ AND submit your links to Racket Stories 
> https://racket-stories.com/
>
> Kind regards, 
>
> Stephen
>
>
>
>

-- 
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/c6888141-abfd-4073-ac3c-24f20a7dcacd%40googlegroups.com.


Re: [racket-users] How can I write a macro that recognizes arbitrary other macros?

2020-04-17 Thread Ryan Kramer
Thanks! That was much easier than I was expecting.

For posterity, here is some working code but be warned that I don't know 
whether 'module is the best expansion context to use. But this is a toy 
example anyway.

#lang racket

(define-syntax (collect stx)
  (syntax-case stx (define-values)
[(_ (define-values (id ...) expr) rest ...)
 #'(let-values ([(id ...) expr])
 (collect rest ...))]
[(_ (macro arg ...) rest ...)
 (syntax-local-value #'macro (lambda () #f))
 (let ([expanded (local-expand #'(macro arg ...)
   'module
   (list #'define-values))])
   (syntax-case expanded (define-values)
 [(define-values stuff ...)
  #`(collect #,expanded rest ...)]
 [else
  #'(cons (macro arg ...) (collect rest ...))]))]
[(_ a rest ...)
 #'(cons a (collect rest ...))]
[(_)
 #'(list)]))

(define-syntax-rule (my-define stuff ...)
  (define stuff ...))

(define-syntax-rule (my-list stuff ...)
  (list stuff ...))

(collect 1 2 (my-define x 3) x (my-list 4 5))


On Thursday, April 16, 2020 at 9:50:45 PM UTC-5, Matthew Flatt wrote:
>
> The main trick in this case is to recognize `define-values` (which is 
> what `define` expands to) instead of `define`. That's because 
> `define-values` propagates syntax arming to its identifiers and 
> right-hand side, which means that your macro is allowed to pull it 
> apart. 
>
> You'll also need to use an expansion context other than 'expression, 
> though. 
>

-- 
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/8b62651d-86de-4ab8-b9b7-27c4a818dfbf%40googlegroups.com.


[racket-users] How can I write a macro that recognizes arbitrary other macros?

2020-04-16 Thread Ryan Kramer
The following code produces '(1 2 3 4)

(define-syntax (collect stx)
  (syntax-case stx (define)
[(_ (define id val) rest ...)
 #'(let ([id val])
 (collect rest ...))]
[(_ (macro arg ...) rest ...)
 (syntax-local-value #'macro (lambda () #f))
 (let ([expanded (local-expand #'(macro arg ...) 'expression (list 
#'define))])
   (println expanded)
   #`(collect #,expanded rest ...))]
[(_ a rest ...)
 #'(cons a (collect rest ...))]
[(_)
 #'(list)]))

(define-syntax-rule (my-define stuff ...)
  (define stuff ...))

(collect 1 2 (define x 3) x 4)


I would like `(collect 1 2 (my-define x 3) x 4)` to produce the same 
result. But instead I get the error message "let-values: cannot bind 
tainted identifier in: x"

"OK, maybe this is impossible" I thought, and moved on to what I should 
have been working on anyway. But now I see that `class*` does seem to 
recognize arbitrary macros. The following example shows that `class*` 
seemingly understands my arbitrary `define-foo` macro:

(define-syntax-rule (define-foo)
  (define/public (foo)
(list this 'foo)))

(define my-class%
  (class* object% ()
(super-new)
(define-foo)))

(define c (new my-class%))
(send c foo)

How does `class*` understand my `define-foo` macro? And can the same 
technique be used to fix my `collect` macro?

-- 
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/0d01f4c1-f0b4-49cb-b9c2-fca7e2ca6429%40googlegroups.com.


[racket-users] Re: `raco test` seems slower, not caching any compilation results?

2020-03-19 Thread Ryan Kramer
On Wednesday, March 18, 2020 at 7:47:22 PM UTC-5, Ryan Kramer wrote:
>
> I'm currently using Racket 7.6 (non-CS) on Windows, and it feels like 
> `raco test` is much slower these days.
>

My mistake, it seems `raco test` never created the "compiled" directories 
with the dep and zo files. I found that using `raco setup -l ` does 
create the dep and zo files, so I just need to remember to do that whenever 
I see the slowness.

-- 
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/b3db4ab9-4d74-4613-b75b-6791bbe7b8a7%40googlegroups.com.


[racket-users] `raco test` seems slower, not caching any compilation results?

2020-03-18 Thread Ryan Kramer
I'm currently using Racket 7.6 (non-CS) on Windows, and it feels like `raco 
test` is much slower these days. Specifically I am seeing

`raco test tests.rkt` takes 10 seconds. This is fine the first time, but 
repeating the test immediately also takes 10 seconds. It never creates any 
"compiled" directories.

Meanwhile, if I open tests.rkt in DrRacket, the first run takes about 10 
seconds but then subsequent runs (without changes) take about 1 second. 
This creates a "compiled" directory, which I thought raco test would be 
able to use, but no luck -- raco test still takes 10 seconds.

I think this is a regression from 7.5, or else something strange is 
happening on my machine. I will try reverting to 7.5 soon to see if I can 
definitely determine the difference.

Does anyone know why this might be occurring?

-- 
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/b7c7b864-3208-4a98-bfc2-84b9c3a1a313%40googlegroups.com.


[racket-users] Re: Help with simple macro transformation

2020-02-17 Thread Ryan Kramer
Gah, of course it's possible with patterns. For some reason I just didn't 
think of matching `(id rest ...)`

(define-syntax (rearrange stx)
  (syntax-case stx ()
[(_ [(id rest ...) body]
more ...)
 #'(cons '[id body]
 (rearrange [(rest ...) body]
more ...))]
[(_ [() body]
more ...)
 #'(rearrange more ...)]
[(_)
 #'(list)]))


-- 
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/0ee5ab41-0ddd-4722-be69-6d5001847dd5%40googlegroups.com.


[racket-users] Help with simple macro transformation

2020-02-17 Thread Ryan Kramer
I'm 95% sure I've done this before, but for some reason I am really stuck 
right now. Given

(rearrange ([(a b c) 1]
[(d e) 2]))

I would like any kind of shape containing [a 1] [b 1] [c 1] [d 2] [e 2]. 
Any kind of nesting should be fine as long as the ids are matched up 1:1 
with the numbers. I've tried variants of the following but always run in to 
"incompatible ellipsis" problems:

(define-syntax-rule (rearrange [(id ...) body] ...)
  '(([id body] ...)
...))

Can this be done with patterns, or do I need to use quasisyntax splicing 
and list manipulation?

Larger context: I am making a table of proc-ids and proc-bodies. Some procs 
share the same bodies, so I want to be able to write [(a b c) shared-body], 
but eventually I need to get to [a shared-body] ...

-- 
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/103ad2ab-432e-4e65-b3c5-1a080c310b01%40googlegroups.com.


[racket-users] Surprising behavior in The Printer

2020-01-10 Thread Ryan Kramer
I have a small program that demonstrates some surprising behavior regarding 
`prop:custom-print-quotable 'never`. Perhaps it could be considered a bug, 
although I haven't seen anything in the docs that this violates. I've found 
that

1. When I call `(println y)`, my `custom-display` is called first. And what 
I do in `custom-display` affects the result of `(println y)`
2. The printer is doing something with `eq?` rather than `equal?`. (Does 
this mean that constructing any new data structure, even a list, during 
printing is an anti-pattern?)

In the example below, if `(maybe-rebuild lst)` returns `(identity lst)` 
then `prop:custom-print-quotable 'never` works as I expected. But if 
`(maybe-rebuild lst)` returns `(apply list lst)` which is a list that is 
equal? but not eq? to the original list, then `prop:custom-print-quotable 
'never` surprises me.

#lang racket

(require racket/struct)

(struct my-struct (item) #:transparent
  #:property prop:custom-print-quotable 'never)

(define (go port mode val)
  (let ([proc (make-constructor-style-printer
   (λ (me) 'my-class%)
   (λ (me) (list val)))])
(proc (void) port mode)))

(define (maybe-rebuild lst)
  ; Works as expected if we return the same list
  #;(identity lst)
  ; But this breaks prop:custom-print-quotable 'never
  (apply list lst))

(define my-class%
  (class* object% (printable<%>)
(super-new)
(init-field content)
(define/public (custom-print port mode)
  (go port mode content))
(define/public (custom-write port)
  (go port #t content))
(define/public (custom-display port)
  (go port #f (maybe-rebuild content)

(define x (list 'CONTENT (my-struct '(1 a
(println x)
(define y (new my-class% [content x]))
(println y)


-- 
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/a8205ac0-bb35-4ffe-aa5e-56377a80cf24%40googlegroups.com.


[racket-users] Re: Can `parameterize` work with pretty printing?

2020-01-03 Thread Ryan Kramer
I found `make-tentative-pretty-print-output-port` and 
`tentative-pretty-print-port-transfer` which looks like it might be the 
right way to go. I changed `write-now` as follows:

(define (write-now proc x port mode)
  (if (pretty-printing)
  (let* ([alt-port (make-tentative-pretty-print-output-port port

(pretty-print-columns)
(λ () 
(void)))]
 [_ (proc x alt-port mode)])
(tentative-pretty-print-port-transfer alt-port port))
  (let* ([alt-port (open-output-string)]
 [_ (proc x alt-port mode)]
 [str (get-output-string alt-port)])
(write-string str port

And it looks like it mostly works, except that now it seems to ignore my 
`prop:custom-print-quotable 'never`, or else I am missing it somewhere... 
I'll investigate more.


But I don't understand how the `overflow-thunk` of 
`make-tentative-pretty-print-output-port` should be used. From the docs: 
"The overflow-thunk procedure is called if more than width items are 
printed to the port or if a newline is printed to the port via 
pretty-print-newline; it can escape from the recursive print through a 
continuation as a shortcut, but overflow-thunk can also return, in which 
case it is called every time afterward that additional output is written to 
the port."

Does that mean its return value is ignored? It seems like it. And when (if 
ever) should I call `tentative-pretty-print-port-cancel` instead of 
`tentative-pretty-print-port-transfer`?

-- 
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/8aefe2fa-49bf-4d05-84c1-612a54d99ff5%40googlegroups.com.


[racket-users] Can `parameterize` work with pretty printing?

2020-01-03 Thread Ryan Kramer
I am `gen:custom-write` and `make-constructor-style-printer` on an object 
graph that may contain cycles. Within my custom write procedure, I use 
`parameterize` to register an object into dictionary and later in the 
writing process I can check that dictionary, detect the cycle, and do more 
custom write logic.

But I have noticed that sometimes that my `parameterize` has gone out of 
scope by the time the printer gets deeper into the object graph. I was able 
to work around this issue by using another port, then copying the result to 
the real port like this:

(define-syntax-rule (write-now proc x port mode)
  (let* ([alt-port (open-output-string)]
 [_ (proc x alt-port mode)]
 [str (get-output-string alt-port)])
(write-string str port)))

This is better than just doing `(proc x port mode)` because it always 
prints the string that I expect. However, it breaks pretty printing. I've 
noticed that the built-in pretty printing logic will sometimes hit the same 
leaf object multiple times, as if it is testing to see how wide the result 
is and backing up and trying again. Perhaps it can also delay evaluation? 
That would explain why my `parameterize` has ended.

Is there a way to use `parameterize` within custom write logic and keep 
pretty printing working? Is there a better approach I should take?



Additional Information
===
https://github.com/default-kramer/morsel/blob/master/morsel-lib/private/essence/base-query-printer.rkt#L22
The `write-now` macro, as written, is "correct but unpretty". I can change 
it to "incorrect but pretty" as follows:

(define-syntax-rule (write-now proc x port mode)
  (proc x port mode))


https://github.com/default-kramer/morsel/blob/master/morsel-lib/private/essence/from.rkt#L373
This is a test that fails in "incorrect but pretty" mode. Rackunit reports:

location:   from.rkt:373:2
actual:
  "(from #0=a/0 \"A\" (attach #1=b/1 \"B\" (attach #2=c/2 \"C\") #3=(list 
#0# #1# #2#)))"
expected:
  "(from a/0 \"A\" (attach b/1 \"B\" (attach c/2 \"C\") (list a/0 b/1 
c/2)))"


Here are two screenshots, one pretty and one unpretty:

[image: pretty.png]

[image: unpretty.png]

-- 
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/6369f1c7-a8a5-470e-af9f-ce1c133469ca%40googlegroups.com.


Re: [racket-users] contract for an "overloaded function"

2019-11-29 Thread Ryan Kramer
Thanks, but I don't think `case->` works for me. It looks like it chooses a 
case purely based on the number of arguments. The following example, when 
given two arguments, will always choose the integer? case even if both 
arguments are strings.

(case-> [-> integer? integer? list?]
[-> string? string? list?])

On Friday, November 29, 2019 at 1:51:52 PM UTC-6, David Storrs wrote:
>
> I think you want `case->`: 
> https://docs.racket-lang.org/reference/function-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._case-~3e%29%29
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/73132ad9-7722-432a-8328-0d4c38bbb5a1%40googlegroups.com.


[racket-users] contract for an "overloaded function"

2019-11-29 Thread Ryan Kramer
I'm not exactly sure what I mean by "overloaded function", but I think you 
will understand. I'm looking for something that would allow me to write a 
function contract like

(magic-> [integer? integer? -> integer?]
 [string? symbol? -> string?]
 [string? ...+ -> string?])

The above contract would mean:
  * If the function is given an argument list that satisfies (cons/c 
integer? (cons/c integer? null?)), then the return value must be an integer?
  * Else if the function is given an argument list that satisfies (cons/c 
string? (cons/c symbol? null?)), then the return value must be a string?
  * Else if the function is given an argument list that satisfies (cons/c 
string? (list/c string?)), then the return value must be a string?
  * Else the caller is blamed for not providing correct arguments.

(I don't think I need support for keyword arguments)

Does this already exist in a library somewhere? If not, it doesn't look too 
hard for me to roll my own but I am (perhaps prematurely) concerned about 
the performance. Would the following approach be reasonable?

(define-syntax-rule (magic-> [dom ... range-expr] ...)
  ; We should make sure that every dom and range is a flat-contract?
  (make-contract
   #:name '(magic-> [dom ... range-expr] ...)
   #:first-order procedure?
   #:projection
   (λ (blame)
 (λ (proc)
   (λ args
 (cond
   [((list/c dom ...) args)
(let ([range ((contract-projection range-expr) blame)])
  (range (apply proc args)))]
   ...
   [else
(raise-blame-error
 (blame-swap blame) args
 '(expected "a conforming argument list" given: "~e")
 args)]))

(define/contract (blah a b)
  (magic-> [integer? string? list?]
   [string? integer? (list/c string? integer?)]
   ; This one will throw a contract violation
   [integer? integer? integer?])
  (list a b))

-- 
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/b21a5512-521f-4c6e-8e4e-ca6d3528df8c%40googlegroups.com.


[racket-users] Re: GitHub ‘template repository’ functionality

2019-08-12 Thread Ryan Kramer
Ah, that makes sense. I guess I didn't realize (or took for granted) that 
`raco pkg new` was doing all that. With that in mind, it certainly does 
make more sense to run `raco pkg new` locally.

-- 
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/b7b626e1-b69c-41c3-9d73-92bf28672b90%40googlegroups.com.


[racket-users] Re: GitHub ‘template repository’ functionality

2019-08-09 Thread Ryan Kramer
Thanks Stephen, this looks useful.

I don't understand why you say "I think the template should only have the 
things that `raco pkg new` doesn't do." Wouldn't the intent be that I use 
the template to create my own repo, clone it onto my local machine, and 
then run `raco pkg install`? In that case, I think you would want the stuff 
from `raco pkg new`. (But my knowledge of packages and collections is 
just-enough-to-get-by.)

I recently struggled converting a repository from a single to a 
multi-collection package. (And I still have some learning and cleanup to 
do.) It might be nice to have a template for a simple multi-collection repo 
also. Maybe with lib, doc, and test collections? On the other hand, maybe 
multi-collection packages are too different for a template to make sense.

-- 
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/7827f4e3-af4b-4d0b-b12b-d97efbae07db%40googlegroups.com.


[racket-users] Re: Racket + Graphviz

2019-08-01 Thread Ryan Kramer
This looks interesting! I have thought about trying to generate Entity 
Relationship diagrams given a database schema, but assumed that laying out 
the boxes would be a hard problem. Looks like GraphViz might do a decent 
job at this. I'll try it out and let you know how it goes.

-- 
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/9566c624-74ce-4e8d-a332-00fc5b582ba4%40googlegroups.com.


[racket-users] Re: define/contract for private functions

2019-07-24 Thread Ryan Kramer
On Wednesday, July 24, 2019 at 12:55:58 AM UTC-5, Roman Klochkov wrote:
>
> I propose to use submodules like in 
> https://github.com/Kalimehtar/binary-class/blob/master/binary-class/base.rkt
>
> So you may in test module (require mod/safe) and in normal operation 
> (require mod).
>

Sorry, I wasn't clear what I meant by "private function." I am talking 
about functions that are not provided anywhere (e.g. they are only 
available in one source file). These functions often have comments like

;; integer symbol -> string

But making them contracts instead of comments can provide some benefits 
that I mentioned earlier.

-- 
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/8bf4684f-75ed-4d1f-add8-bb66bce7a0b8%40googlegroups.com.


[racket-users] define/contract for private functions

2019-07-23 Thread Ryan Kramer
I've found myself wanting to write contracts on private functions, but I 
don't want to pay the performance cost during normal operation. What I've 
been doing is making a `def/c` macro which looks exactly like 
`define/contract` but is wired up to `define` and discards the contract. 
When I want to enable these private contracts (e.g. when running tests or 
debugging a problem) I simply change the source code of `def/c` so that it 
is wired up to `define/contract` and the contract is checked. Here is an 
example: http://pasterack.org/pastes/4224

Manually changing the source code of `def/c` has worked fine so far, but I 
would love to be able to do something like "raco test 
-with-private-contracts (package1, package2) ./" instead.

I prefer this approach over putting the contracts in comments, because 
comments have less precise meaning and may become subtly inaccurate if the 
implementation of the function changes.

I wonder if other people want to write code the same way. If so, having a 
standard, shared `define/contract/private` could be useful. This would 
allow us to do things like
1) Build a contract-aware linter.
2) Build a "minimally intrusive type system." (This might also be called a 
"linter"; I'm not sure if there is a definite line separating the two.)
3) Better IDE support
4) If I suspect a package I am using has a bug, I might be able to confirm 
(but not deny) that suspicion by turning on private contracts for that 
package and seeing if a violation is reported.

So I guess if I'm the only one interested in this then just ignore me. If 
there's already work in this area, great! Please point me to it. But if 
there's interest and a need, I'd be happy to help however I can.

-- 
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/5e8ece69-bbb7-4dbf-933f-52cc097291d2%40googlegroups.com.


Re: [racket-users] datatypes

2019-07-17 Thread Ryan Kramer

>
>  Still, variant reports ‘(a . b) as a ‘pair. and that’s amazing. How is it 
> obtaining that information?
>

I just looked it up and yeah, it is pretty cool: (struct->vector '(a . b)) 
is doing most of the work. See the comments and implementation here: 
https://github.com/mbutterick/describe/blob/b468661a0e76fbe5ef46fe0e89e030f43f7b3acc/describe/main.rkt#L78

-- 
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/6cffaef7-eba2-487d-9bfc-eebb9881e647%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] can Typed Racket handle this function type safely?

2019-07-06 Thread Ryan Kramer

>
> (ann ((ann maybe-car (All (a b) (-> a a))) (list 1 2)) (Listof Integer)) 
>

Aha! That seems to answer my next question "is it truly unsafe?" with a 
Yes. Thanks Sam.

-- 
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/aa89681c-abae-463b-b1c6-421277ab2a20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] can Typed Racket handle this function type safely?

2019-07-05 Thread Ryan Kramer
In the code below, can `maybe-car` have the given type without using 
typed/racket/unsafe?

#lang typed/racket
(require typed/racket/unsafe)

(module untyped racket
  (provide maybe-car)
  (define (maybe-car x)
(cond
  [(pair? x) (car x)]
  [else x])))

(unsafe-require/typed
 'untyped
 [maybe-car (All (a b) (case->
(-> (Pairof a b) a)
(-> a a)))])

-- 
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/c8a25880-8127-405c-b862-95c4c3694440%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Request for Feedback (SQL, Plisqin)

2019-06-21 Thread Ryan Kramer
Thanks Alex, that was very helpful.
 

> it is not clear from the document how any of it can be useful.  
>

I got this same feedback from some friends on the 0.1 release.

Also, it is not clear
> what `Department?` and `Course?` are in the first code snippet -- are they
> functions that the user has to provide or is it something that your library
> generates by looking at the database schema?
>

I was planning on building the "generate functions by looking at the 
database schema" functionality later, but now I realize it might be a 
prerequisite for good documentation.

I would suggest to provide a database schema and some sample data in a
> database, and use this in the subsequent examples.  Start with a simple but
> complete working example and construct more complex, but still complete and
> working examples from them, at each step illustrating the benefits that the
> library provides.  Maybe contrast each step with how the plain SQL would 
> look
> as well?
>

I'm glad you said this because I am planning on doing this. I wrote the 
post you read hoping I could revise those ideas into a shorter, punchier 
"opening argument" before starting the slower walkthrough. But if it wasn't 
clear to you, I don't think I can possibly make it clear to Plisqin's 
target audience (some SQL experience, no Racket experience).

Documentation is hard!

-- 
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/f6f3cf03-b9bf-4769-8d5b-1f751e039269%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Request for Feedback (SQL, Plisqin)

2019-06-21 Thread Ryan Kramer
Oops, I got the link wrong: 
https://github.com/default-kramer/plisqin/wiki/Towards-Better-Relational-Query-Languages

On Friday, June 21, 2019 at 11:41:31 AM UTC-5, Ryan Kramer wrote:
>
> Target Audience: you have 10 minutes and you're familiar with libraries 
> that do SQL kinda like this:
>
> (from i "Item"
>   (where i".ReleaseDate > '2018-01-01'")
>   (select i".ItemName"))
>
> Article: 
> https://github.com/default-kramer/plisqin/wiki/Towards-Better-Relational-Query-Languages
>  
> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fdefault-kramer%2Fplisqin%2Fwiki%2FTowards-Better-Relational-Query-Language=D=1=AFQjCNEE95mJxUmrwClZwEk8FXnCqkmU9A>
>
> Context: Plisqin is my SQL generation library, but I think of it as an 
> "alternate query language" because theoretically it doesn't have to 
> generate SQL. (But it probably always will.)
>
> I'm gearing up to release Plisqin 0.3 and want to improve my 
> documentation. If I can't explain these concepts to fellow Racketeers, I 
> don't stand a chance of explaining them to the general public.
>
> Thanks for any feedback!
>

-- 
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/f7b58794-2716-4758-8c14-0b354030d460%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Request for Feedback (SQL, Plisqin)

2019-06-21 Thread Ryan Kramer
Target Audience: you have 10 minutes and you're familiar with libraries 
that do SQL kinda like this:

(from i "Item"
  (where i".ReleaseDate > '2018-01-01'")
  (select i".ItemName"))

Article: 
https://github.com/default-kramer/plisqin/wiki/Towards-Better-Relational-Query-Language

Context: Plisqin is my SQL generation library, but I think of it as an 
"alternate query language" because theoretically it doesn't have to 
generate SQL. (But it probably always will.)

I'm gearing up to release Plisqin 0.3 and want to improve my documentation. 
If I can't explain these concepts to fellow Racketeers, I don't stand a 
chance of explaining them to the general public.

Thanks for any feedback!

-- 
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/1ec9475b-2d0c-42f2-99eb-ede13075295c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: grammar-based fuzzing

2019-06-12 Thread Ryan Kramer
Thanks everyone for the good suggestions. Xsmith looks particularly 
appealing, looking forward to 1.0!

-- 
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/3b54c6c7-94fe-49b0-a3ba-23fc7dab2091%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] grammar-based fuzzing

2019-06-06 Thread Ryan Kramer
Does Racket have any grammar-based fuzzing utilities? I'm probably going to 
play around with this either way, but if there is an existing solution I'll 
quit after I've had my fun. If, however, people think Racket could use 
something like this I may attempt to make it into a usable package.

I'm thinking specifically about generating inputs for Quickcheck, but such 
a fuzzer might have other uses.

For example, given this grammar:

(struct tree (left right) #:transparent)

(define-grammar tree-grammar
  [Leaf (:choose-integer - )]
  [Subtree #'(tree Node Node)]
  [Node #:max-nesting 10
(:weighted-choice
 [1 Leaf]
 [5 Subtree])])

Then (tree-grammar 'Subtree) might generate #'(tree 1 (tree 2 3)) as one of 
many possibilities.

An important feature that I haven't seen yet is tracking/scoping 
identifiers. There are times when we want to generate any arbitrary 
identifier, and other times when we want to use an existing identifier that 
we know is in scope. For example, if we were fuzzing `let` we might have

(define-grammar let-grammar
  [Root #'(let ([LetId LetVal]
...)
LetBody)]
  [LetId (:choose-identifier)]
  ; TODO ...
  )

And somehow we want to say that LetBody can and should use the enclosing 
LetIds, but I don't immediately see a great way to communicate that. It 
might be possible to have something like (:choose-bound LetId) which would 
generate a LetId that is known to be in scope.

-- 
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/832ed76d-33f6-4f3f-b80f-da891613b6a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Macro guards question

2019-05-29 Thread Ryan Kramer
#'arg is a syntax object, therefore (number? #'arg) or (string? #'arg) will 
always be false. If you are trying to dispatch based on literals, you could 
use e.g. (number? (syntax-e #'arg)) to identify a numeric literal. But it 
is not very common that a macro handles a numeric literal differently than 
an identifier that is bound to a numeric value at runtime. I'm guessing you 
can use a regular procedure and cond for most of this.

-- 
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/111c1509-d77f-48d6-8c1f-19a37748cace%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: catch and bind an unbound id in a macro

2019-04-20 Thread Ryan Kramer
Below is a short example showing that identifier-binding doesn't seem to 
work quite right with Scribble's make-base-eval. It works fine with 
make-evaluator from racket/sandbox.

I'm not sure why this is, but using syntax-local-value instead works 
everywhere. (Implementation here: 
https://github.com/default-kramer/plisqin/commit/2723d7c11be5b6938e681ea869e8b9f4957849b0#diff-1a91d998f2be05413392d588a89323d3R31)

#lang racket
(require scribble/eval
 racket/sandbox)

(define (setup eval)
  (eval
   '(define-syntax (define-if-not stx)
  (syntax-case stx ()
[(_ id val)
 (identifier-binding #'id)
 #'(void)]
[(_ id val)
 #'(define id val)]

(define scribble-eval (make-base-eval))
(scribble-eval '(require racket))
(setup scribble-eval)

(define racket-eval (make-evaluator 'racket))
(setup racket-eval)

(scribble-eval '(define-if-not foo 1))
(scribble-eval '(define-if-not foo 2))
(scribble-eval 'foo) ; want 1, get 2

(racket-eval '(define-if-not bar 3))
(racket-eval '(define-if-not bar 4))
(racket-eval 'bar) ; want 3, get 3

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: catch and bind an unbound id in a macro

2019-04-19 Thread Ryan Kramer
For what it's worth, Matthias' original answer has solved an issue I had. I 
was using identifier-binding for something very similar and it worked fine, 
except in my scribble examples. I had example 1 define foo, but then 
example 2 (with the same evaluator) would not "see" foo via 
identifier-binding, so it redefined foo instead of appending to foo. Using 
syntax-local-value instead seems to have fixed it (pending further testing).

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] bracket generator

2019-03-20 Thread Ryan Kramer
Anyone need to pseudo-randomly generate a bracket for march madness (or any 
other occasion)? Here you go: 
https://gist.github.com/default-kramer/073b68122ea047ac46b33af20cb1eba1

The data I used is too averse to upsets for my taste. If I were going to 
generate another bracket, I would add some more chaos. But that's a 
personal preference.

Enjoy!

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Pretty display of tabular data?

2019-03-14 Thread Ryan Kramer
On Thursday, March 14, 2019 at 12:26:39 AM UTC-5, Alex Harsanyi wrote:

>
> There are now several projects announced on this list, all of them deal 
> with
> data analysis on one way or the other.  Would it be possible to join forces
> and merge these projects so that we end up with one library that servers
> multiple purposes equally well?  Something where the final product is 
> greater
> than the sum of its parts...
>
> Or perhaps these libraries have aims that are so different from each other
> that the only thing they share is a very abstract concept of "table"?
>

I think my project "plisqin" is one of those you are thinking of. Matt's 
"tbl" is also one. I'm also keeping an eye on Ryan's "sql". Are there any 
more you were thinking of?

Regarding joining forces/merging these projects, this is a good question 
that I think warrants discussion. So I'll share my thoughts.

Obviously I can't speak for all of us, but right not I only see the "very 
abstract concept of "table"" as potential shared code. (Also, learning 
about snip% earlier in this thread was awesome. I'd love to use something 
like that in my project.)

I think the differences between plisqin and tbl are fairly obvious - 
plisqin is an alternative to SQL while tbl is an alternative to 
"Python/NumPy/SciPy, or R/Tidyverse (or, horrors, plain R)"

Now comparing Ryan's sql to plisqin is a different story. These projects 
are both alternatives to SQL. But I think there is enough difference 
between our approaches and scope to warrant separate projects, at least for 
now.
1) sql seems to be mostly implemented as macros. plisqin is mostly 
implemented as procedures.
2) plisqin has some design decisions that some might consider "too much 
magic", namely inline joins and "inject-able aggregates" (need better name) 
as documented here: https://docs.racket-lang.org/plisqin/intro.html. 
Whereas sql-the-package seems to more closely mirror SQL-the-language - it 
would be difficult to surprise yourself with the SQL you generate.
3) I am trying to design #lang plisqin so that people with no Lisp 
experience can use it. (Whether I will succeed is another matter...)

I apologize to Ryan C if I have mischaracterized sql. I'd like to have a 
longer conversation about this, but maybe this list is not the right place. 
(Also, Ryan, if you think our goals are more similar than I do, I'd be 
happy to work with you. You're definitely a more experienced Racketeer and 
it would surely boost my code quality.)

- Ryan Kramer

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] lightning talk ideas?

2019-02-25 Thread Ryan Kramer
Thinking about evangelism... I go to a functional programming meetup and we 
usually do "lightning talks" which are described as:

"Sticking with our short talk/demo format, we will once again have 3 - 5 
> slots available for you to show what you're working on, share something you 
> learned, or demo some cool code.
>
> The presentation should aim to be 5 - 15 minutes, with a hard time limit 
> of 20 minutes. Please post a comment with a brief description of what you'd 
> like to present. Anything FP-related is fair game!
>
> I'd really like to encourage as many members as possible to participate. 
> Even if you're just learning something, you can still present. It will help 
> you learn it more deeply by sharing and explaining."
>

I've given two, with a 3rd one planned:
1) you can customize #%app and that's pretty cool
2) define/contract made me realize static typing isn't as important as I've 
always thought
3) scribble is awesome (seriously, does any language have a better code 
documentation tool?)

Obviously there are many great things about Racket, but it can be hard to 
think of a talk that
1) targets FPers who may not have scheme experience
2) can be explained quickly
3) leaves the audience thinking "that's cool, maybe I should take a look at 
Racket"

Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Use cases for tables and records

2019-02-22 Thread Ryan Kramer
On the topic of tables, I recently thought "It would be nice if DrRacket 
had some awareness of tabular data, in the same way that picts and syntax 
objects get special treatment."

For my project, I just wrote a quick-and-dirty function to make an ASCII 
art table and moved on: 
https://github.com/default-kramer/plisqin/blob/3d48cacd3c4239aa0a3a96d712cfdef09272422c/private/rows-result-to-string.rkt#L80

But if we're all working with tables, perhaps it would be worth the time 
investment to enhance DrRacket so that tabular data is formatted better, 
copies well to a spreadsheet, and is scrollable in the case of larger data 
sets. Maybe more features I'm not thinking of.

I have no idea how much work this would be. But if this sounds like a good 
idea, and if someone could give me some guidance, I wouldn't mind making an 
attempt.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: "raco test" causes my reader to fail on carriage return (but newline works)

2019-02-03 Thread Ryan Kramer
Progress! Either rebooting, upgrading to 7.2, or something else caused 
DrRacket to start failing in the same way that raco does*. Now it feels 
like a normal problem I can solve using my normal techniques (of scattering 
printlns everywhere).

(* I was wrong when I said that "raco setup" was working - it wasn't.)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] "raco test" causes my reader to fail on carriage return (but newline works)

2019-02-02 Thread Ryan Kramer
I have a scribble document with a string representation of some code. The 
string is "(+ 1 2) \r\n (* 2 3)" which eventually gets sent through my 
reader.

When I run "Scribble HTML" in DrRacket it works. When I run "raco setup" it 
works. But when I run "raco test" my reader fails with

(exn:fail:read:eof "prog:2:0: read-syntax: expected a `)` to close `(`" 
# (list (srcloc 'prog 2 0 15 1)))

If I remove the \r so that the string is "(+ 1 2) \n (* 2 3)" then 
everything works, including "raco test".

My reader depends on (current-readtable) so my best guess is that "raco 
test" is modifying it before my reader runs. (Is there a way I can access 
the default readtable used by #lang racket, instead of using 
current-readtable? That would probably be better.)

Or maybe there is some parameter that controls newline handling?

I don't know a good way to debug this. Any suggestions and wild guesses are 
appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Why would a value produced by eval-ing code not satisfy its type predicate? (Particularly, a SQL statement from the sql package)

2019-02-01 Thread Ryan Kramer

>
> PS There's also a racket package called plisqin which seemed closer to 
> what I was looking for. Maybe in a few months or so if it clicks I'll see 
> if I can add to that package everything I need (things like limit and 
> distinct) and it might work out.
>

Good news, limit and distinct are in scope for v0.2 - I'm working on it now 
:)

Right now, the scope for plisqin 0.2 is determined by
1) About 6k lines of SQL from my day job
2) Ecto's query API: https://hexdocs.pm/ecto/Ecto.Query.API.html#content

I figure that's a decent way to define a reasonable scope. But if you or 
anyone has a list of "must have" features, let me know and I'll certainly 
consider it.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Scribble examples for languages other than Racket

2019-01-25 Thread Ryan Kramer
On Thursday, January 24, 2019 at 9:45:39 PM UTC-6, Alex Knauth wrote:
>
> Would the `scribble-code-examples` package work for you? 
> https://docs.racket-lang.org/scribble-code-examples/index.html
>
> Looks like yes, it will! Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Scribble examples for languages other than Racket

2019-01-23 Thread Ryan Kramer
OK, I found a much better way. Rather than trying to tweak a syntax object 
to pass in to "examples", it's much easier to use the Low-Level Scribble 
API to rebuild a document fragment that looks like what the built-in 
"examples" would build. What I have now just needs a little CSS and it 
looks close enough. 
https://github.com/default-kramer/plisqin/blob/87a0cca6e2909f5d18c20235a43215f09f1db779/scribblings/TEMP-scribble-lang-idea.scrbl

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Scribble examples for languages other than Racket

2019-01-22 Thread Ryan Kramer
I was thinking about how to document #lang plisqin, a language I am working 
on. I wanted to use the "examples" procedure from scribble/example. But it 
looks like when you use the #:lang option, it disables evaluation and 
printing of results. (The typesetting works fine though.)

I came up with a workaround, in which I programmatically construct a 
racketblock that looks like the standard examples. You can see a working, 
single-file prototype here: 
https://github.com/default-kramer/plisqin/blob/dev/scribblings/TEMP-scribble-lang-idea.scrbl

Since I control the evaluator, this should allow me to typeset a fragment 
of #lang plisqin such as

  {where x.Foo > 3}

but evaluate it as

  (where (> (Foo x) 3))

which will allow me to print the result. (I might even try to typeset both 
syntaxes side-by-side or something.)

Has anyone done something similar?

Does my approach seem reasonable?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Is Racket a good fit for my application?

2019-01-09 Thread Ryan Kramer
Scribble is awesome, but I don't think it's the first tool I would reach 
for in this situation. I'm assuming your reports will be mostly tabular and 
not very much prose, in which case Scribble might become an unnecessary 
layer that gets in the way of what you are really trying to do, which is 
generate HTML.

I would probably try to use X-expressions and something like xexpr->html 
[1] to generate an HTML report. Especially if you are planning on building 
a web UI in the future, HTML as X-expressions should work well. (See for 
example [2] which uses X-expressions.)

[1]: 
https://docs.racket-lang.org/txexpr/index.html#(def._((lib._txexpr%2Fmain..rkt)._xexpr-~3ehtml))
[2]: https://docs.racket-lang.org/continue/

Disclaimer: I've never done anything like this in Racket so I could be way 
off.

If you want to go from HTML to PDF automatically, it might be worth 
considering chrome from the command line:

chrome.exe --headless --disable-gpu --print-to-pdf=my-report.pdf 
my-report.html

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to disallow certain characters in identifiers?

2018-12-20 Thread Ryan Kramer
Interesting. I had never heard of 3d syntax before. But I'm not sure what 
advantage 3d syntax would get me here. If I have to write my own custom 
version of "define", couldn't it just as easily detect a dot in a regular 
syntax object?

On Wednesday, December 19, 2018 at 6:29:22 PM UTC-6, Milo Turner wrote:
>
> Another option, which probably has a lot of terrible consequences, is to 
> transform "a.b" into "3-d syntax" (a struct embedded in syntax) that can 
> now be interpreted differently by forms that are interested. For instance a 
> custom "define" could grab the 3d-syntax in the name and use it to make a 
> decision on what to actually define (or raise an error). In an expression 
> context, #%datum could see this syntax and transform it into some sort of 
> binding looking or other syntax (e.g. (#%dot a b)), which could then be 
> resolved in the typical way.
>
> This approach probably wouldn't work very well because a lot of syntax 
> transformers don't expect to see 3-d syntax. In fact sometimes 3-d syntax 
> is rejected before being made into a syntax object. If you can get this to 
> work I will be pretty impressed.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to disallow certain characters in identifiers?

2018-12-11 Thread Ryan Kramer
Thanks for your response Alexis. You are right: once I figured out the 
correct way to customize the reader, the rest fell into place much more 
easily. Now, when my reader sees a dot it asks the base reader to read 
another piece of syntax, which must be an identifier.

So (define a.b 3) becomes (define a .b 3) and the default error message is 
good enough for now, especially since Racket prints out the 2nd version 
with the error message.

Also, I realized what a bad idea rewriting "a+b" to (+ a b) is. Because 
then I should do the same for subtraction. And then, for example, 
"struct-info" becomes (- struct info) which is a death sentence for a 
language based on Racket. So now infix notation requires whitespace around 
the operator.

For those curious "what are you really trying to do anyway?" I really like 
how at-exp can attach a convenient syntax onto racket without interfering 
with your ability to write standard racket. I am trying to do something 
similar. In my language, curly braces will get treated differently than the 
other paren-shapes. For example {if 10 .add1 {.equal? 11} 'yep 'nope} will 
get rewritten to (if (equal? (add1 10) 11) 'yep 'nope). My hope is that 
experienced Racketeers will find it convenient when they want to use it, 
and unintrusive when they don't. And that beginners who would be scared off 
by raw s-expressions will find it familiar enough to be pleasant.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] How to disallow certain characters in identifiers?

2018-12-10 Thread Ryan Kramer
It turns out expanding the syntax object isn't the right approach. It seems 
easy enough for defining values and simple procedures, but as soon as you 
consider optional arguments and keyword arguments, the resulting expansion 
gets too complicated to analyze.

I don't see an easy way to do this, unless there is some hook that I am 
unaware of. For example, applications get piped through #%app and unbound 
identifiers get piped through #%top. If there is #%something that new 
identifiers get piped through, that would be what I want. But I don't think 
it exists.

So my next attempt will be to go back to the reader, and make it so that 
certain characters (like dot and +) are always treated as individual 
tokens. Meaning that (define foo+bar 42) will come out of the reader as 
(define foo + bar 42). The resulting error message should be good enough 
for my purposes, I think.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] What is the expected PLT package catalog refresh rate? Is it not refreshing now?

2018-11-19 Thread Ryan Kramer
Thanks Jay, it looks like it worked. Or at least, "raco pkg install
plisqin" works. But I'm not sure why "This package needs documentation"
still shows up. Is something wrong with my info.rkt, or should I give PLT
some more time?

David, thanks for your interest. Did you install using "raco pkg install
plisqin"? Because then you should be able to find the documentation in your
pkgs directory. On my Windows machine, it gets installed here:
C:/Users/kramer/AppData/Roaming/Racket/7.1/pkgs/plisqin/doc/plisqin/index.html
Now, to answer your questions:
1) The DB diagram came from SQL Server Management Studio.
2) This could be a nice feature to have. Take a look at sections 3.2.1 and
3.2.2 to see how I generate the code manually for now.
3) I don't see myself getting into DDL anytime soon. I am primarily focused
on queries right now. Maybe take a look at section 6.1 to see what I'm
thinking about doing next.


On Mon, Nov 19, 2018 at 10:58 AM David Storrs 
wrote:

>
>
> On Mon, Nov 19, 2018 at 11:50 AM Jay McCarthy 
> wrote:
>
>> That error means, "The package server knows about this package but
>> never got a checksum, so I'm giving up." It would be fixed once the
>> server updates (which I just noticed it do after I kicked it for
>> Kramer)
>>
>
> Cool, thanks for letting me know.
>
>
> Kramer, this package looks very cool.  I skimmed through the examples but
> didn't dive deep, so I still have a lot of questions.  Full documentation
> would be great, but filling in the README would be more than enough.
>
> Some of the aforementioned questions:
>
> * Did the code autogenerate that UML diagram, or did you create it
> elsewhere?
>
> * Can plisqin introspect an existing database and generate code to
> describe it?  If not, is that a feature you would consider adding?  It
> would be nice to be able to start from an existing schema, then evolve it
> from the code.
>
> * If you do have/add the 'introspect an existing DB' functionality, it
> would allow you to auto-generate DDL for upgrade / rollback on the schema.
> Is that a feature you might add?
>
>
>
>> Jay
>> On Mon, Nov 19, 2018 at 11:47 AM David Storrs 
>> wrote:
>> >
>> > I tried to install it and got this:
>> >
>> > $ raco pkg install plisqin
>> > Resolving "plisqin" via
>> https://download.racket-lang.org/releases/6.11/catalog/
>> > Resolving "plisqin" via https://pkgs.racket-lang.org
>> > raco pkg install: cannot use empty checksum for Git repostory package
>> source
>> >   source: https://github.com/default-kramer/plisqin.git
>> >
>> > You can force a refresh by going to the top-right corner where your
>> name is, click that, and then choose "re-scan all my packages".
>> >
>> >
>> >
>> > On Sun, Nov 18, 2018 at 8:03 PM  wrote:
>> >>
>> >> I've just uploaded a package to the PLT catalog:
>> https://pkgd.racket-lang.org/pkgn/search?tags=author%3Adefault.kramer%40gmail.com
>> >>
>> >> But I don't think it is refreshing? It tells me "This package has been
>> modified since the package index was last rebuilt. The next index refresh
>> is scheduled for Monday, November 19th, 2018 12:58:07am (UTC)."
>> >>
>> >> It always says the next refresh is less than 5 minutes away. But the
>> message remains.after waiting 5 or more minutes.
>> >>
>> >> (Other clues that make me think it is not refreshing: PLT tells me
>> "This package needs documentation" even though it has documentation. And
>> "raco pkg install plisqin" finds nothing.)
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> Groups "Racket Users" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> an email to racket-users+unsubscr...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "Racket Users" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to racket-users+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
>> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
>> -=[ Moses 1:33: And worlds without number have I created; ]=-
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.