Re: [racket-users] Reflecting on context arity

2020-03-27 Thread Ben Greenman
procedure-result-arity is very limited

if you can find a way to call `f` once, though, you could assume that
its result arity never changes

-- 
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/CAFUu9R6YDx9%2BF27dHW3N1P%3DMK_UuzfrWqo01kigM4fBKxxFXUA%40mail.gmail.com.


[racket-users] Reflecting on context arity

2020-03-27 Thread William J. Bowman
I'm trying to write a generalization of map that supports multiple return
values:

(define (map-n n f ls . lss)
  (if (empty? ls)
  (apply values (build-list n (lambda _ '(
  (call-with-values
   (thunk (apply f (car ls) (map car lss)))
   (lambda vs
 (call-with-values
  (thunk (apply map-n n f (cdr ls) (map cdr lss)))
  (lambda lss
(apply
 values
 (map cons vs lss

This version works fine, but, tediously, requires I specify how many return
values.
This is annoying, since surely the context knows how many values it expects:

> (let/ec escape
(let-values ([(a b c)
  (let/cc k
(escape (procedure-arity k)))])
  'meow))
> (arity-at-least 0)

Oh, I guess not.
Well that's fine, because surely I can reflect on `f`'s result arity:

> (procedure-result-arity (lambda (x) (values 'a 'b 'c)))
> #f

Welp.

So, uh, can I haz a current-context-arity please?

-- 
William J. Bowman

-- 
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/20200328002810.GN31619%40williamjbowman.com.


Re: [racket-users] Embedding Racket CS

2020-03-27 Thread Matthew Flatt
At Fri, 27 Mar 2020 15:48:13 -0700 (PDT), zeRusski wrote:
> How I might go about embedding Racket CS

The current development version (as reflected by snapshot builds) now
has support and documentation for that:

 https://www.cs.utah.edu/plt/snapshots/current/doc/inside/cs-embedding.html

Of course, let me know if you run into any problems.


Matthew

-- 
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/5e7e83f2.1c69fb81.a553d.d5f4SMTPIN_ADDED_MISSING%40gmr-mx.google.com.


[racket-users] Embedding Racket CS

2020-03-27 Thread zeRusski
How I might go about embedding Racket CS in a fairly big C codebase, about 
100KLOC big. It is exceptionally well written C authored by people who knew 
what they were doing. I am sadly not one such person, so I'd rather not 
muddy things with my exceptionally terrible C. C code will be driving the 
whole application, which means it'll be the one to call into Racket. Since 
I'd rather not re-implement the whole thing in Racket I'd probably have it 
call back into C for the things implemented there, so I'll have to program 
Racket bindings for at least the things I care in the C library. That's the 
task at hand.

I managed to embed Gambit so I can now have my nested call bonanza: C 
initializes Scheme, invokes Scheme procedures some of which call back into 
C etc. Gambit makes it mostly straightforward. I can certainly make do with 
Gambit, but it'd be nice to have access to Racket batteries, its macro 
bazooka and, you know, actual documentation, so I am eager to try. I 
imagine it'll be quite the workout with CS. I am specifically interested in 
doing this with Chez version, not the C API of the main system, unless our 
plan is to offer the same FFI in Racket CS.

Looking at racket/src/cs/Makefile it builds racket.so, which I suppose I 
can link. It wouldn't offer anything in terms of C FFI yet, right? But I 
bet it links Chez. I wonder if I could lean on its C API which Chez docs 
make out to be nice enough. I could maybe wrap the C API I care about in a 
Chez library, compile and link it, then compile and load Racket user code 
that calls the wrapper compiled from Scheme? Would that be hard? How chummy 
is Racket with Chez, really? Is indirection through Chez the way to go atm?

Is there a more straightforward way to embed Racket and have it as an 
extension language?

Have I wondered into "keep out unless Matthew" territory?

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/156514ed-cae3-4cb4-8768-97be8c88c16c%40googlegroups.com.


[racket-users] Single Stepping?

2020-03-27 Thread Nicholas Papadonis
Is there documentation on single stepping in Racket?  I.e. setting a breakpoint 
and single stepping evaluation of expressions from there?

I found:
https://docs.racket-lang.org/stepper/index.html

however, the documentation is lacking this info.

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/462E3800-C54F-4E7C-A3BD-A1D141D4B9D8%40gmail.com.


[racket-users] UDP networking issue

2020-03-27 Thread David Storrs
This isn't a Racket question per se, but I'm hoping someone here will
have a suggestion.  We're working on NAT traversal, it's failing to
connect, and we aren't clear why.

On hostname Alice on the LAN:

(define s (udp-open-socket))
(udp-bind! s #f 3)
(udp-send-to s "18.218.67.59" 54545 #"hi")


Over on the EC2 instance at 18.218.67.59:54545:

(define s (udp-open-socket))
(udp-bind! s #f 54545)
(define buffer (make-bytes 50))
(udp-receive! s buffer)
Bytes received: 2
Source IP:  "76.127.206.145"
Source port:  3

This shouldn't be the case.  Alice has a socket bound to 3 on that
local machine, but when the message is sent to the router, the router
should choose a new external port number.  That's what this particular
router has done in the past and we aren't sure why that would have
changed.  Still, it wouldn't be an issue except that it's also not
accepting traffic as expected.  More on that below.

This router uses (used to use, since everything is uncertain now)
symmetric NAT, so it will only forward traffic from address X back to
Alice if she had previously sent traffic to address X.  (As opposed
to, e.g. full cone NAT where any traffic arriving at the port would be
forwarded and Alice could sort out what to do with it.)  The problem
is that traffic isn't being forwarded even when it should be.
Demonstration follows, using Alice and Bob (two instances on our LAN)
and the EC2 server from above.  We are deliberately forcing everything
to use the public IP instead of going across the local network.

Alice and Bob hold a continuous connection to EC2 server.
The router's IP is 76.127.206.145, which I'll type as R for
convenience.  R:4 therefore means 76.127.206.145, port 4.

Alice -> server:  I want to talk to Bob
server -> Alice: He's connected to me from R:4
Alice -> R:4 ping

[Router should note that Alice tried to talk to R:4 and shoul
start accepting traffic for her from that address.  Message will not
be received by Bob because he has not previously talked to Alice.]

server -> Bob: Alice wants to talk to you. She's at R:3
Bob -> R:3 ping

[Router should note that Bob tried to talk to R:3 and should start
accepting traffic for him from that address.  Message should be
received by Alice, since she already had the mapping set up to listen
for Bob's messages]

Alice -> R:4 ping

[Message should be received by Bob, since he was already listening for Alice]


That's normal STUN-based NAT traversal, and we had it working until
recently.  Now it's failing and we're unsure what has changed that
would affect it.

Then we get to our next issue, which is that the router is not
choosing different ports for outbound connections to different
machines.  In the past, what we've seen is this:

On Alice:

(define s (udp-open-socket))
(udp-bind! s #f 3)
(udp-send-to s "18.218.67.59" 54545 #"hi")  ; EC2 server, instance #1
(udp-send-to s "18.218.67.59" 63212 #"hi")  ; EC2 server, instance #2

The instance running at 54545 used to see the message as coming from
an arbitrary remote port, e.g., 41378.
The instance running at 63212 used to see the message as coming from a
  different remote port, e.g., 41379.
Now, both instances see the message as coming from port 3.

When we were seeing different external ports we could use the
difference between them to make a prediction about what our next
outbound UDP port would be and leverage that into connecting despite
having symmetric NATs at both ends of the connection (which STUN will
not handle).  Unfortunately, now both servers are reporting the same
port number:  3.

To summarize, we have two separate issues that are probably related:

1) The router is re-using the local port as the external port
2) It's not accepting traffic from an address that has already been
sent to from that port

We're pretty stumped here and could use a hint.  Anyone have thoughts
on where to look?
(udp-bind! s 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKoc28kfZAOo9TLmonTL8Go%2BBYbbBFBFMv5WW_uA7AP9pxQ%40mail.gmail.com.


Re: [racket-users] How to find source file loaded by/relevant for (require )?

2020-03-27 Thread Alexis King
I recommend Ryan Culpepper’s whereis package: 
https://docs.racket-lang.org/whereis/index.html 
 It provides both a 
programmatic interface and a raco command.

Alexis

> On Mar 27, 2020, at 03:56, Marc Kaufmann  wrote:
> 
> Hi,
> 
> I am trying to set up vim such that it jumps to the correct source file when 
> I see a `(require some-module)`. With packages that I have installed myself, 
> I have managed to do so (80% solution), since they get installed in 
> $HOME/.racket//pkgs. However, I can't quite figure out where all the 
> things are. Some are in 
> /usr/share/racket/pkgs/-lib/, but 
> others like racket/match seem to be in /usr/share/racket/collects/... . Are 
> there any other places for the core modules?
> 
> Rather than me trying to do something error-prone, is there a Racket function 
> that I can call on  that returns the right path on my machine? 
> That way I don't write stupid error-prone regexes.
> 
> 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/DB1F4C09-837E-4586-BB0D-272AB14FCD63%40gmail.com.


[racket-users] How to find source file loaded by/relevant for (require )?

2020-03-27 Thread Marc Kaufmann
Hi,

I am trying to set up vim such that it jumps to the correct source file 
when I see a `(require some-module)`. With packages that I have installed 
myself, I have managed to do so (80% solution), since they get installed in 
$HOME/.racket//pkgs. However, I can't quite figure out where all 
the things are. Some are in 
/usr/share/racket/pkgs/-lib/, but 
others like racket/match seem to be in /usr/share/racket/collects/... . Are 
there any other places for the core modules?

Rather than me trying to do something error-prone, is there a Racket 
function that I can call on  that returns the right path on my 
machine? That way I don't write stupid error-prone regexes.

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/2f82bba5-bf2b-4e1e-8d45-5e49b27a3713%40googlegroups.com.