Re: [racket-users] Re: Confusion with udp-receive!

2019-09-26 Thread David Storrs
On Wed, Sep 25, 2019 at 8:16 PM David Storrs  wrote:
>
> On Wed, Sep 25, 2019 at 7:45 PM Alex Harsanyi  wrote:
> >
> > Is there any tunneling involved for connecting to your AWS instance?
> >
> > There is only one copy of the source port in an IP+UDP datagram, and this 
> > needs to be whatever the router is using for NAT, otherwise it would not be 
> > able to route replies back to your machine on the local network.  If you 
> > have some kind of tunneling set up to access the AWS servers, the router 
> > will wrap the original UDP packet into another UDP packet with its own 
> > source port, leaving the original source port unchanged.
>
> I'll have to check.

Okay, we checked and there is definitely no tunneling going on.

Does anyone have any further thoughts on this?
>
> >
> > You could also run tcpdump on your AWS server and dump the entire contents 
> > of the packet to see what the server actually receives.
>
> Did that, and it's getting the 25890 port (the one for my local
> machine instead of the router).
>
> >
> > Alex.
> >
> > On Thursday, September 26, 2019 at 12:49:51 AM UTC+8, David Storrs wrote:
> >>
> >> We (my business partner and I) ran tcpdump on the router and
> >> determined that no, it is not using the local port.  At first it bound
> >> to 65395 and then after we stopped/started the process it bound to a
> >> different port (49428) as expected.
> >>
> >> After a bit of digging in the racket source code I note that the
> >> various UDP functions are an FFI into librktio.  This leaves me with
> >> two questions:
> >>
> >> 1) Is it possible that there is a bug in the underlying C code?
> >>
> >> 2) Why does Racket use a hand-rolled io library instead of a more
> >> standard net stack element?  Is it for portability or...?
> >>
> >> On Wed, Sep 25, 2019 at 9:28 AM David Storrs  wrote:
> >> >
> >> >
> >> >
> >> > On Wed, Sep 25, 2019, 3:16 AM Alex Harsanyi  wrote:
> >> >>
> >> >> Do you know what port the router is using for NAT?  Are you sure that 
> >> >> the router is not simply choosing the same port, so 25890 is both your 
> >> >> local port and the port used by the router?
> >> >
> >> >
> >> > I haven't yet 100% ruled it out, but it doesn't look like it. I tried 
> >> > sending traffic to :25890 and it was not received.  It's 
> >> > possible that the port went stale and was released before my sending 
> >> > went out, but that seems unlikely, as it should persist for seconds or 
> >> > tens of seconds.My next step is to try again with a flood ping, just to 
> >> > be sure.
> >> >
> >> > Regards, it really shouldn't be doing that. If so, it's leaking 
> >> > information about the inner network to the outside, and that's not what 
> >> > I'd expect from the latest version of the FOSS OpenWRT.
> >> >
> >> >
> >> >>
> >> >> Alex.
> >> >>
> >> >> On Wednesday, September 25, 2019 at 1:08:16 PM UTC+8, David Storrs 
> >> >> wrote:
> >> >>>
> >> >>> udp-receive! is giving me unexpected results when my local machine ->
> >> >>> router -> server shows the UDP port of the process running on the
> >> >>> local machine instead of the one from the router.  I'm not sure how to
> >> >>> get the router's port instead.
> >> >>>
> >> >>>
> >> >>> The AWS server does this:
> >> >>>   (define-values (len senders-host senders-port) (udp-receive! socket 
> >> >>> buffer))
> >> >>>
> >> >>> What I'm actually getting is:
> >> >>>
> >> >>> senders-host:  
> >> >>> senders-port: 25890 ; this is the UDP port bound by the process on the
> >> >>> local machine
> >> >>>
> >> >>> What I'm expecting is:
> >> >>>
> >> >>> senders-host:  
> >> >>> senders-port:   >> >>> message from my machine to the AWS server>
> >> >>>
> >> >>> I've been digging through the  RFCs for UDP and Traditional NAT
> >> >>> (https://www.ietf.org/rfc/rfc768.txt and
> >> >>> https://www.ietf.org/rfc/rfc3022.txt) to make sure that I haven't
> >> >>> randomly gotten confused about how routers work but it seems to be
> >> >>> what I recall: The local machine sends to the router using the port
> >> >>> number 25890, the router rewrites it to an arbitrary port number
> >> >>> chosen on the fly, the AWS server sees the router's assigned port and
> >> >>> not 25890.
> >> >>>
> >> >>> What am I missing here?  I'm sure it's something embarrassingly 
> >> >>> obvious.
> >> >>>
> >> >>>
> >> >>>
> >> >>> Simplified form of code for reference:
> >> >>>
> >> >>> ---
> >> >>> shared code
> >> >>> ---
> >> >>> (struct Message (message-id attributes) #:prefab)
> >> >>> (struct Binding-Request  Message () #:prefab)
> >> >>> (struct Binding-Success-Response Message () #:prefab)
> >> >>> (struct transport-address (ip port) #:prefab)
> >> >>>
> >> >>> (define (write-to-bytes v)
> >> >>>   (define out (open-output-bytes))
> >> >>>   (write v out)
> >> >>>   (get-output-bytes out))
> >> >>>
> >> >>> ---
> >> >>> local machine:
> >> >>> ---
> >> >>> (define socket (udp-open-socket #f #f))

Re: [racket-users] Testing Servlets: exceptions not raised/passed through; how to pass extra arguments to tested servlet

2019-09-26 Thread George Neuner



On 9/26/2019 5:45 AM, Marc Kaufmann wrote:
Thanks for clearing this up. If I understand correctly, the following 
happens:


- the servlet raises an exception
- this is caught by the default exception handler
- it prints the traceback and exception message to standard output 
which I see (and which made me realize an exception had been raised), 
and it passes the response to the servlet-tester. However, the 
exception didn't bubble up to check-not-exn


Since I can't turn off the exception handling of the servlets, I have 
to look at the output to find that an exception was thrown. Could I 
pass a different exception-handler to the test-servlet, which would 
return something easier (and more robust) to check whether an 
exception was thrown or not? Or should I bundle the servlet into a 
lambda for this, and have an exception-handler in that lambda that 
simply outputs "exception-raised" or some such? Otherwise I can of 
course parse the output, but that seems a little more error-prone.


I vector every URL through a common dispatch routine that catches 
exceptions from the handlers and sends proper errors back to the 
client.   Of course this means I (you) can't use the ready-made dispatch 
machinery provided by web-server.


I wrote my own dispatcher routine, but there may be a way to do it 
working with web-server.  I was under some time constraints when I did 
this so I didn't have the opportunity to delve into it too deeply.  And 
once it worked, inertia took over and I reused the code. 


YMMV,
George



--
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/ad3777ea-0aa9-c28b-aac2-e0e0c62886e9%40comcast.net.


Re: [racket-users] raco exe & distribute, and namespace-require'ing a module: missing racket/base?

2019-09-26 Thread Matthew Flatt
At Tue, 24 Sep 2019 22:37:41 -0700 (PDT), Jesse Alama wrote:
> This works for making a standalone executable that can exectute foo 
> programs specified on the command line, but doesn't work for a REPL. The 
> difficulty seems to be the `namespace-require` part of `run-repl`, defined 
> like this:
> 
> 
> (define (run-repl)
>   (parameterize ([current-namespace (make-base-empty-namespace)])
> (namespace-require 'foo/expander)
> (read-eval-print-loop)))
> 
> 
> When I invoke the executable with no arguments, `run-repl` gets called. But 
> this leads to:
> 
> 
> standard-module-name-resolver: collection not found
>   for module path: racket/base/lang/reader
>   collection: "racket/base/lang"
> 

The problem is that `racket/base` is declared only in the original
namespace. When you create a fresh namespace, then it gets a fresh
registry, and `racket/base` is not in that registry.

Really, that goes for `foo/expander`. It's not so much that you want to
refer to `racket/base` as `foo/expander`. While `++lang foo` should
make `foo/expander` be in the original namespace's registry (assuming
that the `foo` language refers to it), it won't be in the fresh
namespace's registry.

The solution is to attach the module declaration from the original
namespace to the new namespace.

Here's an example to demonstrate, assuming that the "foo" directory is
installed as a package. The `foo` language here supports just literals
and addition.

;; 
;; foo/main.rkt
#lang racket/base

(provide #%app
 #%datum
 #%module-begin
 #%top-interaction
 +)

(module reader syntax/module-reader
  foo)

;; 
;; repl.rkt
#lang racket/base
(require racket/cmdline
 ;; Ensure that `foo` is here to attach
 (only-in foo))

(command-line
 #:args
 ([file #f])
 (cond
   [(not file)
(define ns (make-base-empty-namespace))
(namespace-attach-module (current-namespace) 'foo ns)
(current-namespace ns)
(namespace-require 'foo)
(read-eval-print-loop)]
   [else
(dynamic-require file #f)]))

;; 
;; Command line
raco exe ++lang foo repl.rkt
raco dist repl-dist repl

-- 
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/5d8cbf24.1c69fb81.f4bd9.0e12SMTPIN_ADDED_MISSING%40gmr-mx.google.com.


Re: [racket-users] handin: how to forbid the use of a certain function

2019-09-26 Thread Matthew Flatt
At Thu, 26 Sep 2019 00:46:23 +, "'Wayne Harris' via Racket Users" wrote:
> I think my message below neither asked any question nor did it contain the 
> adequate politeness which I so much think every e-mail should have.

I don't see any problem with your message. It's more that the handin
server doesn't get a lot of love. I know the little part that I use,
and not much else...

> > I haven't figured out how to forbid the use of length in submitted code.  
> I'm a little lost with
> >
> >   :language
> >   :with-submission-bindings
> >
> > I did understand
> >
> >   :requires
> >
> > so I'm able to let submissions use extra libraries, but I'd like to forbid, 
> say, length in '(special beginner) too.

There doesn't seem to be a simple way of disallowing the use of
`length`. Since `submission` is bound to the whole submission content,
you could have `pre:` action that reads and searches for the symbol
'length:

 #lang s-exp handin-server/checker
 (require racket/gui/base)

 (check: :language '(special beginner))

 (pre:
  (define (mentions-length? r)
(cond
  [(eq? r 'length) #t]
  [(pair? r) (or (mentions-length? (car r))
 (mentions-length? (cdr r)))]
  [else #f]))
  (define-values (defns interactions) (unpack-submission submission))
  (define p (open-input-text-editor defns))
  (parameterize ([read-accept-reader #t])
(let loop ()
  (define r (read p))
  (unless (eof-object? r)
(when (mentions-length? r)
  (error "length not allowed"))
(loop)

A more precise approach would be to expand the program and check
whether there's any identifier bound to `length` that was part of the
original program (as opposed to introduced by a macro), but that's
probably more than you need. Or, of course, you could have a language
that's like Beginner without `length`, but that's probably too much
trouble for your students to set up.

-- 
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/5d8cb591.1c69fb81.87275.160eSMTPIN_ADDED_MISSING%40gmr-mx.google.com.


Re: [racket-users] Testing Servlets: exceptions not raised/passed through; how to pass extra arguments to tested servlet

2019-09-26 Thread Marc Kaufmann
Ah yes, that's right. I did somehow (without really thinking about it,
admittedly) think that the exception would get returned with the response.
I did not realize that test-servlet sets up a server.

So for testing the functions, I just create the right requests and do a
check-* test. That should also work to see if dispatch-rules calls the
correct routes, right? Or does that require something from a running server
that I don't realize?

I'll probably need some time before I figure out which type of testing
belongs where, hopefully I'll get to it this weekend.

On Thu, Sep 26, 2019 at 1:22 PM Jay McCarthy  wrote:

> On Thu, Sep 26, 2019 at 5:46 AM Marc Kaufmann 
> wrote:
> >
> > Thanks for clearing this up. If I understand correctly, the following
> happens:
> >
> > - the servlet raises an exception
> > - this is caught by the default exception handler
> > - it prints the traceback and exception message to standard output which
> I see (and which made me realize an exception had been raised), and it
> passes the response to the servlet-tester. However, the exception didn't
> bubble up to check-not-exn
> >
> > Since I can't turn off the exception handling of the servlets, I have to
> look at the output to find that an exception was thrown. Could I pass a
> different exception-handler to the test-servlet, which would return
> something easier (and more robust) to check whether an exception was thrown
> or not? Or should I bundle the servlet into a lambda for this, and have an
> exception-handler in that lambda that simply outputs "exception-raised" or
> some such? Otherwise I can of course parse the output, but that seems a
> little more error-prone.
>
> I think you're thinking about this wrong. It is not that can't "turn
> off the exception handling" or that "the exception didn't bubble up".
> If you go to pkgs.racket-lang.org and there's an exception in the code
> on the server, do you expect the Racket exception to be thrown to
> Google Chrome where a `with-handlers` can catch it? Of course not.
> `make-servlet-tester` is literally a network client. It starts up a
> hidden server and connects to it.
>
> So, you need to ask what it is that you are trying to test...
>
> If you want to know if a certain Racket function throws an exception,
> then just test that function directly and use `check-not-exn`. That's
> what Rackunit, chk, and other libraries are for. In this case, you are
> testing a Racket function for its behavior: so you ask "Racket"
> questions, like "Are exceptions thrown?".
>
> If you want to know if your servlet returns certain pages, then use
> `make-servlet-tester` to inspect the pages that get generated. In this
> case, you are testing a Web app for its behavior: so you ask "Web"
> questions, like "Is the background of the page purple?".
>
> Jay
>

-- 
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/CAD7_NO5FYHcx-z0PVV2Nz7k%3DuRYrTUar5Fb3cDs657cJDWxa%3Dg%40mail.gmail.com.


Re: [racket-users] Testing Servlets: exceptions not raised/passed through; how to pass extra arguments to tested servlet

2019-09-26 Thread Jay McCarthy
On Thu, Sep 26, 2019 at 5:46 AM Marc Kaufmann  wrote:
>
> Thanks for clearing this up. If I understand correctly, the following happens:
>
> - the servlet raises an exception
> - this is caught by the default exception handler
> - it prints the traceback and exception message to standard output which I 
> see (and which made me realize an exception had been raised), and it passes 
> the response to the servlet-tester. However, the exception didn't bubble up 
> to check-not-exn
>
> Since I can't turn off the exception handling of the servlets, I have to look 
> at the output to find that an exception was thrown. Could I pass a different 
> exception-handler to the test-servlet, which would return something easier 
> (and more robust) to check whether an exception was thrown or not? Or should 
> I bundle the servlet into a lambda for this, and have an exception-handler in 
> that lambda that simply outputs "exception-raised" or some such? Otherwise I 
> can of course parse the output, but that seems a little more error-prone.

I think you're thinking about this wrong. It is not that can't "turn
off the exception handling" or that "the exception didn't bubble up".
If you go to pkgs.racket-lang.org and there's an exception in the code
on the server, do you expect the Racket exception to be thrown to
Google Chrome where a `with-handlers` can catch it? Of course not.
`make-servlet-tester` is literally a network client. It starts up a
hidden server and connects to it.

So, you need to ask what it is that you are trying to test...

If you want to know if a certain Racket function throws an exception,
then just test that function directly and use `check-not-exn`. That's
what Rackunit, chk, and other libraries are for. In this case, you are
testing a Racket function for its behavior: so you ask "Racket"
questions, like "Are exceptions thrown?".

If you want to know if your servlet returns certain pages, then use
`make-servlet-tester` to inspect the pages that get generated. In this
case, you are testing a Web app for its behavior: so you ask "Web"
questions, like "Is the background of the page purple?".

Jay

-- 
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/CAJYbDa%3D%3DfSxLKyUNXx60k4TLA112%3Dtg%3DANy1qcD3CwhaHU6%3Dbg%40mail.gmail.com.


Re: [racket-users] Announcing Stripe Integration

2019-09-26 Thread Neil Van Dyke

Sage, thank you, this is great kind of package for Racket.

--
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/ecfd5d30-3dbd-97d9-b0c3-7c217f48b894%40neilvandyke.org.


Re: [racket-users] Testing Servlets: exceptions not raised/passed through; how to pass extra arguments to tested servlet

2019-09-26 Thread Marc Kaufmann
Thanks for clearing this up. If I understand correctly, the following
happens:

- the servlet raises an exception
- this is caught by the default exception handler
- it prints the traceback and exception message to standard output which I
see (and which made me realize an exception had been raised), and it passes
the response to the servlet-tester. However, the exception didn't bubble up
to check-not-exn

Since I can't turn off the exception handling of the servlets, I have to
look at the output to find that an exception was thrown. Could I pass a
different exception-handler to the test-servlet, which would return
something easier (and more robust) to check whether an exception was thrown
or not? Or should I bundle the servlet into a lambda for this, and have an
exception-handler in that lambda that simply outputs "exception-raised" or
some such? Otherwise I can of course parse the output, but that seems a
little more error-prone.

Thanks

On Wed, Sep 25, 2019 at 4:29 PM Jay McCarthy  wrote:

> The output of `make-servlet-tester` returns the HTTP response object that
> the servlet returns. `make-servlet-tester` really makes a HTTP connection
> to your servlet and is checking the actual result that you sent back. If
> the servlet throws an exception, then probably you have the default
> exception handler which turns that into an HTML display. That HTML display
> would be returned and thus, there was no exception. In other words, it is
> not a sufficient test of what you want to check that no exception is
> thrown, you want to make sure a desirable page is returned.
>
> Jay
>
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
>
>
> On Tue, Sep 24, 2019 at 9:34 AM Marc Kaufmann 
> wrote:
>
>> Hi all,
>>
>> I have gone through https://docs.racket-lang.org/web-server/test.html to
>> finally stop manually checking whether I didn't introduce new bugs in one
>> of my servlets. I think that I have figured out most of the wrinkles for
>> this, except one.
>>
>> I run my tests via `raco test server.rkt`, and server.rkt has the
>> following structure:
>>
>> (require web-server/test web-server/servlet ...)
>>
>> (define (start request)
>>   (define-values (top-dispatch top-urls)
>> (dispatch-rules
>>   [("") home]
>>   [("login") #:method (or "post" "get") log-in]
>>   [("mp") #:method (or "post" "get") mp]
>>   ...
>>   ))
>>
>>   (top-dispatch request))
>>
>> (module+ main
>>   (serve/servlet start ...))
>>
>> (module+ test
>>
>>   (define (test-start-servlet)
>>
>> (define experiment-servlet-tester
>>   (make-servlet-tester start))
>>
>> ; Test all the routes. This only tests that they don't raise
>> exceptions
>> (define routes
>>   (list
>> '()   ; Tests "/"
>> '("/login")
>> '("/mp")
>> ))
>>
>> (for ([route routes])
>>   (check-not-exn (λ () (apply experiment-servlet-tester route
>>
>> (define matrix-servlet-tester
>>   (make-servlet-tester (λ (req)
>>   (matrix req #:h (hash 'mturk-id
>> "TESTER")
>>
>> (matrix-servlet-tester)
>>
>> (displayln "All pages render without exception"))
>>
>>   (test-start-servlet))
>>
>>
>> The meat of what is going on is in the test module at the end. I create a
>> servlet-tester for the start servlet, which uses a dispatcher, and since I
>> have a bunch of routes I go through them in a for-loop. However, even
>> though the "/login" route throws an exception, the (test-start-servlet)
>> code is happily marching on, checks the "/mp" route, and then prints "All
>> pages render without exception". And raco test tells me that all the tests
>> are passing!
>>
>> How do I know that there is an exn? Because it prints the following right
>> before the test results:
>>
>> Servlet (@ /372d34a3-df04-478f-8d84-94fb212725c2) exception:
>> >: contract violation
>>   expected: real?
>>   given: #
>>   argument position: 1st
>>   other arguments...:
>>0
>>
>>
>> So, what is going on here? Clearly test-servet does some exception
>> catching in between, yet it still prints it to the screen? How can I test
>> for this, since I want to know how many and which pages blow up?
>>
>> Also, when I want to test matrix at the end, I have to pass it an extra
>> argument. Is it the right way of passing in the argument by defining a new
>> servlet where I set the argument to some fixed value, as I do above via:
>>
>> (define matrix-servlet-tester
>>   (make-servlet-tester (λ (req)
>>   (matrix req #:h (hash 'mturk-id
>> "TESTER")
>>
>> It seems to work, but I am wondering if I can pass arguments directly to
>> `make-servlet-tester`, but I couldn't figure out how.
>>
>> Thanks,
>> 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 

[racket-users] Re: raco exe & distribute, and namespace-require'ing a module: missing racket/base?

2019-09-26 Thread Alex Harsanyi


On Wednesday, September 25, 2019 at 1:37:41 PM UTC+8, Jesse Alama wrote:
>
> I'm working on building a standalone executable for a #lang that can be 
> used in two ways:
>
> 1. foo awesome.foo: execute file awesome.foo, which is written in #lang foo
>
> 2. foo (no arguments): fire up a REPL. Expressions are to be written in 
> the foo language.
>
> I can get (1) to work, after wrestling with raco exe (using ++lang) and 
> raco distribute (using ++collects-copy). An invocation that works for me is:
>
> ### begin script snippet
>
> raco exe ++lang foo ++lang racket/base ++lang brag foo.rkt
>
> # copy the source code of foo into collects/foo
> mkdir -p collects/foo
>
> find . -mindepth 1 -maxdepth 1 -name '*.rkt' -exec cp {} collects/foo ';'
>
> raco distribute ++collects-copy collects dist foo
>
> ### end script snippet
>
> This works for making a standalone executable that can exectute foo 
> programs specified on the command line, but doesn't work for a REPL. The 
> difficulty seems to be the `namespace-require` part of `run-repl`, defined 
> like this:
>
> 
> (define (run-repl)
>   (parameterize ([current-namespace (make-base-empty-namespace)])
> (namespace-require 'foo/expander)
> (read-eval-print-loop)))
> 
>

This is a wild guess, but since no one replied, I would suggest two things 
to try:

1) try using `make-base-namespace` instead -- I am not sure what the 
difference is between "attached" and "attached + required", but sounds like 
`make-base-namespace` will require racket/base

2) try a compiled form:

(define (run-repl)
  (parameterize ([current-namespace (make-base-empty-namespace)])
(compile `(namespace-require `'foo/expander))
(read-eval-print-loop)))

Alex. 


> When I invoke the executable with no arguments, `run-repl` gets called. 
> But this leads to:
>
> 
> standard-module-name-resolver: collection not found
>   for module path: racket/base/lang/reader
>   collection: "racket/base/lang"
> 
>
> expander.rkt in foo is written in racket/base, so I suppose that's what 
> triggers the issue.
>
> My question, crudely put, is: How do I "embed" racket/base so that I can 
> use `namespace-require` as seen in `run-repl`? (I assume namespace-require 
> is what I need; if that's wrong, please do correct me.) It appears that 
> ++lang racket/base bit in raco exe isn't enough. A related question about 
> raco exe is: if racket/base isn't available, what *is* available?
>
>
>
>

-- 
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/0590b28c-2d3a-4245-a4da-c6deee8c53c3%40googlegroups.com.


[racket-users] Re: raco exe & distribute, and namespace-require'ing a module: missing racket/base?

2019-09-26 Thread Jesse Alama
An update to my command line REPL adventures:

I'm still unable to get a working REPL, even when adding more and more 
information to raco exe/distribute. Here's my latest attempt:

raco exe ++lang foo ++lang racket/base ++lang racket ++lang brag ++lib 
racket ++lib racket/base foo.rkt

I've even taken to copying the entire Racket collects directory (!) based 
on the idea that the built-in executable is potentially looking for all 
sorts of things. Thus, after my raco exe and raco distribute invocations, 
I've got a build directory that looks like this:

$ ls /tmp/dist/lib/plt/foo/collects
acks
db
file
json
openssl
racket
realm
setup
xml
compiler
dynext
info
launcher
pkg
raco
foo # my package; everything else is standard Racket
syntax
data
ffi
info-domain
net
planet
reader
s-exp
version

In other words, I'm not only embedding a bunch of stuff into the generated 
executable, but making a ton of source code available, too. This all looks 
terribly excessive, and probably it is, but I've thrown all this stuff in 
out of desperation because I'm trying to ensure that racket/base can be 
used as lang via `namespace-require`.  Nonetheless, I still get a 
module-not-found error:


instantiate: unknown module
  module name: #
  context...:
   raise-arguments-error
   namespace-module-instantiate!96
   for-loop
   for-loop
   run-module-instance!125
   do-dynamic-require5
   read*14
   thunk_11
   dynamic-wind
   default-load-handler
   standard-module-name-resolver
   module-path-index-resolve5
   perform-require!78
  
 /var/folders/rx/lzgw7dzs0fqc1c7q1bv790_hgn/T/tmp.FrRgf7Mu/foo.rkt:64:0: 
run-repl
   call-with-values
   body of '|#%mzc:foo(main)|


Any idea what might be going on?

On Wednesday, September 25, 2019 at 7:37:41 AM UTC+2, Jesse Alama wrote:
>
> I'm working on building a standalone executable for a #lang that can be 
> used in two ways:
>
> 1. foo awesome.foo: execute file awesome.foo, which is written in #lang foo
>
> 2. foo (no arguments): fire up a REPL. Expressions are to be written in 
> the foo language.
>
> I can get (1) to work, after wrestling with raco exe (using ++lang) and 
> raco distribute (using ++collects-copy). An invocation that works for me is:
>
> ### begin script snippet
>
> raco exe ++lang foo ++lang racket/base ++lang brag foo.rkt
>
> # copy the source code of foo into collects/foo
> mkdir -p collects/foo
>
> find . -mindepth 1 -maxdepth 1 -name '*.rkt' -exec cp {} collects/foo ';'
>
> raco distribute ++collects-copy collects dist foo
>
> ### end script snippet
>
> This works for making a standalone executable that can exectute foo 
> programs specified on the command line, but doesn't work for a REPL. The 
> difficulty seems to be the `namespace-require` part of `run-repl`, defined 
> like this:
>
> 
> (define (run-repl)
>   (parameterize ([current-namespace (make-base-empty-namespace)])
> (namespace-require 'foo/expander)
> (read-eval-print-loop)))
> 
>
> When I invoke the executable with no arguments, `run-repl` gets called. 
> But this leads to:
>
> 
> standard-module-name-resolver: collection not found
>   for module path: racket/base/lang/reader
>   collection: "racket/base/lang"
> 
>
> expander.rkt in foo is written in racket/base, so I suppose that's what 
> triggers the issue.
>
> My question, crudely put, is: How do I "embed" racket/base so that I can 
> use `namespace-require` as seen in `run-repl`? (I assume namespace-require 
> is what I need; if that's wrong, please do correct me.) It appears that 
> ++lang racket/base bit in raco exe isn't enough. A related question about 
> raco exe is: if racket/base isn't available, what *is* available?
>
>
>
>

-- 
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/10939b31-6967-4851-ac42-9b9241ae8efd%40googlegroups.com.