Re: [racket-users] Megaparsack and where errors happen

2020-02-21 Thread Alexis King
Hi Matt,

I think you probably want to read this section of the docs: 
https://docs.racket-lang.org/megaparsack/parsing-branching.html#%28part._.Backtracking_with_caution%29

The core idea is that `try/p` is a heavy hammer. It causes any failure inside 
its scope to backtrack, so you might end up accidentally ruining your error 
messages. Usually, what you really want is to do a small amount of lookahead to 
determine which branch is the correct one to take, then commit to the branch so 
that future parse failures are reported immediately.

Without seeing your `base-type/p`, `convert/p`, and `chain/p` parsers, it’s 
hard to suggest a concrete solution. But consider using `try/p` to do only 
whatever parsing you need to do in order to disambiguate the parsers, then exit 
the scope of `try/p`. Something like this:

(or/p (do (try/p base-type-initial/p) base-type-remainder/p)
  (do (try/p convert-initial/p) convert-remainder/p)
  ...)

There are other approaches as well, and if you provide more information I might 
be able to suggest something better.

This complication is unfortunately fundamental to the Parsec parsing model. The 
syntax/parse model of tracking “progress” and reporting the error associated 
with the parse that made it the farthest is much nicer, but syntax/parse has 
the luxury of parsing a well-known tree structure. A more tractable improvement 
might be to add some kind of explicit committing construct.

Hope this helps,
Alexis

> On Feb 21, 2020, at 20:19, Matt Jadud  wrote:
> 
> Hi all,
> 
> This might be a Lexi question, but perhaps someone else will have some 
> insight as well.
> 
> I'm wrestling with how to get errors to propagate down in megaparsack. For 
> example:
> 
> (define convert/p
>   (do (string/p "convert")
>  ...
>   [assigns ← (many/p #:min 0
>  assignment-statement/p
>  )]
>  ...
>   (pure ...)))
> 
> (Assume I have a bunch of other parsing bits around the call to 
> `assignment-statement/p`.)
> 
> Currently, if I have a malformed assignment statement, the error is at the 
> top level of `convert`. `convert/p` is part of a backtracking conditional:
> 
> (define conversion/p
>   (do
> [result ← (many/p (or/p (try/p base-type/p)
> (try/p convert/p)
> (try/p chain/p)
> )
>   #:sep space0+/p
>   )]
> eof/p
> (pure result)))
> 
> What should I do to get the error to report/fail down the parse tree, as 
> opposed to the top? I would rather know that there's something wrong down in 
> my assignment statement, as opposed to getting an error that "c" was 
> unexpected (because the entire conversion/p failed on account of an error 
> somewhere down inside).
> 
> I need to give the docs a more careful read, but I thought I'd ask, as it 
> seems both simple and, given the nature of the parsing tools, possibly subtle.
> 
> Many thanks,
> Matt
> 
> 
> -- 
> 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/CAAGM45761tRo%2Bj0Rh078ngriYiMDum%3DyDyRgwQ1LLiuPZDFj6A%40mail.gmail.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/69FA9918-BD9C-4041-85A7-BCF87867%40gmail.com.


Re: [racket-users] How do I just run the type checker?

2020-02-21 Thread Ben Greenman
On 2/21/20, 'David Florness' via Racket Users
 wrote:
> Sam Tobin-Hochstadt  writes:
>
>> If you compile the file with `raco make server.rkt` then it will run
>> the type checker as part of compilation. Furthermore, it will run
>> faster the next time since it won't have to re-compile.
>
> Question about this: if, after runing `raco make server.rkt` I run
> `racket server.rkt`, will the bytecode be used?

yes

-- 
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/CAFUu9R6aD5c2jU5FXrkmJ%2BnbHyeU7MC6hw12zyjXbA0Ug3HUAA%40mail.gmail.com.


Re: [racket-users] How do I just run the type checker?

2020-02-21 Thread 'David Florness' via Racket Users
Sam Tobin-Hochstadt  writes:

> If you compile the file with `raco make server.rkt` then it will run
> the type checker as part of compilation. Furthermore, it will run
> faster the next time since it won't have to re-compile.

Question about this: if, after runing `raco make server.rkt` I run
`racket server.rkt`, will the bytecode be used?

Thanks

--
David

-- 
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/87imjz96nj.fsf%40florness.com.


signature.asc
Description: PGP signature


Re: [racket-users] How do I just run the type checker?

2020-02-21 Thread Marc Kaufmann
Fantastic, that's what I was looking for, thanks.

Marc

On Friday, February 21, 2020 at 6:27:23 PM UTC+1, Sam Tobin-Hochstadt wrote:
>
> If you compile the file with `raco make server.rkt` then it will run 
> the type checker as part of compilation. Furthermore, it will run 
> faster the next time since it won't have to re-compile. 
>
> Sam 
>
> On Fri, Feb 21, 2020 at 12:13 PM Marc Kaufmann 
> > wrote: 
> > 
> > Hi, 
> > 
> > the way I currently check my web server is by simply running `racket 
> server.rkt` on the command line. However, this also launches the server, 
> which I usually do want to, but not always. So is there a way to run just 
> the type checker -- plus all the compile-time stuff that needs to happen 
> for this -- without anything else? The best I have managed is to put the 
> most time-consuming commands that I run into `(module+ main ...)`, but that 
> still does more than than just run the type checker. 
> > 
> > Secondly, is it possible to somehow speed up subsequent type checks by 
> caching something before? 
> > 
> > Cheers, 
> > Marc 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/b8922e9a-524f-4c2d-b716-c857914e7107%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/92d2cf1b-da1b-4d7f-89ce-8429d07ee9e9%40googlegroups.com.


Re: [racket-users] How do I just run the type checker?

2020-02-21 Thread Sam Tobin-Hochstadt
If you compile the file with `raco make server.rkt` then it will run
the type checker as part of compilation. Furthermore, it will run
faster the next time since it won't have to re-compile.

Sam

On Fri, Feb 21, 2020 at 12:13 PM Marc Kaufmann
 wrote:
>
> Hi,
>
> the way I currently check my web server is by simply running `racket 
> server.rkt` on the command line. However, this also launches the server, 
> which I usually do want to, but not always. So is there a way to run just the 
> type checker -- plus all the compile-time stuff that needs to happen for this 
> -- without anything else? The best I have managed is to put the most 
> time-consuming commands that I run into `(module+ main ...)`, but that still 
> does more than than just run the type checker.
>
> Secondly, is it possible to somehow speed up subsequent type checks by 
> caching something before?
>
> Cheers,
> Marc
>
> --
> 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/b8922e9a-524f-4c2d-b716-c857914e7107%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/CAK%3DHD%2BapBjywcVuDQYqQgSdeYu2R%2BKR3nyGW8yp2ku-fLzGajA%40mail.gmail.com.


[racket-users] Re: xrepl ,require-reloadable and ,require

2020-02-21 Thread Marc Kaufmann
Hi,

I'm hitting the same issue again, except that now that I use Typed Racket, 
and after I do the 

> ,rr "code.rkt"
> ,r "code.rkt"

dance, if I `provide` a new function in code.rkt, then it complains that it 
is missing type for the identifier, and says that I should consider using 
`require/typed` to import it. But code.rkt is #lang typed/racket, and I 
don't want to specify every type again! 

So 

1. how can I get Typed Racket to reload a file (I started it with `racket 
-I typed/racket`)
2. is there a way to avoid the Step 1: > ,rr "code.rkt" Step 2: > ,r 
"code.rkt" dance even for standard Racket?

Or what workflow do people use to reload files quickly (that does not 
depend on Emacs/Racket-mode)?

Cheers,
Marc
On Tuesday, October 8, 2019 at 1:32:20 PM UTC+2, Marc Kaufmann wrote:
>
> Hi,
>
> according to the docs (
> https://docs.racket-lang.org/xrepl/index.html#%28xrepl._require-reloadable%29)
>  
> I would have assumed that when I do 
>
> > ,require-reloadable "code.rkt"
>
> that I can use whatever "code.rkt" provides, the same way as when I do
>
> > ,require "code.rkt"
>
> However, when I do just the ,require-reloadable I have to follow it up 
> with a simple ,require for the provides to be available. Example: if code 
> has (provide my-function), then I have (where ,rr is the short-form for 
> ,require-reloadable and ,r for ,require):
>
> > ,rr "code.rkt"
> > (my-function args)
> ; my-function: undefined;
> ...
> > ,r "code.rkt"
> > (my-function args)
> ; Works fine, and seems like I can reload it afterwards
>
> Is this how it should be - and if so, why? Might be worth pointing out in 
> the docs if this behavior is expected, as I kept closing and restarting the 
> repl to reload my changes since I couldn't get ,require-reloadable to work.
>
> Cheers,
> Marc
>

-- 
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/13ef69a3-cf22-40b5-8b74-5a3c30b815d2%40googlegroups.com.


[racket-users] How do I just run the type checker?

2020-02-21 Thread Marc Kaufmann
Hi,

the way I currently check my web server is by simply running `racket 
server.rkt` on the command line. However, this also launches the server, 
which I usually do want to, but not always. So is there a way to run just 
the type checker -- plus all the compile-time stuff that needs to happen 
for this -- without anything else? The best I have managed is to put the 
most time-consuming commands that I run into `(module+ main ...)`, but that 
still does more than than just run the type checker. 

Secondly, is it possible to somehow speed up subsequent type checks by 
caching something before?

Cheers,
Marc

-- 
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/b8922e9a-524f-4c2d-b716-c857914e7107%40googlegroups.com.


[racket-users] Megaparsack and where errors happen

2020-02-21 Thread Matt Jadud
Hi all,

This might be a Lexi question, but perhaps someone else will have some
insight as well.

I'm wrestling with how to get errors to propagate down in megaparsack. For
example:

(define convert/p
  (do (string/p "convert")
 ...
  [assigns ← (many/p #:min 0
 assignment-statement/p
 )]
 ...
  (pure ...)))

(Assume I have a bunch of other parsing bits around the call to
`assignment-statement/p`.)

Currently, if I have a malformed assignment statement, the error is at the
top level of `convert`. `convert/p` is part of a backtracking conditional:

(define conversion/p
  (do
[result ← (many/p (or/p (try/p base-type/p)
(try/p convert/p)
(try/p chain/p)
)
  #:sep space0+/p
  )]
eof/p
(pure result)))

What should I do to get the error to report/fail down the parse tree, as
opposed to the top? I would rather know that there's something wrong down
in my assignment statement, as opposed to getting an error that "c" was
unexpected (because the entire conversion/p failed on account of an error
somewhere down inside).

I need to give the docs a more careful read, but I thought I'd ask, as it
seems both simple and, given the nature of the parsing tools, possibly
subtle.

Many thanks,
Matt

-- 
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/CAAGM45761tRo%2Bj0Rh078ngriYiMDum%3DyDyRgwQ1LLiuPZDFj6A%40mail.gmail.com.