Re: [racket-users] Why is get-impure-port* slower than a system call to curl?

2020-09-16 Thread George Neuner



On 9/16/2020 5:59 PM, Alex Harsanyi wrote:
On Windows at least, "localhost" resolves to two IP addresses (in this 
order): "::1" (IPv6) and "127.0.0.1".  The Racket `tcp-connect` 
function will try the fist one first, and since you probably don't 
bind your web server to the IPv6 address, the connection times out, 
than `tcp-connect` tries the IPv4 one and succeeds.  This is  why 
using "localhost" is slower than using "127.0.0.1".


I know this because I have been caught by it as well :-)  My solution 
was to learn IpV6 and start my server on IPv6 :-)


 Perhaps curl and Chrome go straight for the IPv4 address.

As a test, try starting your web server on an IPv6 address (::1) and 
see if things improve.


Alex.


That's true - Windows tries IPv6 first - but it isn't the whole story 
here.  If IPv6 were the only cause, then disabling IPv6 should fix the 
problem ... but it doesn't always fix the problem.  On some Windows 
machines, name resolution by the local DNS client is just painfully slow 
[and no one knows exactly why].


Certainly Stephen should try either binding the server to ::1 or 
disabling IPv6 altogether ... but it's possible that neither of these 
options may solve his problem.


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/ba034951-9271-03fa-6d3d-e98879ba7792%40comcast.net.


[racket-users] Re: Why is get-impure-port* slower than a system call to curl?

2020-09-16 Thread George Neuner
On Wed, 16 Sep 2020 08:14:11 -0700, Stephen Foster
 wrote:

>Turns out it's largely a "my system thing": requests to "localhost" are
>slow, but 127.0.0.1 are fast.  On Chrome and curl, both were fast, which is
>why I assumed the slowdown was in some Racket package.  It's more likely a
>DNS issue.  (I have to use an unfamiliar Windows machine for game
>development; there's probably something misconfigured about the DNS.)

Slow "localhost" name resolution is a known issue with Windows.  

It's not a misconfiguration ... at least not in the conventional
sense.  Windows DNS client ignores the HOSTS file wrt "localhost" -
the loopback is hardcoded in the client.

Unfortunately the problem seems to strike randomly: many people never
see it, and no one really knows why it happens or what to do about it.
Flushing the DNS cache sometimes seems to help.

On Win7 or Win8, you could disable the DNS client and use the HOSTS
file exclusively, but Win10 doesn't allow to disable the DNS client
(or even to stop it via the GUI - it can be stopped briefly using the
command line service tool, but it will restart automagically after a
few minutes or if the machine is rebooted).

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/ua25mfl91f5slf8cju64hli557917mrssg%404ax.com.


Re: [racket-users] question about places and main thread gc

2020-09-13 Thread George Neuner


On 9/13/2020 4:12 PM, Nate Griswold wrote:
Sorry, i forgot to mention this would be interfacing on the main 
thread from c


does this still hold true? Like if a c call returns does it kill the 
places?


Nate


I'm not really sure what you are asking:  it sounds like you are wanting 
to embed Racket into a C program ... if that is the case, then the 
primary thread is in the C program and any/all Racket threads will be 
secondary.


I don't know that Racket's place API even works in an embedded 
scenario.  You certainly can create multiple threads within your C 
program and run Racket in them, but it's hard to share a Racket 
environment, and if you create a separate execution environment for each 
thread, then their operations will be independent of one another.


If you just call a Racket function from C, that function will be 
executed in the same thread as the caller, and it will return to the 
caller when it finishes.  Of course that function could have side 
effects such as signaling a separate Racket thread to terminate.


A lot depends on what you are trying to do and how you structure your 
solution.



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/c6d3915d-5c92-ea6a-bedd-5c31a540cc71%40comcast.net.


Re: [racket-users] question about places and main thread gc

2020-09-13 Thread George Neuner



On 9/13/2020 3:55 AM, Nate Griswold wrote:


I am making an app that basically spawns two racket places and i want 
to be able to communicate with them from c code.


Will gc happen in the two racket places if i don't keep the main 
thread (the one that spawned the places) running?


Exiting the main thread kills the process.  "dynamic"[1] places are (OS 
level) threads within the same process and they will die with it.  
[Technically the main thread is itself a place, but normally we don't 
use place  terminology when talking about the main thread unless there 
are other places involved.]


I was thinking about whether i should keep the main thread running and 
block on a stream read, sending it messages, or if i can only call 
into the main thread when i need something using racket/chezscheme 
apis. I guess it would be simpler to just talk directly to the main 
thread when i need to, which is why i'm asking. Otherwise i'm thinking 
of just using zeromq on the main thread.


You certainly can talk to any of the places individually ... but you do 
need the main thread to remain running (even if just waiting on some 
event) if you want dynamic places to continue running.



Now "distributed"[2,3] places are separate processes - you can start 
them and they will continue running regardless of what happens to the 
process that spawned them.



Nate


Hope this helps,
George

[1]  https://docs.racket-lang.org/reference/places.html
[2]  https://docs.racket-lang.org/distributed-places/index.html
[3]  https://pkgd.racket-lang.org/pkgn/search?q=loci

--
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/48c3d0ce-50ed-6ad3-7e03-470335c98474%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-10 Thread George Neuner




On 9/10/2020 10:06 AM, Philip McGrath wrote:
Also, this is happening over encrypted HTTPS: no one is sniffing the 
User-Agent header.


While it may not be the issue here, you need to understand that 
appliance firewalls CAN and routinely DO examine data inside encrypted 
connections.


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/b7faf924-5d4a-0d21-db6c-dee1afde8c61%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-10 Thread George Neuner



On 9/10/2020 7:37 AM, Hendrik Boom wrote:

On Thu, Sep 10, 2020 at 12:49:25AM -0400, George Neuner wrote:
> 
> I don't know if DrRacket even sends a "user agent" string.


If DrRacket can send a user agent string, so can malware.

So it's not really reliable to filter on the user agent string.

-- hendrik


Of course ... any HTTP request can forge a user agent string:  most 
browsers allow you to change it, and so do some HTTP aware 
applications.  E.g., there is a plugin for Firefox that changes it on 
the fly based on the URL - use cases involve things like Google image 
search behaving differently for Chrome vs non-Chrome users, and 
Microsoft sites behaving differently for non-Windows users.


My point is that there may be something unseen - probably a firewall - 
blocking the DrRacket request but not blocking requests from the known 
browser.  If it isn't some software installed on the machine itself, it 
likely is an IT appliance guarding the whole network. Firewall 
appliances are NAT routers: they can look inside even encrypted 
connections to examine protocols being used and the raw data passing 
through.


Based on the error from Shriram's message, it looks like DrRacket is 
successfully calling out but doesn't like/understand the response ... 
which would tend to eliminate Windows built-in firewall as a suspect [it 
doesn't do protocol inspection].  It still could be other AV/firewall 
software on the machine, or something upstream in the network that his 
student is unaware of.


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/8a1628af-b647-5272-1c9a-da347b604091%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-09 Thread George Neuner



On 9/9/2020 10:05 PM, Shriram Krishnamurthi wrote:
Thank you. Can you imagine why the proxy would affect DrRacket but not 
the Web browser?


DrRacket and the browser can be configured independently ... at least 
for a known proxy.    DrRacket's setting is in preferences under 
"browser".  However, if your student is on campus (or at work?), he/she 
may be behind an upstream system-wide firewall or proxy which is unknown.


Commercial firewalls can read request headers and pass/fail based on the 
"user agent" string so as to allow known browsers and other vetted 
applications to operate while rejecting requests from unvetted applications.


I don't know if DrRacket even sends a "user agent" string.

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/40d69d4d-81cc-525f-5bc2-b22a8f6eb50f%40comcast.net.


Re: [racket-users] package manager woes on Windows 10?

2020-09-09 Thread George Neuner



From the error message, it looks like a firewall/proxy issue.

It definitely is not the package itself:  I'm still on Racket 7.7, but 
it works for me.  I tried both with 64 and 32 bit BC on Win10 1909 - the 
package and its dependencies install for me without errors  [but I don't 
know how to test the install  8-)]


George


On 9/9/2020 9:00 PM, Shriram Krishnamurthi wrote:
I have a student using Racket 7.8 on Windows 10 (v. 1909) who can't 
get a package to install that he needs to do homework. Does anyone 
else recognize this phenomenon? Thanks for any advice — none of us has 
Windows so we can't even reproduce this. He has restarted DrRacket, 
confirmed he can connect to the repo via his browser, tried several 
times (so it's not intermittent network outage), confirmed he's 
copying-and-pasting the URL.


It's probably something obvious that I'm just not spotting. Extra eyes 
would be much appreciated given that the clock's ticking on his homework!


The repo in question is

https://github.com/shriram/mystery-languages/
https://github.com/shriram/mystery-languages.git


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/d856cb76-928f-3d69-d292-1a8f8b1e5240%40comcast.net.


Re: [racket-users] GUI zoom and normal-control-font

2020-08-19 Thread George Neuner

On 8/19/2020 1:37 PM, James Platt wrote:
> 
> On 8/18/2020 12:31 PM, James Platt wrote:

>> I'm looking at implementing a zoom contents (not zoom window) feature in a 
GUI with lots of elements and I'm wondering about the best way to do this.  Most, if 
not all, standard GUI widgets in Racket can be resized by changing the font size of 
their contents or label.   Then redraw the widget and you have the whole thing in a 
new size.  So zoom could be done by creating a function which handles each element 
individually but I would like a more general solution, if possible.  Most widgets use 
the value normal-control-font for their default but it doesn't look like this can be 
changed at present.  If there were a setter for normal-control-font, it looks like 
you could have a menu item change it, then recursively get the children of the frame 
it is attached to and redraw them.  Would this actually work? Is there a better way 
to do it?
> 
> If you can access (or render) the contents as a 'pict', then it be scaled somewhat arbitrarily (though a scaled version is not guaranteed to look good).

> https://docs.racket-lang.org/pict/Pict_Drawing_Adjusters.html
> 
> It is a form of BitBLT operation.  I would search the docs for "blt" or "blit" in addition to "scale" and "size".  Sorry I can't point you more directly to relevant functions:  I've done a lot of GUI programming, but, unfortunately, I know it from C++ using device contexts directly, not from using Racket's graphics.


If I understand correctly, I would do that like in the Stackoverflow post 
below.   Note the need for using the bitmap% version of the button label.   The 
advantage of this approach is that you can change the label dynamically with a 
send.  The drawback is that I would have to create a modified version of every 
widget.  I was just hoping for a solution which would not require so much 
customization of a standard Racket package.

https://stackoverflow.com/questions/48414363/how-to-change-the-color-of-text-in-a-racket-gui-button/48468797#48468797


Sorry, it was not clear to me that you wanted to resize widgets (child 
windows).  Typically when one speaks about a window's "content" they are 
referring to text or imagery drawn onto the window's backing bitmap.


Basically, you need to push a resize message to every child.  I'm not 
sure the best way to do that, but my first thought would be something 
involving panels (or panes).  When a panel gets resized, all its 
children are resized as well.

https://docs.racket-lang.org/gui/windowing-overview.html#%28part._containeroverview%29
https://docs.racket-lang.org/gui/panel_.html
https://docs.racket-lang.org/gui/pane_.html

The trick is that normally a panel would be sized relative to its 
parent.  To effect a "zoom" you would have to override that behavior so 
at least the (Z-stack) bottom panel can be made larger than the 
application window's viewing area.


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/65bbe973-c309-1f92-620a-76d4708f32c7%40comcast.net.


Re: [racket-users] GUI zoom and normal-control-font

2020-08-18 Thread George Neuner



On 8/18/2020 12:31 PM, James Platt wrote:

I'm looking at implementing a zoom contents (not zoom window) feature in a GUI 
with lots of elements and I'm wondering about the best way to do this.  Most, 
if not all, standard GUI widgets in Racket can be resized by changing the font 
size of their contents or label.   Then redraw the widget and you have the 
whole thing in a new size.  So zoom could be done by creating a function which 
handles each element individually but I would like a more general solution, if 
possible.  Most widgets use the value normal-control-font for their default but 
it doesn't look like this can be changed at present.  If there were a setter 
for normal-control-font, it looks like you could have a menu item change it, 
then recursively get the children of the frame it is attached to and redraw 
them.  Would this actually work? Is there a better way to do it?


If you can access (or render) the contents as a 'pict', then it be 
scaled somewhat arbitrarily (though a scaled version is not guaranteed 
to look good).

https://docs.racket-lang.org/pict/Pict_Drawing_Adjusters.html

It is a form of BitBLT operation.  I would search the docs for "blt" or 
"blit" in addition to "scale" and "size".  Sorry I can't point you more 
directly to relevant functions:  I've done a lot of GUI programming, 
but, unfortunately, I know it from C++ using device contexts directly, 
not from using Racket's graphics.


Hope this helps,
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/c9f51d94-3b70-83fc-14b8-f858fcfed32c%40comcast.net.


Re: [racket-users] Strange performance behavior

2020-08-08 Thread George Neuner



On 8/9/2020 1:20 AM, wanp...@gmail.com wrote:


One more thing which bothers me is if I put a (collect-garbage) in 
front of the testing, I got gc time: 0 if not I got gc time: 9.
Why can't 1 gc reclaim all memory during execution while it can before 
executes?


Those numbers show *time* spent working, not what was done.  If you 
collect before running your program, at that point little has been 
allocated, and little or nothing has been freed, and so the GC has 
little to do ... hence it spends '0' time doing it  [zero meaning below 
the resolution of the computer's clock].  Once your program starts 
running, memory is being allocated and freed, and so a GC in the middle 
or at the end has much more work to do.


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/8499ad0d-a5a7-424b-1027-df25b255bc61%40comcast.net.


Re: [racket-users] Re: Strange performance behavior

2020-08-08 Thread George Neuner



On 8/8/2020 9:45 AM, Matthew Flatt wrote:

At Sat, 8 Aug 2020 03:32:57 -0400, George Neuner wrote:
> 
> On 8/8/2020 1:55 AM, Sorawee Porncharoenwase wrote:
> > I even saw people doing `collect-garbage` three times, just to be safe 
> > I guess. And yet theoretically it's not guaranteed that things will be 
> > claimed back properly.

> >
> > Honestly, there should be a function that does this `collect-garbage` 
> > until fixpoint or something, so that we don't need to perform this ... 
> > uh  ritual.
> 
> There may be no documented guarantee, but I *think* the implementation 
> assures that 2 collections, back-to-back, are sufficient to reclaim all 
> objects that were garbage at the beginning of the 1st collection.  At 
> least for BC Racket.


In the absence of finalization, then a single `collect-garbage` would
always be sufficient, and a second `collect-garage` would have no
effect.

For the specific benchmark in this thread as run in plain `racket`, I
think a single `collect-garbage` is sufficient, and that's what I
normally do.

But finalization complicates the picture --- especially finalization
via `register-finalizer`, since the finalizers run in a background
thread. Because of that background thread, in a context that uses a
library like `racket/gui`, I sometimes use repetitions of

  (collect-garbage)
  (sync (system-idle-evt))


Yes.  But, at least if you use the generational collector, you know that 
once an object has been finalized it will be collected the next time the 
GC looks at it:  i.e. at or before the next major collection.


But there is the issue of incremental GC.  Incremental complicates the 
notion of the GC "cycle" because it interleaves GC with execution of the 
mutator and splits a single "full" collection into many partial 
collections.  I don't know enough about Racket's implementation to say 
whether objects that become garbage *during* a GC cycle can be collected 
in that same cycle, or whether they must wait for the next.



But in truth these details should not matter much except for debugging, 
benchmarking, or for programs that must operate in limited memory.




It's difficult to know whether the libraries that you use rely on
finalization. Also, finalization means that there is no simple number
of `(collect-garbage)`s and `(sync (system-idle-evt))`s that are needed
to really collect everything that could potentially be collected;
finalization chains can require an arbitrary number of
`(collect-garbage)` cycles to clean up (so libraries should avoid
finalization chains!). The collector is precise and the compiler is
safe-for-space, so you can reason about the reachability of an
individual value, but reasoning precisely about overall memory use
across many libraries is difficult or impossible.

Using an extra `(collect-garbage)` is not ideal and often not
necessary, but it's a reasonable just-to-be-sure habit.


Matthew


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/9cb6e5ef-c3f3-2fdd-44a9-88f9e0c9036b%40comcast.net.


Re: [racket-users] Re: Strange performance behavior

2020-08-08 Thread George Neuner



On 8/8/2020 1:55 AM, Sorawee Porncharoenwase wrote:
I even saw people doing `collect-garbage` three times, just to be safe 
I guess. And yet theoretically it's not guaranteed that things will be 
claimed back properly.


Honestly, there should be a function that does this `collect-garbage` 
until fixpoint or something, so that we don't need to perform this ... 
uh  ritual.


There may be no documented guarantee, but I *think* the implementation 
assures that 2 collections, back-to-back, are sufficient to reclaim all 
objects that were garbage at the beginning of the 1st collection.  At 
least for BC Racket.


And I know that sounds like weasle ... but GC efficiency is measured 
statistically, and it's impossible to reclaim 100% of garbage in a 
single collection without completely stopping the mutator for the 
duration.  The whole point of incremental, generational  [and multispace 
in general] collection is to avoid long pauses.


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/245ee574-69e9-d1f8-b2a0-fe1316e542f2%40comcast.net.


[racket-users] Re: Strange performance behavior

2020-08-07 Thread George Neuner
On Fri, 7 Aug 2020 06:23:52 -0700 (PDT), "'Joel Dueck' via Racket
Users"  wrote:

>On Wednesday, August 5, 2020 at 10:44:21 AM UTC-5 Sam Tobin-Hochstadt wrote:
>
>> Here's a benchmark of your two functions that takes long enough to run 
>> that it avoids some of these issues, and also runs a GC before 
>> benchmarking: https://gist.github.com/7cb4645308d8572e2250833ef7b90b7c 
>>
>
>What is the reason for calling `collect-garbage` twice consecutively? 

It is an attempt to start with the cleanest heap possible.  

Objects that have a "finalizer" get collected over 2 GC cycles - the
finalizer function gets run during the 1st collection, and then the
object memory is reclaimed during the next collection.

Running GC twice makes sure any finalized objects have been collected.


Also, when GC can run in parallel with the mutator, it is possible to
miss collecting objects that become garbage *while* GC is running.
This can't happen in BC Racket, but it might be possible in RacketCS
because Chez has a different thread model. ???


>Also, the docs are unclear on this, but is `(collect-garbage)` equivalent 
>to `(collect-garbage 'major)` ?

The docs clearly state that the default is 'major.

 (collect-garbage [request]) ? void?
   request : (or/c 'major 'minor 'incremental) = 'major


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/tp8sifhd4c0cdlvk22qfsmksckv5r0ajpq%404ax.com.


[racket-users] Re: Strange performance behavior

2020-08-06 Thread George Neuner
On Wed, 5 Aug 2020 08:21:07 -0700 (PDT),
"wanp...@gmail.com"
 wrote:

>I was working on a exercism problem named Raindrops.
>
>  :
> 
>I thought version 1 would be faster, but it turned out to be wrong. Running 
>with raco test got following timing information.
>
>version 1
>cpu time: 9 real time: 9 gc time: 9
>version 2
>cpu time: 0 real time: 0 gc time: 0
>
>Then I ran both version in DrRacket, both output following result.
>cpu time: 0 real time: 0 gc time: 0
>
>It's strange, isn't it?

It looks like the time for the 1st version was skewed by a garbage
collection during execution.

Generally for a decent benchmark, you need to run the code many times
and average the results.  For Racket, additionally you need to
*exclude* the time for the 1st run because that will include time for
JIT compilation.

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/csmnifpho2kgr9sme0psdd0729ui9isdhb%404ax.com.


Re: [racket-users] Re: Racket CS release plan

2020-08-01 Thread George Neuner



On 8/1/2020 3:48 PM, Sam Tobin-Hochstadt wrote:
Note that Matthew's point was not about bytecode, but about the 
machine code in the Racket BC executable vs the machine code in the 
Chez kernel plus boot files. Especially if you look pre-7.0, there is 
very little bytecode in the Racket BC executable.


Sam


Got it.  I missed the context when I read Matthew's message.

However, my comment about average code size remains:  If the Chez code 
uses explicit length prefixes on all instructions that allow them (so as 
to be unambiguous about intent) ... and the GCC code for the BC version 
does not ... then the Chez code EASILY could be much larger.


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/f6c28acb-83db-7c11-8dc0-011429ec6efe%40comcast.net.


Re: [racket-users] Re: Racket CS release plan

2020-08-01 Thread George Neuner

Hi Matthew,

On 8/1/2020 2:01 PM, Matthew Flatt wrote:

At Sat, 01 Aug 2020 03:56:36 -0400, George Neuner wrote:
> On Fri, 31 Jul 2020 20:20:05 -0700 (PDT),
> "wanp...@gmail.com"
>  wrote:
> 
> >I noticed that the size of the CS version is 244% compare to BS 
> >version. Wondering why it became so large. Does that mean Chez Scheme 
> >runtime/vm 100 MB larger than the original one?

> >
> >Racket Mac OS X
> >  64-bit Intel 116.7 MB SHA1: 521b5a264afcfb3f390afacc682987268f650a25
> >
> >Racket CS Mac OS X
> >  64-bit Intel 285.8 MB SHA1: 060f311fc6621c5797a62f98b743499fa4277793
> >
> >https://pre-release.racket-lang.org/
> 
> 
> The CS version compiles to native code rather than portable bytecode,

> so pretty much everything in the distribution is somewhat larger.  It
> adds up quickly.

That's still the best explanation I have, but I also think there must
be something more to it.

For example, the Chez Scheme boot files in uncompressed form add up to
about 8 times the size of compiled Racket BC executable, but Chez
Scheme doesn't have 8 times the functionality of the Racket BC
executable (so it should have 8 times as much machine code). The
machine code generated by Chez Scheme for its boot files is less
compact than machine code generated by GCC or LLVM for Racket BC's
implementation --- but, again, I don't think it's a factor of 8. So,
I'm optimistic that I've so far overlooked something that can make a
big difference.

I've concentrated more on understanding the difference in the run-time
memory footprints, and the difference there is not nearly so large.
Racket CS now sometimes has a smaller memory footprint than Racket BC
(e.g., peak memory use for a distribution build).

Matthew


I don't know details of the Racket bytecode, but I'm assuming that it is 
a mix of simpler operations that map directly to one or a few native 
instructions, and more complex operations that compile to (the 
equivalent of) a small function.  Probably some of these functions can 
be inlined, but I expect there still would be some that can't.


To understand the difference in code size, you would need to look at the 
lengths of bytecode instructions vs their native code equivalents, and 
account for instances of those operations that can be inlined and for 
calls to the functions for operations that can't.



As I said above, I don't know details of Racket bytecode, but a lot of 
virtual machines use 8 or 16 bit opcodes and (allowing for immediate 
operands) have average instruction lengths of 3..4 bytes. Contrast this 
with, e.g., x86-64 code in which the average instruction is 5..6 bytes  
[larger if many instructions require length prefixes (e.g., 32-bit ops 
in 64-bit code)].  The difference can add up very quickly.


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/c3324f5f-19cd-1e0f-3d83-08787474bede%40comcast.net.


[racket-users] Re: Racket CS release plan

2020-08-01 Thread George Neuner
On Fri, 31 Jul 2020 20:20:05 -0700 (PDT),
"wanp...@gmail.com"
 wrote:

>I noticed that the size of the CS version is 244% compare to BS 
>version. Wondering why it became so large. Does that mean Chez Scheme 
>runtime/vm 100 MB larger than the original one?
>
>Racket Mac OS X
>  64-bit Intel 116.7 MB SHA1: 521b5a264afcfb3f390afacc682987268f650a25
>
>Racket CS Mac OS X
>  64-bit Intel 285.8 MB SHA1: 060f311fc6621c5797a62f98b743499fa4277793
>
>https://pre-release.racket-lang.org/


The CS version compiles to native code rather than portable bytecode,
so pretty much everything in the distribution is somewhat larger.  It
adds up quickly.

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/mp6aifl0f4rtb5dqmmbu4an5i414j5ci78%404ax.com.


Re: [racket-users] “If you could have a wish granted, what would you like to see next in Racket?”

2020-07-23 Thread George Neuner


Hi Laurent,

No, "sandboxing" isn't what I want - at least not usually.  I want to be 
able to limit the VM process itself ... particularly the heap size but 
occasionally other things as well.  I often have the need to squeeze a 
Racket application into the corner of a small cloud VM, and I would like 
is more fine-grained control over Racket processes.


Also, sandboxing only notices the overrun when it's too late.  If the 
memory is known limited from the beginning, it would be used 
differently, e.g., GC'd more often.



Without a lot of details about the memory use of various features[*], 
"ulimit -H -d ..." at best is a guess.  "ulimit -H -m ..." works to 
limit memory use, but it can't be used without swap, and without 
limiting the data segment as well, it's easy to start thrashing code vs 
data and kill performance.


"cgroups" helps with multiprocess applications, but it is complicated to 
set up properly.


But in Windows there is no built-in user control for resource use ... 
there are some 3rd party utilities, but many admins won't permit using 
them.  I work a lot with various DBMS, and things may get easier as SQL 
Server is available for Linux, but most people who run it still run it 
on Windows.



And, of course, containers can limit (at least) memory and CPU, but they 
have their own sets of issues, and the container system itself can 
require substantial resources.  Generally I prefer to avoid containers 
and run on the bare machine wherever possible.


YMMV,
George


[*] particularly JIT:  e.g., application mapped files are "data" from 
the POV of the OS regardless of whether the mapping is executable.  So 
JIT'd code really is data for "ulimit" purposes.




On 7/23/2020 12:47 PM, Laurent wrote:

Just in case (not sure how relevant this is to you):
https://docs.racket-lang.org/reference/Sandboxed_Evaluation.html?q=with-limits#%28form._%28%28lib._racket%2Fsandbox..rkt%29._with-limits%29%29
Works pretty well, but there are some caveats: if an object can be 
reached outside of the `with-limits` scope, it's not counted.


On Thu, Jul 23, 2020 at 5:42 PM George Neuner <mailto:gneun...@comcast.net>> wrote:



Limits on resources used by individual VMs.  ulimit works only at the
process level (so only indirectly affects in-process "thread"
places),
and Windows has no simple equivalent:  I am aware of Windows "job
objects", but there are no user controls for them.



--
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/7ef2f992-076d-1f0e-a36c-243fd810ad3d%40comcast.net.


Re: [racket-users] “If you could have a wish granted, what would you like to see next in Racket?”

2020-07-23 Thread George Neuner



On 7/23/2020 8:30 AM, Stephen De Gabrielle wrote:
“If you could have a wish granted, what would you like to see next in 
Racket?”


https://www.reddit.com/r/Racket/comments/hwe49b/if_you_could_have_a_wish_granted_what_would_you/?utm_source=share_medium=ios_app_name=iossmf 
or [original 
twitter](https://twitter.com/racketlang/status/1286020900660404232?s=20)




SIMD ops.  !!!

Limits on resources used by individual VMs.  ulimit works only at the 
process level (so only indirectly affects in-process "thread" places), 
and Windows has no simple equivalent:  I am aware of Windows "job 
objects", but there are no user controls for them.



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/8b3d3265-616d-e93e-4cd3-01b3ca91a474%40comcast.net.


Re: [racket-users] reading s-expressions from a file

2020-07-17 Thread George Neuner


On 7/17/2020 8:19 PM, Hendrik Boom wrote:

Yes,  I know the functino for reading s-expressions seems to be (read [in]).

I want a loop that reads S-expressions and does something to each one, until 
there are no more to be found in a file.

Now of course that's absurdly easy to do with a tail-recursice loop.

But I's like it to look like a loop, with (for ...) or (while ...) or
(loop ...) or something like that.

But I fail to fine any iterators that process a file, such as (in-file
...)

There's a long list of iterators in
https://docs.racket-lang.org/reference/for.html
and in
https://docs.racket-lang.org/guide/for.html

An I just looking in the wrong place, or are there really no iterators
for reading a stream of s-expressions from a file.

-- hendrik


This should work if you're reading the sexprs for value:

(with-input-from-file /filename/
  (lambda ()
    (for [(expr (read))]
  :
    )))

If your intent is to read/parse the sexprs as text, there isn't a simple 
way to do that.  Regex is problematic for nested expressions ... you 
could try "read-syntax" if you are familiar with macros, or "match" if 
you know what patterns to look for.


There's no "in-match" sequence, so if you want a loop that *appears* 
simple [match in the /"for-clause"/], you'll have to write some glue: a 
helper that returns one match result at a time so as to plug nicely into 
a loop.


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/7184da64-a388-91bf-e027-a213a3d66c73%40comcast.net.


Re: [racket-users] Best data structure for ordered data set with insertion and reordering?

2020-07-16 Thread George Neuner


Hi David,

On 7/16/2020 11:44 AM, David Storrs wrote:
On Thu, Jul 16, 2020 at 10:09 AM George Neuner <mailto:gneun...@comcast.net>> wrote:



The problem seems under-specified.  Can you say more about the
real purpose?


Basic version:  It's a peer-to-peer encrypted swarmed file sharing 
system that presents like Dropbox on the front end (i.e. "make a 
change to the filesystem on peer A and peers B-Z will replicate that 
change") and works something like Bittorrent on the back end in that 
files are sent in chunks but it offers functionality that Bittorrent 
does not, such as encrypted transfer, WoT authentication, etc.


Interesting.  So I'm guessing your problem is to (compactly) represent 
the state of the shared space.


Do you plan on having index servers, or are you aiming for a fully 
distributed solution?  And, if distributed, do you want each node to 
maintain its own state picture of the shared space, or were you thinking 
that nodes could just snoop admin broadcasts looking for mention of data 
they don't currently have?  [Your question about how to pair / collapse 
messages suggests you might be considering a snoopy solution.]


Asking because keeping a state picture has scalability issues, a snoopy 
solution has complexity issues, and (depending on latency) both have 
issues with performing unnecessary work.  In any event, I have some 
suggestions.




Snoopy is the more interesting case.  You start with a queue of file 
operations to be done as gleaned from the admin messages - mkdir, rmdir, 
fetch a file, delete a file, etc. - in whatever order the messages were 
received.


Separately, you maintain a (hash table) mapping from pathnames to a list 
of queue nodes that operate on that object.  The map should use weak 
references so that nodes can safely be removed from the queue and 
discarded without also needing to update the map.  If queue processing 
gets to some operation first, any map reference to it will dissolve (be 
replaced by #f).


When a message is received, you lookup the pathname in the map, and if a 
complementary operation is found in the queue, you remove and discard 
it.  [You can also remove references in the map or just let them 
dissolve depending on your handling.]   Then simply discard the message.


Otherwise you queue whatever operation the message indicates and add a 
reference to the queue node under the object's pathname in the map.


Extra complexity comes in having to notice that map entries (pathnames) 
have no operations left in the queue.  Weak references don't just 
disappear - they are changed to #f when the referenced object is no 
longer reachable - however AFAICT there is no hashtable variant that 
permits weak reference values, so you have to use weak-boxes and those 
continue to exist even if the objects they reference are gone.   Useless 
map entries will need to be identified and removed somehow.



Modeling the filesystem can be done rather simply with a trie in which 
folders are represented by mutable hash tables and files by structures.  
You can combine this with the operation queue above, but in this case 
lookups can be done in the trie and queue references kept in the trie 
nodes.  And the trie provides a snapshot of the current state which may 
be useful for other purposes.



The trick in either case is processing latency: you don't want to wait 
too long, but if you really want to avoid unnecessary work you need to 
delay performing file operations long enough that complementary messages 
are likely to be received.





What if messages are lost permanently, e.g., due to hardware crash?


What it you receive a create but a corresponding delete or update is
lost - then your information / picture of the file system state is
wrong.

What if you receive a file delete without a corresponding create?
In the
absence of other information, can you even assume there *was* a
create?
If these messages are sent in response to user actions, can they
ever be
sent mistakenly?


The ultimate answer to these questions is "If things get out of sync 
in a way that the system cannot resolve, it will be flagged for a 
human to resolve." There are things we do that mitigate them -- for 
example, a write-ahead log for messages received from peers -- but we 
acknowledge that we cannot resolve 100% of situations automatically.  
Neither can any other file replication service.  (Dropbox, Box.com, etc)


Also relevantly, differences are reconciled across multiple peers.  If 
there's 5 peers in your replication set and the other 4 agree that 
there should be a file at path P but you don't have one then it's safe 
to assume that you missed a File-Create message.  And yes, that comes 
with issues of its own (Q: What if it was deleted on your machine and 
none of the others got your File-Delete because you crashed before 
sending it? A: Worst case, the file gets recreated and the user 

Re: [racket-users] Best data structure for ordered data set with insertion and reordering?

2020-07-16 Thread George Neuner



On 7/16/2020 4:29 AM, David Storrs wrote:

tl;dr
Can anyone recommend a data structure that is ordered and supports 
efficient reordering, insertion at arbitrary location, and deletion?


Long form:

I'm working on an operation-log reconciliation problem, where each 
operation is one of:


  File-Create    P H
  File-Update   P H
  File-Delete    P H
  Folder-Create P
  Folder-Delete P

P = path
H = hash of the file (e.g. md5)

Operation messages travel over the network, meaning that they could 
arrive out of order.  (They could also be missed entirely, but that's 
a separate problem that I'm not working on yet.)


Shouldn't be a problem:  "at-least-once" and "at-most-once" semantics 
both are pretty easy.  It's the "exactly-once" that is the problem.  
Hopefully you have no need for that.



Specifically, I want to be able to take a series of messages and 
collapse them where appropriate.  For example:


  File-Update P H1 -> H2
  File-Create P1 H1
Result after collapse:
  '(File-Create P1 H2)

  File-Create P H1
  File-Delete P H1
Result after collapse:
  '()

  File-Delete P X
  File-Create P X
Result after collapse:
  '()
  File-Delete P1 H1
  File-Create P2 H2
  File-Create P1 H1
Result after collapse:
  '(File-Create P2 H2)

I've been mulling over various ways to handle all of this and digging 
around to find examples of other people doing it, but I'm wondering if 
there's a data structure or existing algorithm that will handle it 
cleanly.  Does anyone know of such a thing?


What if messages are lost permanently, e.g., due to hardware crash?

What it you receive a create but a corresponding delete or update is 
lost - then your information / picture of the file system state is wrong.


What if you receive a file delete without a corresponding create? In the 
absence of other information, can you even assume there *was* a create?  
If these messages are sent in response to user actions, can they ever be 
sent mistakenly?


The problem seems under-specified.  Can you say more about the real purpose?


I can think of some ways to keep an index of the file system and track 
changes made to it ... but at best that could provide a snapshot in time 
rather than an ongoing audit log.  And it seems like a log would not be 
terribly useful without all the information.


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/e5bfead8-20cc-47b5-3f10-6a568aa04ba9%40comcast.net.


[racket-users] Re: Are Regular Expression classes Unicode aware?

2020-07-09 Thread George Neuner
On Thu, 9 Jul 2020 14:43:03 -0400, Philip McGrath
 wrote:

>On Thu, Jul 9, 2020 at 10:32 AM Sorawee Porncharoenwase <
>sorawee.pw...@gmail.com> wrote:
>
>> Racket REPL doesn’t handle unicode well. If you try (regexp-match?
>> #px"^[a-zA-Z]+$" "héllo") in DrRacket, or write it as a program in a file
>> and run it, you will find that it does evaluate to #f.
>>
>See this issue for workarounds, including installing the `readline-gpl`
>package: https://github.com/racket/racket/issues/3223
>
>But you may have some other issues: for me, `(regexp-match?
>#px"^[a-zA-Z]+$" "h\U+FFC3\U+FFA9llo")` gives an error saying "read-syntax:
>no hex digit following `\U`"

It works if you remove the '+' sign.  \U and \u are defined to take
hexidecimal values, which are unsigned.  For comparison, \x fails with
the same error if the value is signed.

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/ge0fgflkfkh679e5v8uk9udr3hj0mhvf8h%404ax.com.


Re: [racket-users] Layout + styling in racket/gui

2020-07-06 Thread George Neuner



On 7/6/2020 5:54 PM, Travis Kiefer wrote:

Hello all!

I'm coming from the background of building web apps that are wrapped 
in a headless browser and would like to take the app development 
experience and bring it to the racket ecosystem. As an html / css / 
javascript engineer I'm finding the learning curve pretty daunting 
with racket's documentation but lack of copious examples... So I'd 
like to create some practice apps that introduce ideas / concepts that 
are familiar from the web app realm within the environment of racket...


That said, what I'd like to do is build the canonical "Todo App" in 
racket/gui or an equivalent. Basically I'd like the ability to create 
the equivalent of div / layout elements, sub elements that you are 
familiar to the browser (text input, checkboxes), and the ability to 
mix in styles. Basically HTML + CSS.


Ideally I'd like to create a Racket version of the following 
website: http://photonkit.com.


Any resources to get started would be great.

Best,
Travis


There is a basic GUI layout editor called "MrED".  It's not included 
with Racket, but it is available as an installable package:

   https://pkgs.racket-lang.org/package/mred-designer
http://planet.racket-lang.org/display.ss?package=mred-designer.plt=orseau

The 1st link is newer, but AFAICT doesn't include the documentation.  
2nd link is to the older package server, but includes documentation.



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/1ba3c824-f7bf-81d9-2246-e9d7bc13c862%40comcast.net.


Re: [racket-users] Creating .dmg for a GUI application

2020-07-06 Thread George Neuner



On 7/6/2020 12:48 PM, Travis Kiefer wrote:

Hello all!

Relatively new to the Racket ecosystem and trying to figure out how to 
create an "app" from the GUI library. Has anyone written a tutorial on 
this or have suggestions on where to start to generate this? For 
context, I'm used to the Javascript ecosystem and have built apps with 
Electron. I'm looking to migrate to a more robust lisp-y environment 
when developing native apps and not sure where to start here.


Any help would be greatly appreciated!

Thanks,
Travis


The simplest way is to select "Create Executable..." from the "Racket" 
menu in DrRacket.  Select "GRacket" as the base if your program uses a 
graphical interface.


For more options, see the "raco" command line tool: 
https://docs.racket-lang.org/raco/index.html



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/48e68181-b3bd-4cfe-a30b-7be67109fb60%40comcast.net.


Re: [racket-users] Wills, plumbers, and checking if a port is closed

2020-06-30 Thread George Neuner



On 6/30/2020 4:27 PM, David Storrs wrote:
I have a port that (my current theory says) is being closed when it 
shouldn't, but I'm having trouble isolating exactly where and when.  I 
thought maybe I could do something Rackety to say "as soon as this 
port gets closed, run this function".  I went digging through Wills 
and Plumbers but I'm having trouble grokking it.  Am I headed in the 
right direction, or is there a better way?


Ports are able to raise events.  I don't know if any of these are 
directly useful to diagnose your early close problem, but you may be 
able to cobble something using multiple events.


https://docs.racket-lang.org/reference/sync.html
https://docs.racket-lang.org/reference/port-lib.html?q=port#%28part._.Port_.Events%29


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/47967210-b87b-7a94-a9e2-035a8159e380%40comcast.net.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread George Neuner



Sorry for the noise:  it behaves as you say returning "!", "2", ...    
Somehow I paths screwed up and was running CS when I thought I was 
running regular (bytecode) Racket.


Sigh!
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/abbcdae5-f88e-8a4c-f48b-c6f4fb6be38c%40comcast.net.


Re: [racket-users] Why does this counter behave differently in different runtimes?

2020-06-17 Thread George Neuner


It seems to work ... i.e. returns # ... in Windows.  I tried it in 
7.6 and 7.7,  both 32 and 64 bit versions.   Not near my Linux machine 
to try it there.


The expansion in all cases is the same and seems reasonable:

   (module count racket
  (#%module-begin
   (module configure-runtime '#%kernel
 (#%module-begin (#%require racket/runtime-config) (#%app
   configure '#f)))
   (#%provide count!)
   (define-values
    (lifted/2)
    (begin
  (with-continuation-mark
   contract-continuation-mark-key
   (#%app cons idB12 'no-negative-party)
   (let-values ()
 (#%app
  idX9
  (#%app
   module-name-fixup
   (#%app
    variable-reference->module-source/submod
    (#%variable-reference))
   (#%app list)))
   (define-values
    (count!)
    (let-values (((i) '0))
  (lambda () (begin0 (set! i (#%app add1 i)) (#%app lifted/2
   i)))



Btw:  my Racket installations report only  "7.7", not  "7.7.0.5". Are 
you running a snapshot build?


George


On 6/17/2020 3:04 AM, Sage Gerard wrote:
I attached a video demonstrating what I'm seeing. In case it does not 
load or is not available, I'll summarize here. Forgive any typos; it's 
been a late night of coding.


Here's a module with an incorrect counter. It's incorrect because it 
uses begin0, and is therefore expected to return void instead of an 
incrementing integer.


#lang racket
(provide count!)
(define count!
  (let ([i 0])
    (λ () (begin0
    (set! i (add1 i))
    (~v i)

Notice that I added the ~v to format the return value. If I launch 
Racket v7.7.0.5 using racket -it prog.rkt, (count!) returns the 
formatted value. But if I remove the ~v, it behaves as written 
(returning void).


The video shows the behavior with and without ~v, both in DrRacket and 
racket. DrRacket is the only environment that consistently runs the 
code correctly.




--
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/626cee23-fa67-c17f-781c-44554a50cf2e%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-09 Thread George Neuner



On 6/9/2020 8:11 AM, Jon Zeppieri wrote:

On Tue, Jun 9, 2020 at 7:59 AM Bogdan Popa  wrote:
>
> I think we'd need to also set `SO_REUSEPORT', which is not available on
> all platforms, to support multiple processes listening on the same port
> without reusing file descriptors.

And even where it is available, it doesn't work the same way. The
Linux version can be used to load balance accept()s across processes,
but the BSD version (also in OS X) cannot. (FreeBSD apparently has a
variant, SO_REUSEPORT_LB, that behaves like the Linux version of
SO_REUSEPORT.)


And Windows has 2 options that mean essentially the same thing: 
SO_REUSE_UNICASTPORT  and  SO_PORT_SCALABILITY.


SO_PORT_SCALABILITY  was introduced in Windows 7 / Server 2008.
SO_REUSE_UNICASTPORT  was introduced in Windows 10.

Whichever port reuse option is supported by the platform, it normally is 
set automagically whenever  SO_REUSEADDR  is specified. Only functions 
that require an explicit bind need it to be set manually.




It's clear that enabling the functionality would have to be studied 
carefully.


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/908a290c-75a3-30f0-515f-b93ade3ac103%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-09 Thread George Neuner



On 6/9/2020 7:59 AM, Bogdan Popa wrote:

George Neuner writes:

> Multiple Racket applications *should* all be able to listen on the
> same port without having been spawned from the same ancestor process.
> If that isn't working now, something has gotten hosed.

I don't know whether this used to work in the past or not, but currently
only `SO_REUSEADDR' is set on TCP sockets:

https://github.com/racket/racket/blob/60bf8f970e97caae391bfe919b78c370b2d01bdd/racket/src/rktio/rktio_network.c#L1427

I think we'd need to also set `SO_REUSEPORT', which is not available on
all platforms, to support multiple processes listening on the same port
without reusing file descriptors.


It has been discussed before, but perhaps now, with RacketCS imminent, 
the socket functions should be changed / expanded to allow changing 
options without resorting to FFI.


AFAICS, the functionality of SO_REUSEPORT (if not the verbatim option) 
is available on all supported platforms.  Granted it is (relatively) a 
recent addition to both Linux and Windows.


Android doesn't support it, but AFAIK, Android is not considered a 
supported system.




> I'm not sure what you mean by "sharing" a listener,  but using a
> single listener with a pool of processing places actually is possible
> (though tricky).

I mean passing a `tcp-listener?' around between places so that each
place can call `tcp-accept' on it.  Something like this:

 #lang racket/base

 (require racket/place
  racket/tcp)

 (define ch
   (place ch
 (define listener (place-channel-get ch))
 (tcp-accept listener)
 (place-channel-put 'ok)))

 (module+ main
   (define listener
 (tcp-listen  512 #t))
   (place-channel-put ch listener)
   (place-channel-get ch))

Currently, this fails with:

 place-channel-put: contract violation
   expected: place-message-allowed?
   given: #
   context...:
 ...

My understanding is that there's nothing preventing this from working
apart from the fact that no one's yet added support for this in the
rktio layer.  As you mentioned, though, even if this was supported we
might run into other limitations when running many places at once.


Only serialized[1] functions can be passed between place ... and the 
receiving place still has to have imported the libraries (if any) 
necessary to understand it.  I don't know if a listener even can be 
serialized, though ... AFAIK a serializable function has to be compiled 
that way.


George

[1]  https://docs.racket-lang.org/web-server-internal/closure.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/ea9627a2-34d7-0c09-8246-32fd2d955c25%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-09 Thread George Neuner



On 6/9/2020 3:02 AM, Bogdan Popa wrote:

Alex Harsanyi writes:

> Question 1: Based on this benchmark, is there any reason to chose anything
> else but "drogon"?  Even if one chooses the second best on that list, which
> is "actix", they already loose about 6% performance and things degrade
> quickly afterwards.  The framework at position 10 is already half the speed
> of the top one.

My take on these benchmarks is all that matters is that the framework
doesn't get in your way once you add business logic.  The vast majority
of "real" web applications out there don't (and most likely can't) do
50k rps.


Or anywhere close to that given more realistic database queries.



You can see that in the "multiple queries" and "data updates" tests
where the results are packed closer together because the logic is closer
to what a lot of database-backed web applications do and the database
ends up being a bottleneck.  A description of the requirements of each
test can be found here:

https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview

If you know and are willing to deal with writing and maintaining C++
then drogon looks like it might be a great choice.

> Question 2:  Based on Bogdans message in this thread, it seems that most of
> the performance improvement for the Racket benchmark comes from the nginx
> configuration (which has nothing to do with Racket) and the next
> improvement has to do with how the user program is written (by supplying a
> "Content-Length" header).  So, is this benchmark really testing the Racket
> web server performance, or is it testing a very specific deployment?

The largest improvement comes from making the Racket application take
advantage of all the hardware threads on the machine.  Because Racket
doesn't currently have a way to share TCP listeners across places and
because fork isn't natively supported (I mentioned that it works via the
FFI earlier in the thread, but I believe it needs some support from the
runtime (handling of `EAGAIN') to work efficiently and not cause a lot
of churn) I did the next best thing: I made the benchmark run one Racket
process for each thread[1] and added nginx as a load balancer in front.

The nginx process listens on port 8080, forks one subprocess per core
(which lets the subprocesses reuse the same port) and then proxies any
incoming requests on that port to one of the Racket processes so every
single request is ultimately served by the Racket app.  What this means
in terms of this benchmark is that, compared to others, we're actually
paying a toll for using nginx here because its own workers are consuming
resources on the machine, but, to my knowledge, we don't have a better
alternative at the moment.


Hmm.  SSL which can be tricky to set up right for Racket, but that's the 
only reason I can see for using a separate HTTP server. Multiple Racket 
applications *should* all be able to listen on the same port without 
having been spawned from the same ancestor process.  If that isn't 
working now, something has gotten hosed.


I'm not sure what you mean by "sharing" a listener,  but using a single 
listener with a pool of processing places actually is possible (though 
tricky).  TCP ports can be passed among places, so a single listener 
instance can direct multiple processing instances.  I don't know how 
passing off the port would interact with web-server response handling (I 
would think the listener place could just shut down / abandon the port 
and leave response to the process place but I have never actually tried 
that).


Dynamic (thread in process) places seem to have issues when there are 
many instances, so for lots of cores it is better to use distributed 
(parallel process) places.  Paulo Matos's  Loci  package makes using 
process places much easier [and it also works on Windows if that matters].

https://pkgs.racket-lang.org/package/loci



[1]: 
https://github.com/TechEmpower/FrameworkBenchmarks/blob/988f052c8170da661c49dd51d1f33d500a871031/frameworks/Racket/racket/scripts/run#L15-L19


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/b763ea64-6319-b162-747b-825cf1cabcb9%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 4:21 PM, Bogdan Popa wrote:

George Neuner writes:

> But Python's DB pool is threaded, and Python's threads are core
> limited by the GIL in all the major implementations (excepting
> Jython).

Python's Postgres pooling does not[1] use POSIX threads under the hood
to manage the connections if that's what you mean, nor is the
concurrency of the Python applications based on system threads.  All of
the Python examples use either asyncio + fork(2) or green threads +
fork(2).  This includes the django example[3].


I said nothing whatsoever about POSIX.  And FYI, POSIX does not imply 
any particular implementation - POSIX specifies only the API, and a 
compliant implementation may provide kernel threads, user space threads, 
or a combination of both.


What I did say is that Python's threads are core limited - and *that* is 
true.   As a technical matter, Python *may* in fact start threads on 
different cores, but the continual need to take the GIL quickly forces 
every running thread in the process onto the same core.




> There are a few things Python can do faster than Racket, but the VAST
> difference in performance shown in the techempower tests isn't
> explained by them.

Here's a benchmark that doesn't touch the DB at all, showing an even
bigger difference in throughput between the two:

https://www.techempower.com/benchmarks/#section=data-r19=ph=json


That one actually is expected:  Racket's JSON (de)serializer is 
relatively slow.



What wasn't expected was Sam's results from the "plain text" test which 
also showed Racket much slower than Python.  That does hint at a lot of 
overhead in the Racket framework.




I wrote the latest implementation of the Racket code for that benchmark
and I considered doing things like bypassing the "standard"
`dispatch/servlet' implementation to avoid the overhead of all the
continuation machinery in the web server, but that felt like cheating.


To my knowledge, continuations will not be a factor unless either 1) the 
application is written in the #web-server language (which converts 
everything to CPS), or 2) the code invokes one of the send/suspend/*  
functions.


FWIW: I try to avoid using client facing continuations in my own web 
applications - for my money there are too many uncertainties connected 
with them.


Also the stuffer does a fair amount of work to deal with long 
continuation URLs.




Another area where the web server does more work than it should is in
generating responses: the web server uses chunked transfer encoding for
all responses; whereas all the Python web servers simply write the
response directly to the socket when the length of the content is known
ahead of time.


My understanding is that the port passed to  response/output  is the 
actual socket ... so you can front-end it and write directly.  But that 
might be "cheating" under your definition.



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/2fd131be-ca0e-eaa1-6595-d31a410d43d4%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 3:40 PM, Sam Tobin-Hochstadt wrote:

I'm skeptical both of the DB explanation and the multi-core
explanation. As you say, the difference between something like Django
and Racket is much too large to be explained by that. For example, on
the "plaintext" benchmark, Racket serves about 700 req/sec (I get
similar results on my machine). Many of the benchmarks in languages
like Python and Ruby do more than 1000x better, which means that even
if we had perfect speedup on 32 cores, we'd be nowhere close.
Additionally, the "plaintext" benchmark doesn't touch the DB at all. I
tried commenting out all of the DB code entirely, and it did not
change the results.

My guess is that the web server is just doing a lot of per-response
work that would need to be optimized.

Sam


Possibly ... I admit that I did not look at the plain text results: I 
was drawn to the fact that the DB results impose a lot of non-Racket 
overhead.


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/cfc6c027-180d-d822-6d36-9f1cfb1849fc%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 1:40 PM, Bogdan Popa wrote:

I replied earlier today off of my Phone, but, for whatever reason
(caught in the moderation queue?), it's not showing up in this thread.

Here's what it said:

The reason for poor performance relative to the other
langs/frameworks is that there is currently no easy way to take
advantage of multiple cores using the web framework so that's being
benchmarked is single-core performance.

This is mainly a problem for benchmarks such as this, but not really
an issue in the real world where you'd just run multiple processes
with a load balancer in front.


Single core [by itself] doesn't explain the enormous performance 
difference between Racket and Django.


I haven't looked at the Django submission - Python's (in)comprehensions 
give me a headache.  But Python's DB pool is threaded, and Python's 
threads are core limited by the GIL in all the major implementations 
(excepting Jython).


There are a few things Python can do faster than Racket, but the VAST 
difference in performance shown in the techempower tests isn't explained 
by them.  My suspicion is that the Racket application is making too many 
database connections and not relying enough on its open connection 
pool.  Hundreds of trivial requests can be served in the time it takes 
to spin up a new backend process.


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/9236dcff-81df-1db8-c2ef-06b20e4690ec%40comcast.net.


Re: [racket-users] Re: [racket] Web Framework Benchmarks

2020-06-01 Thread George Neuner



On 6/1/2020 11:12 AM, Sam Tobin-Hochstadt wrote:

I think the biggest thing is that no one has looked at optimizing
these benchmarks in Racket. If you tried out running one of these
benchmarks and ran the profiler it would probably show something
interesting.

Sam
The code[1] itself isn't bad.  There are a couple of minor things I 
personally would tweak, but in my opinion the main problem is with the 
database access.


Postgresql uses process parallelism - it forks a new backend process to 
handle each connection.  Assuming (???) there are enough concurrent 
requests to open the maximum number of DB pool connections, then 1024 is 
WAY too many.  PG experts recommend no more than 5..10 backend processes 
per core, but according to the environment details[2], the test machines 
have only 14 HT cores (28 threads).


Mind you I'm only guessing, but it looks to me like this application 
could be losing an enormous amount of time in the starting of new 
backend database processes.  And since it is running inside a Docker 
container, there also is some per connection overhead there.


The requests made by the tests[3] are so trivial (needing little 
additional Racket processing) that I would consider reducing the number 
of PG pool connections to just a few per core and see how that goes.  My 
expectation is that the time saved by spinning up many fewer PG 
processes will vastly outweigh any loss in absolute request 
concurrency.  [Particularly if they also are running PG itself inside 
Docker.]


YMMV,
George

[1] 
https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/Racket/racket/servlet.rkt
[2] 
https://www.techempower.com/benchmarks/#section=environment=ph=fortune
[3] 
https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview


--
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/eafb41e8-734c-7666-e684-edade3731e79%40comcast.net.


Re: [racket-users] Function that potentially can return more than one value

2020-05-27 Thread George Neuner



On 5/27/2020 1:50 PM, Jens Axel Søgaard wrote:
Den ons. 27. maj 2020 kl. 19.27 skrev George Neuner 
mailto:gneun...@comcast.net>>:



On 5/27/2020 6:34 AM, Jens Axel Søgaard wrote:
>
> In standard Racket an application doesn't communicate how many
values
> a function is expected to produce.

You can ask:  see procedure-result-arity
https://docs.racket-lang.org/reference/procedures.html


I think  procedure-result-arity  answers the question "how many
values could this procedure return?" and not "how many values
is the procedure expected to return in this context?".


Oh, I get it ... it's not that you "don't know" what's expected, it's 
that you've got something that returns N values on some path and M 
values on some other path, etc.  and you can't predict which path will 
be followed.


Yeah, that is a problem:  e.g., I don't think procedure-result-arity  
works for  case-lambda  where different invocations can return different 
numbers of results.


In that case, better to return a container: a list, vector, hash, etc. 
rather than a bunch of individual values.  Or, if the function is canned 
[e..g, in a library] to put them into a container for your code to work 
with.



> I have written a small proof-of-concept of an assignment operator :=
> that communicates to a function how many extra values it is expected
> to produce (and still works with standard functions).
>
> Are there alternative solutions that are better than the "use a
> keyword" approach?

You can use  call-with-values  which connects the function that
produces
with the one that consumes, but they have to agree on the number of
values being passed or it won't work.


My problem is that the producer still needs to be told how many values 
to produce.



Sorry, I missed that - I thought you needed to know how many were 
produced by something.


The only way to call attention - particularly compiler attention - to a 
particular argument is to make it a keyword with no default value.


If your function has default behavior that the keyword(s) would only 
modify, then you can make keyword(s) optional using default values or by 
defining the function with  make-keyword-procedure.



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/5bea165b-3357-7236-173c-934ca3a0ab58%40comcast.net.


Re: [racket-users] Function that potentially can return more than one value

2020-05-27 Thread George Neuner



On 5/27/2020 6:34 AM, Jens Axel Søgaard wrote:


In standard Racket an application doesn't communicate how many values
a function is expected to produce.


You can ask:  see procedure-result-arity
    https://docs.racket-lang.org/reference/procedures.html



I have written a small proof-of-concept of an assignment operator :=
that communicates to a function how many extra values it is expected
to produce (and still works with standard functions).

Are there alternative solutions that are better than the "use a 
keyword" approach?


You can use  call-with-values  which connects the function that produces 
with the one that consumes, but they have to agree on the number of 
values being passed or it won't work.


You can use a Rest argument in the consumer if the values from the 
producer are put into a list.



Unfortunately, Scheme did not embrace the idea of using tuples for 
return values, nor did it allow to catch only the first N values as was 
permitted by Lisp.


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/fefd28d4-bab8-11bc-0a29-0983758cd454%40comcast.net.


Re: [racket-users] Testing for Packages

2020-05-27 Thread George Neuner


On 5/26/2020 10:36 PM, Robert Postill wrote:


Inspired by the reply to 
https://stackoverflow.com/questions/62014612/how-to-test-a-racket-package-self-sufficiently, I 
decided to ask the question here.  So a little background to the 
discussion.  I've been looking at a racket package, and the package 
has a couple of collections.  It's been dormant for a few years, and 
so when I ran the tests they didn't work (it's a driver, and the 
database it works with had moved on in the intervening time).  So I 
started thinking about the tests.  One thing that troubled me was that 
the tests seemed to be dependant on the package already being 
installed. Ryan Culpepper's comment on the stack overflow question 
(https://stackoverflow.com/a/62027185/11219) suggests that the tests 
should be run once the package is under raco pkg's management.


The problem is that any particular package may require a specific 
runtime environment:  e.g., many packages provide Racket interfaces to 
3rd party libraries.  And those libraries have their own sets of 
dependencies.  And many libraries have compatibility problems with 
others, so having many libraries available in a "generic" test 
environment is not possible.


But even if the package host did maintain custom test environments (VM 
or container or ...) for every contributed package - that STILL does not 
guarantee that any given package will work on YOUR system, with YOUR 
particular set of libraries.


You say the package that inspired this question used a database. Which 
database?  What version?  There are dozens of DBMS available - many are 
NOT $$$ free to own, and all of them have multiple versions having 
various compatibility problems (i.e. what works with v8.2 may not work 
with v10.4 - or the reverse).  Many server class DBMS will not 
peacefully co-exist with another on the same system, so then you're 
talking about many virtual machines or containers (if the DBMS in 
question even works in a container - some don't).



In the generally excellent docs for racket, I haven't found advice 
relating to the right way to structure the tests for a package.


Right.  Because many packages interface to 3rd party software, and so a 
lot of - so called - advice would, of necessity, be generic to the point 
of being useless.



Now I think I should explain why I'm thinking that way.  FYI I've been 
a part of the ruby community, and so my thinking has a ruby-ish 
colour.  Which makes me think I'm maybe off in my community norms for 
racket. I've always considered the point at which a package gets 
transferred into the domain of raco pkg's management to be a pivotal 
moment. It has this implied social contract that if I'm mixing with 
code into a system area managed by the language, the package needs to 
be trustworthy.


If the Ruby maintainers told me that they were able to test every 
contributed package in that package's expected runtime environment, I 
simply would not believe them.


I wouldn't believe it if Google, or Apple, or Oracle, or Microsoft, or 
Redhat, or Ubuntu said it either.  Nobody can do it - the expense is 
prohibitive.



Testing *after* installing seems a bit like I'm putting the cart 
before the horse? It feels like saying here's my code, put it in a 
system-wide place, I hope it works.


I understand both the motivation and the frustration.  For a long time I 
developed embedded software under situations where I controlled 
everything: the hardware, the OS (if there was one), my application, the 
libraries it depended on, etc.  I knew exactly the conditions my 
software was expected to operate under, and and the complete set of 
input it could possibly receive.


But 99+% of all software has to run under an uncertain environment that, 
at best, is only partly know to its developer, depending (at least 
transitively) on a lot of 3rd party software that the developer often is 
completely unaware of.



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/03945aa3-d83a-73c9-d206-ce25a423fd39%40comcast.net.


Re: [racket-users] Is it possible to make submodules with private names?

2020-05-23 Thread George Neuner



On 5/22/2020 11:11 PM, rocketnia wrote:
I've been thinking about making libraries that would generate 
submodules when they're used. However, submodules exist in a flat 
namespace, I'm a bit afraid of conflicts if I choose the same name as 
some other library does, and I don't really want users to have to 
supply their own local choices of names (`rename-in` style) since I'm 
thinking of these submodules as an implementation detail.


Why not name your modules using UUIDs or similar generated random 
strings?  You can't ever be certain that a generated name won't 
conflict, but you can make the probability very, very small.


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/00338189-f731-bf57-5bb4-f70815485792%40comcast.net.


[racket-users] Re: Is there an easy way to daemonize a thread?

2020-05-19 Thread George Neuner
On Tue, 19 May 2020 12:01:54 -0400, David Storrs
 wrote:

>I'm using the file-watchers module to keep an eye on a directory tree and
>trigger various actions whenever something changes.  I had an issue where
>an exception was thrown, the thread died, and file watching therefore
>stopped.  The immediate solution is to wrap a with-handlers around it so it
>doesn't end up killing the thread, but this made me wonder if there's an
>easy way to do this automatically?
>
>What I'm thinking of is "Create a thread that will do something in a loop.
>Ensure that the thread remains running and restart it if it dies for any
>reason.  Also, make sure that it runs periodically."  I can think of a
>solution involving multiple threads, channels, and polling to ensure that
>the 'daemonized' threads are running, but I was wondering if there's a
>built-in or existing answer.

There is a package called "thread-utils" which claims error safe
looping threads.
https://pkgs.racket-lang.org/package/thread-utils

*Disclaimer*  I have never tried it.


I can think of a some possible implementations, but they all involve
monitoring by a separate thread (which could be the main thread).
Channels aren't necessary - monitoring can be done using events.

Restarting a (possibly failed) computation IN a running thread is
relatively simple - if you know what errors or events might occur. The
problem is that a thread can't restart itself if somehow it gets
suspended or killed.

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/uvi8cftuuvfkq0cqm27m0icvhhq5mpupuo%404ax.com.


[racket-users] Re: Futures + threads SIGSEGV

2020-05-03 Thread George Neuner
On Sat, 2 May 2020 14:10:19 +0200, Dexter Lagan
 wrote:

> I’ve been getting inconsistent results as well. A while ago I made a
>benchmark based on a parallel spectral norm computation. The
>benchmark works fine on Windows on most systems and uses all cores,
>but crashes randomly on other systems. I haven’t been able to figure
>out why. On Linux it doesn’t seem to use more than one core. I’d be
>interested to know if this is related. Here’s the benchmark code :
>
>https://github.com/DexterLagan/benchmark
>
>Dex

I haven't examined the code in detail, but I suspect you're not giving
the futures time to do anything.  Your 'for/par' function touches them
almost immediately, and touching forces a future to be evaluated by
the thread that has touched it.

Also be aware that futures essentially are limited to data access and
math ... in particular if you try to do any kind of I/O within a
future it will force (at least) that future into serial execution.

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/i2tuafl9rs29bjlr9i6rb387bdqj02epqg%404ax.com.


Re: [racket-users] Reducing parentheses without language damage.

2020-05-03 Thread George Neuner



On 5/2/2020 4:58 AM, Dexter Lagan wrote:

  For the sake of discussion, here’s a long rant:

  I might have a very uninformed opinion here, but wouldn’t having 
significant white space and no scope-defining character amount to 
multiple spaces and line feeds being part of the syntax? The next best 
thing being, allowing semicolons in place of line feeds. I’m no 
language designer, so let me try to give you my perspective as an 
average programmer:


  I find editing Python and Haskell a pain, because of white spaces. I 
can’t count the times I got that dreaded ‘invalid indentation’ error, 
because I’m editing code with a different editor on a different 
system. I also had to reformat entire programs after somebody saved 
using the incorrect tab setting, and I avoid Python because of this. 
Yet I haven’t heard this complaint from Python programmers, so I 
always believed I was just too dumb.


Python is as much a cult as a programming language.


  I haven’t seen a better solution than s-expr to make expressions and 
scope ultra-visible and easy to manipulate. Yet s-expressions still 
bring their own requirements for comfortable editing: most people 
still require a specialized editor or a plugin for lisps. I fact, is 
there any language that doesn’t require some sort of plugin or 
specialized editor to be attractive to new programmers? Thinking of 
it, isn’t the IDE almost as important as the syntax or the language 
these days?


For most languages, IDEs are mainly needed for debugging.  For just 
editing, the majority of languages really don't need syntax or structure 
awareness.  Syntax coloring is nice, but programmers got along fine 
without it for ~50 years.


Most languages in use now have syntax based (however loosely) on C and 
mostly are not WS sensitive.  The compiler doesn't care about how the 
code is formatted:  there is a statement terminator (or separator [there 
is a difference]) character that serves to keep the compiler 
synchronized with the source.


In Pascal, you can write an entire program on a single edit line. In C 
and C++, the preprocessor is line sensitive, so it isn't possible to 
write a whole program in one line - but the mainline code is WS 
indifferent, and you can write entire functions, or even multiple 
functions, in one line.


But no one does that except in those competitions trying to pack a whole 
program into 255 characters or less.


For most languages it is visual debugging: tracing and breaking 
execution, probing runtime values, while seeing the source ... *that* is 
where an IDE comes into its own.



S-expr languages are different in this respect because they are 
expression based rather than statement based.  Expressions can be nested 
arbitrarily, and it is more difficult to visually identify things 
without some editor assistance like coloration, parenthesis matching, 
and syntax directed indentation.


S-expr languages have long used - though not required - indentation as a 
guide to visualize program structure.  When you program with Racket (or 
Scheme or Lisp) for a while, you cease to see the parentheses and really 
mostly see only the indentation structure.


For debugging: tracing and breaking S-expr code is more complicated to 
*display* and interact with reasonably - the UI matters greatly to 
programmer efficiency.  But the actual debugger internally is not really 
much different from a debugger for a statement language - it's mostly 
how the programmer interacts with it that needs to change.



Some JavaScript programmers can’t work without VSCode, scope-sensitive 
autocomplete, a linter and god knows how many other plugins. PHP 
programmers also feel naked without a fancy IDE and a host of plugins. 
I keep hearing people complain about x or y language because it 
doesn’t have a good editor, IDE or plugin for VSCode. Globally, people 
use more and more tools to program in the same languages.


Programmers today are spoiled.  My first program was written on a 
teletype connected by modem to a PDP-10 at some nearby college.  It took 
half an hour to get a 10 line program working.



  That’s what turned me into a sort of ‘digital minimalist’. I take 
comfort in not being dependant on anything other than a 
compiler/interpreter and a simple editor I can whip out of any system 
in seconds. I think there’s value in reducing our dependencies, 
including on tools, editors, IDEs and plugins. That being said, I love 
DrRacket and its facilities, also because it’s self-contained and 
bundled with Racket. One less thing to install.


  These are the considerations I’d take in account when thinking of a 
new syntax. Still, like I said before, I’m excited by the fact that 
the Racket team is looking for a solution to this problem, and I’ll be 
the first to applaud a way to keep the next Racket expressive and 
powerful, while making it more attractive to people used to more 
familiar syntax. Parentheses are, and always will be a barrier to 
entry for 

Re: [racket-users] Reducing parentheses without language damage.

2020-05-01 Thread George Neuner


On 5/1/2020 4:35 PM, Dexter Lagan wrote:
  Is there value in Rob Pike’s comment on avoiding significant white 
space in the Go language?


“We have had extensive experience tracking down build and test 
failures caused by cross-language builds where a Python snippet 
embedded in another language, for instance through a SWIG invocation, 
is subtly and invisibly broken by a change in the indentation of the 
surrounding code.” — Rob Pike, 2012 





I'm not really sure what Pike is getting at there:  I haven't used SWIG 
myself, but if I understand it correctly, Python code would have to be 
in a module to be called from "other" language code.  If so, I don't see 
how the indentation of the "other" code could affect the Python.


That aside:

Even working only in Python, programmers routinely get tripped up by 
copy/paste errors - so it is evident that indentation sensitivity is not 
any real solution to scope related logic problems.  It might [for some 
definition] help newbies identify stupid errors, but I believe that even 
moderately experienced programmers are more hindered than helped by it.



  I personally dislike white space and prefer either mustaches or 
parenthesis, just so I know my code will still work if line feeds are 
stripped somehow, or that some piece of code is embedded or quoted in 
another language, which is what I gather Rob was talking about. 
However, Haskell and Python people don’t seem to mind, and if it saves 
us more keystrokes while keeping expressiveness, why not?


Well, few people use Haskell, so I would discount it as a data point.  
Even so, one of the tutorials includes this interesting tidbit:


   With good text editor, programming is fun. Of course, you can get
   along with simplistic
   editor capable of just cut-n-paste, but good editor is capable of
   doing most of the chores
   for you, letting you concentrate on what you are writing. With
   respect to programming
   in Haskell, good text editor should have as much as possible of the
   following features:

   • Syntax highlighting for source files
   • Indentation of source files
   • Interaction with Haskell interpreter (be it Hugs or GHCi)
   • Computer-aided code navigation
   • Code completion


The implication is that Haskell is difficult to write without proper 
editor support.  So too is Python.  Decent syntax and structure aware 
editors are not really a problem any more, but they can go only so far:  
they can fail spectacularly when code gets complicated and the language 
syntax provides no clues to figure out the scoping.


S-exprs do not suffer from this affliction.


Also mentioned previously is my concern that indentation sensitivity may 
make implementing macros as we enjoy them in Racket difficult. Or maybe 
impossible.  Although certainly there are indentation languages which 
have macro facilities, I am not aware of any in which the macros can be 
written in the same language.  All the ones I know of implement a 
separate DSL macro language.


I have designed and implemented a few languages: including a Scheme-ish 
mostly functional language [but lacking macros].   I have not thought 
through all the nuances of implementing a language that can reflectively 
manipulate the structure of a program in the midst of compiling it  [or 
in the case of Lisp - running it].  However, I have to think there are 
reasons for existing indentation languages not having done so.


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/e92ee43b-5d6c-000d-dc04-25fe76149284%40comcast.net.


Re: [racket-users] Reducing parentheses without language damage.

2020-05-01 Thread George Neuner



I haven't followed all the discussion regarding a potential successor to 
Racket.  AFAIHS, no one actually has suggested a required indentation 
scheme ala Python, but since source indentation (and formatting in 
general) currently is under discussion, I wanted to make known my 
feelings on the matter.


If you don't feel strongly about source indentation, you can skip this.

George


On 5/1/2020 1:19 PM, Christopher Lemmer Webber wrote:

Sorawee Porncharoenwase writes:

>
>> I hate being at the mercy of whatever editor I'm stuck using.
>
>
> I agree with this in principle, but in practice, it's really a matter of
> what mainstream editors support. Editors in the past don't universally
> support automatic indentation, and I could imagine a criticism like
> "Indentation sucks, because I hate being at the mercy of whatever editor
> I'm stuck using." But now, automatic indentation is universal, and the
> criticism goes away.

You don't even need to imagine it... when Python was taking off, one of
the biggest arguments was that it forced people to learn to do
reasonable indentation.  Doesn't seem like as much of a good argument
now as I thought it was then, and that's partly because most code is
indented fine these days due to, as you say, good IDE support.


The indentation requirement - aka "significant whitespace" - is one of 
the main things I dislike about Python [the other is its comprehension 
syntax].  An argument certainly can be made for advocating a readable 
coding style ... but on principle I disagree with a language *requiring* 
any particular style.



As it happens, I am old enough to remember when Fortran required very 
particular formatting: worse even than Python, Fortran was designed 
around 80-column punch cards, and for a VERY long time it was necessary 
that particular things be placed in particular columns ... else the 
statement would not compile.


    see https://web.stanford.edu/class/me200c/tutorial_77/03_basics.html

Fortran's adherence to rigid source formatting really did not simplify 
the compiler much at all  (actually an argument can be made that it 
unnecessarily complicated recognizing certain constructs). And if it 
ever helped, it wasn't necessary for long - by 1962 [Fortran was 
introduced in 1959] compilers were able to deal with free form code.  
The first version of Lisp [1961] was on punch cards as well, but from 
the beginning Lisp never had column based restrictions on source format.


Fortran ... still recognizes the old style, but ... no longer requires 
column based formatting.  Free form source has been supported by 
compilers since Fortran90.


Historically, there have been a handful of (higher level, non-assembly) 
languages that had odd source formatting requirements, but none were as 
onerous as Fortran, and none of them survived very long.  But just as 
Fortran finally was giving up on the idea, Python came along to revive 
it.  [Python began at about the same time Fortran90 was in committee.]



Forcing programmers to do menial tasks like configuring editors to 
certain modes [spaces vs tabs], and to manually count spaces when 
corresponding scoped lines are too far apart to eyeball the vertical 
alignment is simply counterproductive - there are plenty of more 
important things that programmers should be worrying about. Programming 
editors having language structural awareness have been around since the 
80's ... there is no reason ever to bake such things as indentation 
requirements into the language.


Just my 2 cents.

--
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/e180703e-6e2e-ea6b-d918-b46ff4eebb07%40comcast.net.


Re: [racket-users] Reducing parentheses without language damage.

2020-04-30 Thread George Neuner


On 4/30/2020 5:40 PM, Sorawee Porncharoenwase wrote:

  :
To clarify what I mean: non S-exp languages usually have a line as a 
unit of code, so editors need to support "jump to the beginning/end of 
line"  to make editing pleasant.


Actually, in the majority of programming languages there is no 
connection between program source and line grouping in an editor. 
Statement based languages define some character to be the statement 
"terminator" (or statement "separator" - yes, there is a semantic 
difference), but most often that character is the semi-colon, not 
#\return or  #\linefeed.


Racket, like Scheme and Lisp, is expression based, NOT statement based, 
and it can't do the same (at least not easily) because expressions can 
be nested arbitrarily, and they can't be limited to a single line.



S-exp languages in contrast has a parenthesized expression as a unit 
of code, so editors need to support "jump to a matching parenthesis" 
to make editing pleasant. In your notation, it looks like editors need 
to also support "jump to closest /" to make editing pleasant.


Also, does it actually make code more readable? I guess I'm not 
accustomed to it, and might find it easier to read it once I am.


Once you use Racket (or Scheme or Lisp) long enough, you cease to see 
the parentheses and instead perceive the structure of the code from its 
indentation.  Most editors will happily match parentheses and many can 
understand Scheme structure enough to properly indent things.


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/c49cbf7a-c66b-88ed-5e6f-489a1c075009%40comcast.net.


[racket-users] Re: Reducing parentheses without language damage.

2020-04-30 Thread George Neuner
On Thu, 30 Apr 2020 11:16:10 -0400, Hendrik Boom
 wrote:

>I stongly recommend that we get a language with less of a 
>parenthesis problem so that code is readable without having to haul 
>it into a specialised editor.
>
>It is possible to do this without creating a hugely complicated and 
>unintuitive syntax for the language!  We don't need to savage 
>the language to accomplish this!

ML and Haskell both look very similar to what you seem to want.  So
does Python for that matter.

But it isn't possible to write integrated, reflexive macros in any of
those languages.  They DO allow macros (of a sort), but their macros
have to be written using a different, more restrictive language ...
ie. you don't write an ML macro in ML, you write it in the subset
language M(acro)ML.

Consequently, macros are not used heavily in any of those languages.
And use of DSLs with those languages are rare.


If you look at the history of Lisp, you'll see that originally it was
intended to have a more conventional syntax: the S-expr parenthesis
laden syntax we still use was intended as a stopgap until the
conventional "M-expr" syntax could be implemented.  But macros proved
to be very difficult to adapt to the M-expr syntax, and macros were so
important to Lisp that they caused McCarthy to abandon the idea of
M-exprs.

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/hvrlafdq67djfk04p10i7teekn0m2pa4kb%404ax.com.


[racket-users] Re: Rhombus project plan

2020-04-29 Thread George Neuner
On Wed, 29 Apr 2020 21:38:49 +0200, Dexter Lagan
 wrote:

>Thanks so much for your reply, it's very nice to see another perspective. I
>added specific comments below :
>
>They say that Racket is slow. I would like to know who are "they".
>>
>
>  Same here, never had a problem, but I do understand there may be
>requirements for real-time apps and system programming. Everything I said
>about performance really should be put into the context of wider
>acceptance. I don't look at benchmarks, but all of my colleagues do, and
>that deeply saddens me. Being a better tool isn't necessarily just being a
>faster tool, but performance attracts people and businesses.

My suspicion is that they are comparing to something like Python's
IDLE, which in fairness IS more responsive than DrRacket ... but it
also does much less.  

It might be interesting to compare DrRacket built with RacketCS and
see if its performance is significantly different.


>  If there was two things I'd love to look at, performance-wise - and they
>aren't related to Racket itself - it would be the 2-3s lock-up I get after
>opening DrRacket. I can type a line of code, and everything locks up for a
>few seconds before I can type again. It's nothing big, but it's so annoying
>that I'm considering downloading the source tree and hack at it. 

I can't say for certain, but I think it's due to garbage collection.
DrRacket pulls in and JITs a lot of code at startup. If you watch the
memory use (at the bottom), you'll see that after startup it increases
for quite a while (~10 seconds on my machine) before peaking and
falling back to some "base" level (that it never goes below).  If you
start typing before the memory use stabilizes, it seems triggers a
major collection.


>The other
>problem I'm encountering is the relatively slow scrolling / navigation,
>again in DrRacket. I usually disable all the plugins, and sometimes even
>debugging to get smoother performance.

I haven't noticed this particular problem, but perhaps my typical
source files aren't large enough to manifest it.


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/fcbkaf97b1lrmbqfd6s02t3q5mfh34kpbf%404ax.com.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-08 Thread George Neuner


On 4/8/2020 6:09 PM, Brian Adkins wrote:


Thanks for the info George. Are you feeding that entire template 
(after substituting the @ variables) into the smtp-send-message 
function as the message argument i.e. a list of lines?


Yes.


I'm also curious about having "subject" in the template vs. the header.


History.  When I first did this (many years ago) there was an issue with 
/standard-message-header/  screwing up the line breaks, and the 
resulting message being formatted incorrectly if there was a non-empty 
subject string.


I am sure this has long been fixed, but at the time I started 
constructing my own header strings using /insert-field/  from the 
net/head library.  Message[*] headers can be in any order - they need 
only to precede the body - so it didn't really matter where the subject 
line came from, and since the subjects were static for most of my 
messages, it was simplest to just put them into the message templates.


[*] Note that embedded MIME multipart headers DO have defined order.


I take it from your reply there isn't already something in existence 
that streamlines this process in a similar way to a framework such as 
Rails.


Don't get me started on Rails  8-(  Makes easy things easy and hard 
things damn near impossible.



There's nothing in Racket for MIME that I'm aware of ... but then 
multipart formatting is needed only for multi-version messages, or for 
embedding non-text data (graphics, etc.) into a message.   Since so many 
people read mail in web browsers, and most offline clients handle HTML, 
I don't think many people even bother with multi-version messages any 
more.  Sending plain HTML is as easy as sending plain text.


Multipart formatting is recursive and parts can be nested arbitrarily, 
so handling it all properly could be complicated given the need to 
integrate with other code generating the message body (HTML, etc.) 
within.  It's doable ... I just never got the urge to tackle it.


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/93536d3e-28be-bb37-4ad1-e92d29a573c5%40comcast.net.


Re: [racket-users] Examples of sending HTML email w/ Racket?

2020-04-08 Thread George Neuner


On 4/8/2020 12:54 PM, Brian Adkins wrote:
I was able to write a simple wrapper around smtp-send-message and get 
it working through SendGrid in a few minutes (see below), but I wasn't 
able to find any examples of sending emails containing both a plain 
text version and HTML version. Can anyone point me to some examples?


Thanks,
Brian Adkins


You done the hard part.  Once you can send a plain text message, HTML is 
not much harder.


You have to construct a MIME multipart message, which has a particular 
internal structure.

See:
https://stackoverflow.com/questions/10631856/mime-type-to-satisfy-html-email-images-and-plain-text
http://www.enewsletterpro.com/articles/multi_part_mime_messages.asp
https://www.ietf.org/rfc/rfc1521.txt


My solution is to use message templates like the attached - which shows 
using not just multipart but also embedded graphics.  My program 
customizes the message by substituting for the '@' preceded "variables" 
in the template.  Feel free to (ab)use the same style or adapt it for 
your needs.


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/b58bf51b-e970-1c54-bb24-e08996e43849%40comcast.net.
Subject: confirm password reset
MIME-Version: 1.0
Content-Type: multipart/alternative;
  boundary="__ALT__"

This is a MIME-encoded HTML message. If you are seeing
this text only section, your mail program either is too
old or is not configured properly.


--__ALT__
Content-Type: multipart/related;
  boundary="__REL__"

--__REL__
Content-Type: text/html; charset=us-ascii
Content-Disposition: inline
Content-ID: 



@USERNAME,

A request has been received to reset your password
   
   If you wish to reset your password, please confirm by
   clicking on the link below. Shortly you will receive
   another email containing a new password .
   


Reset My Password



   Message sent at @SEND_TIME on @SEND_DATE.
   Links will expire at @LINK_TIME on @LINK_DATE.
   If you believe you have received this message in error,
   Please contact technical support and reference @REFERENCE.
   




--__REL__
Content-Type: image/jpeg
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-ID: 

  base64 encoded logo image goes here
  reference in body as 

--__REL__
--__ALT__--


Re: [racket-users] Are there interfaces for IP ports at least raw sockets?

2020-04-02 Thread George Neuner



On 4/2/2020 1:45 PM, David Storrs wrote:

On Thu, Apr 2, 2020 at 1:32 PM George Neuner  wrote:
>
> ... it is because of Windows that Racket doesn't provide raw (or Unix)
> sockets.  Racket tries to support all of its features across all target
> platforms.

I mean...Racket tries to be memory-safe etc, but it also has libraries
like 'unsafe/foo'.  There's already a unix-sockets library
(https://docs.racket-lang.org/unix-socket/index.html) that is
Unix-only, which I found after starting this thread.  Why not have
core modules like unix/sockets and windows/thing-that-only-windows-has
?  Seems more useful than simply not having the functionality at all.


Well, I'm not on the development team, so I can't speak for them. But, 
IMO, things which don't work everywhere do not belong in the core -  
they belong in contributed libraries ... which is where you found the 
*nix-only library.


However, since (IIRC) 1803, Windows 10 does have a partial 
implementation of Unix sockets which provides SOCK_STREAM service only 
(no DGRAM or SEQPACKET) ... but there is no mention of this in the 
platform docs (docs.microsoft.com), and AFAIHS only a few developer 
blogs have described how to get at it: e.g.,

https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/
https://devblogs.microsoft.com/commandline/windowswsl-interop-with-af_unix/
https://github.com/MicrosoftDocs/WSL/tree/live/wsl-samples/afunix-wsl-interop/windows_server


I haven't tried to use Unix sockets on Windows, but I did check that the 
"afunix.sys" driver is present on my 1903 system.  [And yes, I know 2003 
is due imminently ... as Scooby would say "rotsa ruck".]


Presumably the existing library could be extended to work on recent 
versions of Windows 10, but that wouldn't help anyone still running 
older versions.  Or Windows 8.1.  Windows 7 is EOL'd, but Windows 8.1 
will be supported until 2023, so excluding it might pose a problem.


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/0f5abe26-dd9d-bf25-8234-a8d22b60feaa%40comcast.net.


Re: [racket-users] Are there interfaces for IP ports at least raw sockets?

2020-04-02 Thread George Neuner



On 4/2/2020 1:00 PM, David Storrs wrote:

On Thu, Apr 2, 2020 at 12:37 PM George Neuner  wrote:
>
> Windows historically placed a lot of limitations on the use of raw sockets.
> https://docs.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2
>
> There doesn't seem to be any updated information on Win10, so you might
> conclude that it has the same limitations as Win7.

Doesn't surprise me.  Fortunately, I don't need it for Windows, at
least right now.


But it is because of Windows that Racket doesn't provide raw (or Unix) 
sockets.  Racket tries to support all of its features across all target 
platforms.




> Re: ICMP, I think it should be possible to implement at least some of
> the functions (not sure about all of them) ... but it will have to be
> done via FFI.

Cool thanks.  Do you happen to know what library I should be FFI'ing
into, ideally for macOS?


Sorry, I don't know MacOS.  In Unix it would be libsocket, and if you 
are using GCC then glibc transitively links libsocket and re-exports the 
entire socket API.


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/2405a32b-1095-0888-6b06-41d97b7d2ef2%40comcast.net.


Re: [racket-users] Are there interfaces for IP ports at least raw sockets?

2020-04-02 Thread George Neuner



On 4/2/2020 11:13 AM, David Storrs wrote:

The Reference lists TCP and UDP but nothing else.  I'd like to be able
to implement ICMP, since there doesn't seem to be such a thing at the
moment, and I'm trying to figure out how to do that.

In an ideal world I'd have something like ip-in and ip-out ports as
the complement to tcp-in and tcp-out ports and then I could simply
hand the ip-out port some bytes that constitute an ICMP or etc packet
and away it goes.  Failing that, if I can get a raw socket then I
could do the IP stuff on top of it; with that in hand it would be
(more) straightforward to implement other protocols.

Is there a way to do this in Racket?


Windows historically placed a lot of limitations on the use of raw sockets.
https://docs.microsoft.com/en-us/windows/win32/winsock/tcp-ip-raw-sockets-2

There doesn't seem to be any updated information on Win10, so you might 
conclude that it has the same limitations as Win7.



Re: ICMP, I think it should be possible to implement at least some of 
the functions (not sure about all of them) ... but it will have to be 
done via FFI.


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/bc77f87f-378c-6d5c-3875-3270cb25134b%40comcast.net.


Re: [racket-users] How to compile static racket binaries

2020-04-02 Thread George Neuner



On 4/2/2020 10:24 AM, Matthew Flatt wrote:

At Thu, 2 Apr 2020 06:28:00 -0700 (PDT), Tristram Oaten wrote:
> I've compiled it on ubuntu 19:10, and am running into this problem on 
> ubuntu:latest (18.04), due to the different versions of libc.


Ah, I didn't realize that the C library version had changed in recent
Linux distributions. (It had been the same for several years.) That's a
pain.


AFAIK, Ubuntu 19.10 is using glibc 2.30.

Version 2.30 (Aug 2019) fixed some privilege elevation and unwanted code 
execution vulnerabilities dating from 2.26.  Also fixed a data 
corruption issue with memmove introduced in 2.28 (in 2018).


https://www.gnu.org/software/libc/
https://www.cvedetails.com/vulnerability-list/vendor_id-72/product_id-767/GNU-Glibc.html

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/96eb0d5f-db44-331d-7892-81ebbf37bb74%40comcast.net.


[racket-users] Re: How to compile static racket binaries

2020-04-02 Thread George Neuner
On Thu, 2 Apr 2020 06:28:00 -0700 (PDT), Tristram Oaten
 wrote:

>My use case is trying to get binaries into a container for deployment.
>
>I've compiled it on ubuntu 19:10, and am running into this problem on 
>ubuntu:latest (18.04), due to the different versions of libc.
>If I run on ubuntu:19.10, it works as expected, but that's too brittle for 
>my liking.
>
>I'm keen find a way to statically-link libc, in the way that gcc, rust, go 
>etc can do it. 

Is there a reason that you can't put the (actually linked) C library
into the container with the application?

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/dtrb8fdi23tr5u0f6inj45tnfe5m1fs8vv%404ax.com.


[racket-users] Re: questions about top-level-bind-scope in root-expand-context

2020-03-23 Thread George Neuner
On Mon, 23 Mar 2020 16:57:26 -0400, Hendrik Boom
 wrote:

>On Mon, Mar 23, 2020 at 02:46:53PM -0400, George Neuner wrote:
>> On Mon, 23 Mar 2020 01:45:40 -0700 (PDT), Yongming Shen
>>  wrote:
>> 
>> >I have the following as `module-that-defines-fib`:
>> >
>> >  #lang racket
>> >  (provide fib)
>> >  (define fib "fib")
>> >
>> >And this is the error that I got (using Racket 7.6):
>> >
>> >  ; application: not a procedure;
>> >  ;  expected a procedure that can be applied to arguments
>> >  ;   given: "fib"
>> >  ; [,bt for context]
>> 
>> 
>> I've run into this problem before ... I don't recall the official
>> explanation, but my takeaway was that Racket does not permit you to
>> directly *export* a value - you have to export a function or macro
>> that produces the value.
>
>That seems like an extremely arbitrary restriction.

Well, Racket considers exported objects to immutable.  You can export
a simple value (e.g., "foo" or 42) but it can only be used as a
constant.  If what you need is a module variable then the only way to
expose it is via an access function.

AFAIHS, the OP has not shown us the code which uses the provided
object, so we really don't know what it was trying to do when the
error occurred.

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/p9bi7fpigiqm3tc3togm4vmontlv5v70ti%404ax.com.


[racket-users] Re: questions about top-level-bind-scope in root-expand-context

2020-03-23 Thread George Neuner
On Mon, 23 Mar 2020 01:45:40 -0700 (PDT), Yongming Shen
 wrote:

>Hi Matthew,
>
>Thank you for the quick reply!
>
>I tried the example you gave for my first question and it resulted in an 
>error.
>I have the following as `module-that-defines-fib`:
>
>  #lang racket
>  (provide fib)
>  (define fib "fib")
>
>And this is the error that I got (using Racket 7.6):
>
>  ; application: not a procedure;
>  ;  expected a procedure that can be applied to arguments
>  ;   given: "fib"
>  ; [,bt for context]


I've run into this problem before ... I don't recall the official
explanation, but my takeaway was that Racket does not permit you to
directly *export* a value - you have to export a function or macro
that produces the value.

E.g., 
  #lang racket
  (provide fib)
  (define (fib) "fib")


>I think this is because `(define-values (x) ...)` expands `...` without the 
>top-level-bind-scope, even when expand-context-to-parsed? is #t (according 
>to expander/expand/top.rkt). Is this a bug?
>Related to your answer to my second question, `define-syntaxes` similarly 
>does not add the top-level-bind-scope when expanding `...`. Does this mean 
>that even for `define-syntaxes`, `...` won't use the top-level-bind-scope 
>binding(s) after all?
>
>A little bit off-topic, in the definition of define-values (in 
>expander/expand/top.rkt), there is `(define-match m s ...)`, but for 
>define-syntaxes it is `(define-match m disarmed-s ...)`. Is this difference 
>significant? Or does define-match not care whether `s` or `disarmed-s` is 
>used?

I don't know the internals so I can't evaluate your theory.


>Thanks,
>Yongming

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/2l0i7flr0to9msl6sg165vptiec0qq26l7%404ax.com.


[racket-users] Re: re-run really fast!

2020-03-04 Thread George Neuner
On 5 Mar 2020 01:25:09 -0500, "'John Clements' via users-redirect"
 wrote:

>Okay, I’m probably under a rock and just haven’t read my e-mail in a
>week, but … I just noticed that re-running a long TR file of 900
>lines took ONE second, rather than eleven. It appears to me that
>either TR or DrRacket or both are now cooperating to not re-compile
>when no edits have been made. Is that a recent change, or am I just
>easily pleased?
>
>John

Perhaps "easily surprised"?  Racket has long had the option to cache
compiled modules and use them if their source has not changed.  

You get this either by running "raco make ..." from the command line,
or, in DrRacket in the 'Choose Language' dialog by selecting the
option to 'Populate "compiled" directories (for faster loading)'.


Not recompiling all the time can be a big time saver.

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/kt816f9b3f7oehhjdcv9020r2hv6m0vhi3%404ax.com.


Re: [racket-users] Lambda calculus done in Racket

2020-02-17 Thread George Neuner


On 2/17/2020 12:12 PM, Lawrence Bottorff wrote:

I found these blowing down the sidewalk today

; TRUE = λx.λy.x
(define mytrue
  (lambda (t) (lambda (f) t)))

and

; FALSE = λx.λy.y
(define myfalse
  (lambda (t) (lambda (f) f)))

Two problems, I don't understand them and AFAICT, they don't work. I 
traced them back to this 
 
post on stackoverflow. Can anyone get me started here?


LB


In addition to Ricardo's good answer:

The definition of TRUE above is one of the combinators of the S-K-I 
combinator calculus, which is a simple to understand subset of the 
untyped lambda calculus.  Programs in S-K-I are expressed as sequences 
of 3 simple combinators, and computation is done by repeated expansion, 
application and reduction until an irreducible form - the result - is 
reached.


https://en.wikipedia.org/wiki/SKI_combinator_calculus

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/56ba86fe-c379-3127-d8b2-ba70078380e2%40comcast.net.


Re: [racket-users] subprocess failure (Windows-specific ?)

2020-02-08 Thread George Neuner


On 2/8/2020 8:58 AM, Bertrand Augereau wrote:


The 1st value returned by (subprocess) is an opaque reference to
the executing process.  If you pass the reference to
(subprocess-status) it will return *'running*  if the process
currently is executing, or the exit/error value.


"exit/error value" is the issue there.
(subprocess-status ps) will return 'running if the process is running.
If it doesn't, either the process has never ran, either it has 
finished with a exit code.

No way (that I see) to disambiguate.


I'm not sure I completely understand the problem.  You're correct that 
there's no way to tell whether the value is an exit code from the 
program or an error from the operating system ... but there also is no 
way to tell that starting the program from the shell  IF  you rely 
solely on the exit code.


But if the idea is to tell whether the program started correctly - even 
if it since has ended - then something like:


   (or
  (eq? 'running (subprocess-status ps))
  (not (= 0 (subprocess-pid ps)))
  )

should do the trick.


(subprocess-pid) is only valid when (subprocess-status) is 'running 
but testing the status then requesting the pid is not atomic, 
therefore subprocess-pid should return #f or raise. Or return pid 0 
but it should be documented :)


It does return 0 if the program never started.

I won't argue about documentation, but I will note that the Racket 
"process" object retains the assigned pid value even after the process 
terminates ... so testing whether it is running before retrieving the 
pid does not seem to be a real burden.  Do you have a use case where 
this matters?



By the way there is a process with pid 0 on Linux, it's "sched". And 
on Windows, its "idle". Of course it could never be the result of 
(subprocess ...) but I don't want to rely on incidental behaviour from 
an API :=


Those are not processes - they are kernel functions called when no 
actual process is ready to run.  They consume time and CPU cycles, so 
they are included in the process listing, but they really are just 
system overhead.  When the OS is in one of these functions it is 
sleeping waiting for either a timer tick or an I/O completion.


And pid 0 will never be assigned to a real process.




Hope this helps,
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/8e8fa61b-92b4-b58a-5601-d7197a04ba84%40comcast.net.


Re: [racket-users] subprocess failure (Windows-specific ?)

2020-02-08 Thread George Neuner


On 2/8/2020 3:37 AM, Bertrand Augereau wrote:

  :
I spawn my subprocess with subprocess : 
https://docs.racket-lang.org/reference/subprocess.html
And for the sake of completeness I want to know when suprocess failed 
(because the users tampered with the exe, because there's an ACL 
issue, whatever).
The function doesn't have a return value for failure and it doesn't 
raise an exception when I do stuff like

(subprocess "no exe here")
or
(subprocess "nice picture of an aardvark.png")
It only returns a seemingly valid value.


The 1st value returned by (subprocess) is an opaque reference to the 
executing process.  If you pass the reference to (subprocess-status) it 
will return *'running*  if the process currently is executing, or the 
exit/error value.



Can someone help me ? Is it an API defect and a special value should 
be returned ? Should an exception be raised ? The doc doesn't say much 
about this.


A special value is returned - the opaque reference.  Perhaps the docs 
could use a simple example of how to use the functions effectively.  Try 
playing a bit with the following:


   #lang racket

   (define sub #f)

   (let [
  (name "C:\\WINDOWS\\system32\\notepad.exe")
  (in #f)(out #f)(err #f)
 ]
  (set!-values (sub out in err) (subprocess #f #f #f name))
  )

   (subprocess-status sub)
   (subprocess-pid sub)

   (subprocess-wait sub)
   ;; close subprogram here

   (subprocess-status sub)
   (subprocess-pid sub)



I don't really care about the OS-level cause of the failure but I need 
to know if it failed.

I didn't test on my Linux box for consistency.

By the way, subprocess-pid returns 0 on such a "never spawned" 
process, and I think it should be an error case too.


No actual process can have pid 0 ... that value is reserved  (on 
Unix/Linux and Windows).


Racket doesn't support fork (because Windows doesn't), but recall that 
when you fork in Unix/Linux, the child process receives the illegal pid 
value 0 so that it knows it is the child, while the parent receives the 
real pid value for the child.


Also note that (subprocess-pid) will be valid only if the process 
started successfully.



Hope this helps,
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/447df58e-66ba-49aa-8151-7a8abd943090%40comcast.net.


Re: [racket-users] keyboard shortcuts in a popup menu

2020-01-22 Thread George Neuner



On 1/22/2020 4:44 PM, James Platt wrote:

I'm working on some GUI code and I am seeing some glitches with keyboard 
shortcuts in popup menus.  I wonder if others are seeing the same things.

In Racket 7.5 on macOS 10.11.6 "El Captian":
Shortcuts defined in a menu-item% in a popup menu don't work unless the popup 
menu is displayed. In other words, you have to right click first and then the 
shortcut will work while the menu is open.  This isn't a big deal if you are 
working according to Apple's human interface guidelines because all items in 
popup menus are also supposed to be in the main menu bar [1].   Still, it seems 
like this should work on it's own.


It's pretty standard across platforms for popup windows (any kind) to 
become inactive when they are hidden.  In most windowing systems it is 
possible to override that behavior and keep a window active even when 
not shown, but I haven't worked with Macs since MultiFinder so I can't 
guide you as to how to do it there.




In Racket 7.5 on Linux Mint 19.1 (Racket installed with the Ubuntu PPA):
The shortcuts don't work at all, whether the popup is displayed or not.  Also a 
keyboard shortcut defined with '#\backspace'  does not display in the popup.  
This  is supposed to be ctl-backspace on Linux and Windows and command-delete 
on macOS.  The macOS version works but not the Linux version.  I haven't tested 
with Windows.


This sounds like a bug.



James

[1] 
https://developer.apple.com/design/human-interface-guidelines/macos/menus/contextual-menus/


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/d40267d2-f8f3-3083-c8ec-b2ae3d099d32%40comcast.net.


[racket-users] Re: file-position in Win32 not working beyond 1 GB

2020-01-02 Thread George Neuner
On Wed, 1 Jan 2020 15:50:10 -0700, Matthew Flatt
 wrote:

>The release builds and that special build are cross-compiled using
>MinGW. The one that doesn't run from the Utah snapshot is built with
>MSVC 2017. I think that must be the difference, with modenr MSVC doing
>something to the executable that XP doesn't recognize.

IIRC VS2015 could build for XP if some extension was installed: it
produced an execuable that could run with the VS2013 library.  

I'm pretty sure VS2017 and later don't support XP at all.

VS2013 will work for XP assuming that the code doesn't require any
functions that are only in later systems.  Maybe someone has a copy
that they can donate?

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/sk6s0flo8848cpdqpbptu38vte7oth63eo%404ax.com.


Re: [racket-users] Can I somehow connect to and update values in a specific hash table used by a running web server?

2019-12-23 Thread George Neuner



On 12/21/2019 9:25 PM, Matt Jadud wrote:
My off-list thought (which was largely because I wasn't sure it would 
even work) was to run a second web server on another port that was 
bound to localhost. Then, SSH onto the localhost when needed, and 
squirt values into the locally bound webserver as needed. Depending on 
the server config (e.g., you're the only one on it) would make this 
reasonably secure. (If someone got onto your host, you probably aren't 
worrying about the hash table of parameters...)


Certainly you can run a 2nd web server on a different port, but IMHO 
that is overkill.


I use shared secrets to secure my setting page:  a hidden parameter 
whose value is a cryptohash of a shared pass-phrase.  If that parameter 
isn't present, the web server returns "unknown URL" rather than the 
setting page.


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/253b8bc1-842c-e3df-ae45-cedd7f4e2fce%40comcast.net.


Re: [racket-users] Change error message of web server continuations from "Sorry, this page has expired. Please go back."

2019-12-23 Thread George Neuner



On 12/23/2019 6:54 AM, Marc Kaufmann wrote:

By the way, where does it say that the default is 130MB?


In the docs for serve/servlet.

Can I set the instance-expiration-manager to #f and that is the place 
where it generates the 'Sorry, this page link has expired' error? So I 
could provide a more meaningful error message there? Or better not, 
since it does more work behind the scenes?


I don't know if you can set the handler to #f.  But you can replace it.

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/758e97d9-e948-0baf-24ec-505ea56442a6%40comcast.net.


Re: [racket-users] Change error message of web server continuations from "Sorry, this page has expired. Please go back."

2019-12-21 Thread George Neuner


On 12/21/2019 4:38 AM, Marc Kaufmann wrote:


Did you perhaps change the continuation manager - or its setup?

https://docs.racket-lang.org/web-server/servlet.html?q=ffi#%28part._managers%29





No, not really. I simply import send/suspend/dispatch etc and use them 
without doing anything in particular. I am requiring them within 
typed/racket if that matters via require/typed. So I have no idea 
where to configure the continuation manager - I don't even know where 
the current one is.


If you started from serve/servlet - and didn't specify differently - 
then you are using the default LRU continuation manager.   If the load 
spikes, it will drop saved continuations to get memory use back under 
control.


 * 
https://docs.racket-lang.org/web-server/run.html?q=serve%2Fservlet#%28def._%28%28lib._web-server%2Fservlet-env..rkt%29._serve%2Fservlet%29%29
 * 
https://docs.racket-lang.org/web-server/servlet.html#%28def._%28%28lib._web-server%2Fmanagers%2Flru..rkt%29._make-threshold-.L.R.U-manager%29%29


You can specify to use a different manager (including a custom one) in 
the call to serve/servlet.



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/f974666a-3e1a-3cd8-d371-09e9a283a157%40comcast.net.


Re: [racket-users] Can I somehow connect to and update values in a specific hash table used by a running web server?

2019-12-21 Thread George Neuner


On 12/21/2019 4:44 AM, Marc Kaufmann wrote:
one useful feature of the Django web framework is that it is easy to 
access the database and change it on the fly. I am not using a DB, but 
a hash inside of Racket for various reasons. I understand that it 
would be easy to connect to a database in any language, and getting 
the hash is a different beast - but I am wondering if there is an easy 
way such that I could tell the racket web server via a command line or 
REPL interaction "(update-user uid key-name new-value)" or some such.


Is that easily possible? (And very secondarily: Is this a stupid idea? 
But even if it is, it's what I am under time pressure to get working, 
as a proper solution ain't gonna happen in time.)


Running a REPL inside your program is fairly easy but not terribly 
safe.  E.g., you can dedicate a thread to reading a network port and 
executing whatever code fragments you send.  But you need to take 
precautions, limiting what it is allowed to do, and who can access it, 
so unauthorized users can't screw up your program.


In my apps I make hot tweak settings available through a secured web 
interface.  The "variables" are functions exported from my configuration 
module (similar to the way parameters work).


   (define-syntax getter/setter!
  (syntax-rules ()
    ((getter/setter!)
 ; -- start template

 (let [(var null)]
   (lambda x
 (cond
   ([null? x] var)
   ([pair? x] (set! var (car x)))
   (else (error))
   ))
   )

 ; -- end template
 )))

   (define some-config-var (getter/setter!))


Then /(some-config-var )/  changes the value, and 
/(some-config-var)/  gets the current value.


It's simplistic, but it works well.  I haven't run into the need for 
more explicit synchronization, but if needed it would be simple to add a 
semaphore / mutex to the macro.


During program execution I can tweak these "variables" using a special 
HTML page that lets me review and set many variables all at once.  But 
it could be done using a bunch of simple handlers - one per variable - 
that could be command line driven using curl.



In your case, you could create an "update-user" URL handler that updates 
your hash from its arguments.  If you give it an hard to guess name and 
don't document it, then it may be reasonably safe.


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/b3a4de57-9b40-faa3-651b-b5efa08329a4%40comcast.net.


Re: [racket-users] file-position in Win32 not working beyond 1 GB

2019-12-20 Thread George Neuner



On 12/20/2019 6:59 PM, Matthew Flatt wrote:

At Fri, 20 Dec 2019 23:39:30 +0300, Dmitry Pavlov wrote:
> > The Racket-imposed limit should be 64 bits (more than enough) on all
> > platforms. I can try to replicate the problem later today, but more
> > information on the error message would be helpful.
>
> I do not have access to that Windows 7 machine until Monday.
> I managed to reproduce the problem, though, on a 32-bit Windows XP with 
> Racket 7.1.
> 
> file-position: new position is too large

>    port: #
>    position: 1122398240

I'm not able to replicate the error on a fresh(!) 32-bit Windows 7
installation using v7.1 or v7.5. I also don't think it should happen
based on the implementation. So, I'm missing something.


I tried with 32-bit  7.3, but I also could not create a ~1GB file 
position size error.



One strange thing I did notice though:
My 32-bit Racket happens to be on a 64-bit Win10 host.  I dashed off the 
little test program below, then compiled it to a (13MB) distribution 
executable for the 32-bit Win7 machine (which does not have Racket 
available).  When I tried it, I was quite surprised that it took over a 
minute to run.  I deleted the data file and ran it again, this time 
monitoring the file size in Explorer.  The file began small and steadily 
increased in size until the program ended. Being curious, I then tried 
the executable on the 64-bit Win10 machine and got the similar results - 
it ran faster, but still took much longer than I expected.


Is Racket really writing billions of zeroes rather than creating a 
sparse file?  It seems to me that this file should only create 2 actual 
data blocks, and (modulo JIT) the program should finish almost 
instantly.  What am I missing?


George

  -
#lang racket

(define (fout) (current-output-port))

(with-output-to-file "test.dat"
  (lambda ()
    (write "hello")
    (file-position (fout) (* 3 1024 1024 1024))
    (write "there")
    )
  #:mode   'binary
  #:exists 'can-update
  )

--
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/c27936fd-441d-2f0d-7ae6-9ea4701e9ae1%40comcast.net.


Re: [racket-users] file-position in Win32 not working beyond 1 GB

2019-12-20 Thread George Neuner



On 12/20/2019 2:49 PM, Dmitry Pavlov wrote:
I would have understood maximum the limit of maximum signed integer 
2^31 = 2 GB (and my program would be fine with 2 GB limit).
meant to be "I would have understood the limit of maximum signed 
integer ..."




The fixnum tag is just 1 bit, but you are forgetting about the sign.  32 
- 1 (tag) - 1 (sign) = 30.


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/8725ca1a-460c-f7bd-cd9d-b6e608783676%40comcast.net.


Re: [racket-users] Change error message of web server continuations from "Sorry, this page has expired. Please go back."

2019-12-20 Thread George Neuner



On 12/20/2019 8:45 AM, Marc Kaufmann wrote:
reading a past thread started by me, I realize that I should have 
learned how to implement Philip's advice on using stateless 
continuations, but well I didn't. So I still use vanilla 
`send/suspend/dispatch` and hence my users hit the "Sorry, this page 
has expired. Please go back." The quick fix is to tell them that they 
should go to page xyz.com. But I don't know how I can easily change 
this error message to add a link. Anyone?


I'm about to leave for travel or else I would have done some digging 
around.


PS: For some reason I keep hitting these errors faster than in the 
past - as in, within a few minutes. Any idea why that might be and how 
to increase the time? I can crank up the RAM of the machine too, 
anything that cuts down on developer time really. I'll be back in the 
new year to actually fix this, but not now.


Did you perhaps change the continuation manager - or its setup?
https://docs.racket-lang.org/web-server/servlet.html?q=ffi#%28part._managers%29

As to where to put your message: you can install a custom "expiration" 
handler in the continuation manager.  Unfortunately I haven't done this 
in a very long time, so I can't guide you through it.  Perhaps someone 
(Jay?) knows exactly what to do.


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/85246bf7-7ba3-1d21-e6d0-17846a9bd498%40comcast.net.


Re: [racket-users] file-position in Win32 not working beyond 1 GB

2019-12-20 Thread George Neuner



On 12/20/2019 9:39 AM, Dmitry Pavlov wrote:


On a fresh 32-bit Racket 7.5 install on 32-bit Windows 7,
(file-position port number) does not work when number
is more that 1 GB.


On 32-bit machines, the largest fixnum is 2^30  which is 1GB.  I suspect 
that /file-position/  really wants a fixnum rather than a 
non-negative-integer as is documented.




Can I work this problem around somehow?


I don't believe there's a way within Racket.  Potentially you could use 
FFI and drop into Windows own file functions - the 32-bit API contains 
an extended seek function which works with 64 bit offsets.



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/35fa32ff-2c3a-de2b-c06f-fb09208069e2%40comcast.net.


Re: [racket-users] Vector lenght and indices contracts

2019-12-04 Thread George Neuner



On 12/4/2019 11:03 AM, Dominik Pantůček wrote

looking at vector-length[1] documentation, it returns
(exact-nonnegative-integer?). However, as far as I can tell, it returns
(fixnum?). Also for subsequent contracts in the vector's documentation
all indices are assumed to be (exact-nonnegative-integer?) but usually
it is impossible on given platform to use anything larger than (fixnum?)
in reality


You are correct that (exact-nonnegative-integer?) doesn't limit values 
to fixnum range, but the point of using it is more to exclude negative 
values than to allow super large positive ones.


This question - or something substantially similar - has come up 
before.  Your question is about contracts - which can be used from plain 
Racket - but it is noteworthy that typed/Racket provides types for  
positive, negative, nonpositive, and nonnegative fixnums - but there are 
no built-in tests for any of these, so a suitable contract or type 
declaration has to be synthesized using multiple tests.




For example on 64bit platforms the (fixnum?) could store numbers from (-
(expt 2 62)) to (sub1 (expt 2 62)). Vector slots cannot be smaller than
64bits (machine-dependent pointers) which means 8 bytes = 3 bits of
address. Given 64bit (VERY theoretical) size of the address space, this
leaves the possibility of storing a single vector with (expt 2 61)
elements into the memory.

If I did not overlook anything, the contracts could be safely changed to
(fixnum?).


It would be more correct to use  (and/c fixnum? (or/c zero? positive?)) 
to explicitly limit the value.




And yes, I found this issue while cleaning up my futures-sort[2] package
discussed a few months ago here. If I assume
(exact-nonnegative-integer?), I need to manually check for (fixnum?).
Even though it - given the information above - does not really make much
sense.


Should I open a PR?


I don't remember how the previous discussions went.  I'm not sure 
anything ever really was resolved.




Cheers,
Dominik


[1]
https://docs.racket-lang.org/reference/vectors.html#(def._((quote._~23~25kernel)._vector-length))
[2] https://docs.racket-lang.org/futures-sort/index.html


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/295427b5-9390-43b7-b7d5-cf25cce7fd4b%40comcast.net.


[racket-users] Re: Reason why char=? accepts only one argument?

2019-11-25 Thread George Neuner
On Mon, 25 Nov 2019 00:14:45 -0800, Siddhartha Kasivajhula
 wrote:

>Another way to think of it could be to interpret the operator as asking,
>"do the arguments supplied form an equivalence class
>?" If only one argument is
>supplied, then it trivially forms such a class.

What about Common Lisp's /= and char/= functions?  Can nonequivalent
values form an equivalence class?

I note that neither Scheme nor Racket implements these functions.  Is
there some pedagogical reason, or is it simply a practical realization
that "(/= _)" is interchangeable with "(not (= _))" ?


Not a language theorist, just an aging compiler geek.
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/pfunteltm3sm5irkjifvh00r7mien6l1nm%404ax.com.


Re: [racket-users] Reason why char=? accepts only one argument?

2019-11-24 Thread George Neuner



On 11/24/2019 5:30 PM, Jonathan Simpson wrote:


The documentation for char=? leaves the impression that it takes a 
minimum of two arguments:


https://docs.racket-lang.org/reference/characters.html?q=expand#%28def._%28%28quote._~23~25kernel%29._char~3d~3f%29%29

If a single character is passed as argument 1, char=? returns true. To 
me, '=' implies at least two things to compare. The other functions in 
this family appear to behave the same way.


There is a note saying that since 7.0 the functions accept one 
argument. Any reason for this change? At the very least I think the 
documentation could make this clearer(probably because the docs were 
originally written when it required two arguments).


-- Jonathan



I don't know the developers' reasoning, but I can guess.

Predicates already were variadic taking 2 or more arguments (at least 
since R3RS, circa 1986), and they behave like a fold/reduce with an 
implied base/identity value.  I think the idea is that they should work 
with any non-empty list of arguments.


FWIW, Common Lisp's predicates always have behaved in this way.

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/224f2bfe-1ee5-7a49-855f-19c21e202a83%40comcast.net.


Re: [racket-users] Re: GUI (get-directory)

2019-11-19 Thread George Neuner



On 11/19/2019 2:04 PM, pow bam wrote:
Ah thank you very much Hadi.. that indeed worked out nicely and now 
makes alot more sense to me. The documentation structure can be a bit 
confusing/misleading on points like this and I rather wish that they 
would display "real world" usage examples more in-depth in the docs 
for clarity. Again thank you.


You might want to have a look at this page that describes the 
conventions used in the manul:
    "Notation for Documentation" - 
https://docs.racket-lang.org/reference/notation.html



Probably there should be a link to this on the main documentation page - 
or an intro section on "how to read the manual" right up front.   We 
can't reasonably expect novices to know the notation conventions.


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/84161a5d-166b-c369-2d0a-7a671e1dfe18%40comcast.net.


Re: [racket-users] Determining if 2 lists share a common element

2019-11-13 Thread George Neuner



On 11/13/2019 10:11 PM, Andrew wrote:

I have this:

(define (related? a1 a2)
   (if (equal? a1 a2)
   true
   (related? (member (rest ("proc that calls list" a1)) (rest ("proc that calls 
list" a2)))
  (member a1 ("proc that calls list" a2))


a1 and a2 are part of a binary search tree and I have another function that 
creates a list from the elements of the tree

hence the "proc that calls list"


For some reason, whatever input I'm putting into a1 and a2 is returning only 
true, even when I know the answer is suppose to be false

Can anyone guide me onto what's going wrong?



Just guessing, but the empty list is a member of both and all instances 
of '() compare eq?  (same symbol).


   (eq? (list) (list))
   => #t

But if I'm understanding your code correctly, it seems like it would not 
work for lists of different lengths.


I think it would be simpler - and probably faster - to create an (obj -> 
obj)  hash^[1]   using eq? compare from the elements of one list and 
step though the other list checking if the current element is in the 
hash.   Or skip the lists entirely and do it directly from the tree walks.


Hope this helps,
George

[1] 
https://docs.racket-lang.org/reference/hashtables.html?q=hash#%28def._%28%28quote._~23~25kernel%29._hasheq%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/ce899707-40ca-8f36-2841-3670b41e5b74%40comcast.net.


[racket-users] Re: Setting TTL on non-multicast UDP

2019-10-16 Thread George Neuner
On Wed, 16 Oct 2019 15:34:53 -0400, David Storrs
 wrote:

>I'm implementing the port prediction NAT-traversal algorithm[1], part
>of which specifies sending non-multicast UDP packets with very short
>TTLs.  The only method I see in the Racket docs for setting TTL on UDP
>is the udp-multicast-set-ttl! function.  Is there a way to do this for
>regular UDP packets?

More generally, is there a way to set and query socket options?  
I may have missed something, but I don't see any equivalent of
setsockopt or getsockopt.

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/jhcfqepbfkpo77h3uj7c9bpp5fu6aipqui%404ax.com.


[racket-users] Re: Structured Concurrency in Racket

2019-10-10 Thread George Neuner
On Wed, 9 Oct 2019 16:15:14 -0400, Sam Tobin-Hochstadt
 wrote:

>The Racket community, and even more so the design of Racket
>concurrency APIs, is very strongly influenced by the academic side of
>Racket. As far as I can tell, structured concurrency is fairly close
>to what is traditionally called the fork/join model.

To a 1st approximation. There are different implementations of
fork/join.

In some the forking thread stops immediately to wait for the spawned
child(ren) to exit.  In others, the forking thread can continue until
it executes a deliberate join.  

But then there are systems where join implicitly targets all children.
Then there are systems where join implicitly targets the last child
forked and to wait for all children you have to keep executing join
until it fails.  Still others where (like with Unix processes) join
implicitly targets a single child, but you don't know which one will
return and to wait for all you have to keep executing joins.  And
still others where join can be told to wait for a particular set of
children (ignoring others).


Threads in Racket are signaling, and their completion (or death) can
be detected using events or directly using their handles.  So Racket
can easily emulate any of the behaviors above.  Putting a nicer syntax
on it would just be some macrology.

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/neftpe5surndb67v0p2gqgrpklq8bq3jpf%404ax.com.


[racket-users] Re: General ways and concrete examples of approaching web dev

2019-10-09 Thread George Neuner
On Wed, 9 Oct 2019 10:01:34 +0200, Marc Kaufmann
 wrote:

>You don't happen to have a free/cheap (Linux compatible) one to try out? I
>found 10 lists with 'best 6/10/33 db modeling tools', which is 5/9/32 tools
>too many...

  I know what you mean.  

I routinely deploy on Linux, but much of my development work actually
is done on Windows.  Unfortunely, I'm much less familiar with the
state of DBMS tools on the Linux side.

There are some well respected programs that have Linux versions, but
many/most of them will require JVM and JDBC drivers for your DBMS ...
which may make their installation a bit tricky.  I've seen plenty of
issues with JVM software on Linux - some programs just aren't happy
with OpenJVM/JDK and demand Sun/Oracle's version instead.


You didn't mention what DBMS you are targeting - that matters for
scripting - but I would take a look at the list below.  They all are
free or have free versions, are multi-platform, and support multiple
DBMS.  

https://www.oracle.com/database/technologies/appdev/sql-developer.html
https://dbeaver.io/
http://www.bestofbi.com/page/architect
http://squirrel-sql.sourceforge.net/
http://www.modelsphere.com/org/


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/1bdtpehmfhajjoaasq97h5icachdkr6b9s%404ax.com.


Re: [racket-users] Re: Structured Concurrency in Racket

2019-10-09 Thread George Neuner


On 10/9/2019 2:34 AM, Zelphir Kaltstahl wrote:

I don't think places are a good example for good support of parallelism.


Hoare's "Communicating Sequential Processes" is a seminal work in 
Computer Science.  We can argue about whether places are - or not - a 
good implementation of CSP,  but you can't very well knock the concept.




It is difficult to get a flexible multi processing implementation done,
without hard-coding the lambdas, that run in each place, because we
cannot send serializable lambdas (which also are not core, but only
exist in the web server package) over channels. That means, that one
needs to define ones lambdas ahead of time before even starting a place
and sending it the data to process. That means, that we cannot have
something like a process pool.


1) Serial lambdas and closures are in web-server-lib, not the 
framework.  What is the problem including a library?


2) /serial-lambda/, /define-closure/, etc.  only create functions that 
CAN BE serialized.  You still do have to (de)serialize them.


3) You can send serialized code over place channels - it is just a string.


The difficulty in sending code is making sure all the support context is 
available.  To be sure, this can be a pain.  But consider that for a 
local place you can send the name of a code file to dynamic-require ... 
and for a remote place you can send the file itself.


And if channels present a problem, take a look at Paulo Matos's Loci 
package which implements (local, same machine) distributed places over 
sockets. https://pkgs.racket-lang.org/package/loci




The other problem is, that using places means using multiple Racket VMs,
if I remember correctly, which uses some RAM. It is not like places are
super lightweight at least.


This is a more substantial argument.  Each place is a separate copy of 
the VM.  I've wished publicly to have more control over the resources 
used by Racket - hard limits on heap and so forth, like with server 
JVM.  It's just a small problem on Unix/Linux where you can ulimit ... 
but its a major PITA on Windows where you can't.


But, you can choose whether to use *dynamic* places which are OS threads 
in the same process, or *distributed* places which are separate 
processes, or a mixture of the two.




Racket threads run on a single core, I think.


Actually the whole VM is single core limited, but multiple threads can 
execute within it.  That's why places and futures are important - for 
multi-core support.


The reason for the thread limitation is GC.  The mutator has to stop - 
at least momentarily - when the collection begins and again (possibly 
multiple times) to check that the collection is complete. User-space 
threads can be halted easily ... OS threads are much more difficult to 
deal with - there generally is little control over their scheduling and 
little or no visibility into when it would be safe to stop them.


Obviously GC can be done with OS threads sharing memory - but it is 
order of magnitude harder than with user-space threads.  Maybe with the 
switch to Chez, it is time to revisit this.




I know there is a tutorial about using futures somewhere, where it
depends on the number type one uses, whether the code can be
automatically run in parallel or not, so there is also some issue there,
or at least it did not look to me like one could use futures everywhere
and have neat parallelism.


/would-be-future/  returns what is essentially testing code that logs 
any future-unsafe operations when executed.  You can use it to determine 
if the code actually would run in parallel as a future.


Generally, you can access vectors/arrays and do math.  Almost anything 
else is problematic.




Correct any of the things I wrote above, if they are not true, but I
think Racket definitely needs a better multi processing story.


You certainly can argue that sending code for execution on a remote 
place is not as easy as it could be.  And unloading code is not as easy 
as it should be.  Killing / spawning a new place works, but it is a 
heavy hammer that works against having a compute pool.




I would love to see something like Guile Fibers. Andy Wingo even mentioned in
his video, that some of the Racket greats advised him to look at
Concurrent ML and that that is where he got some ideas from, when
implementing Guile Fibers as a library. Shouldn't Racket then be able to
have a similar library? I don't understand how Fibers really works, but
that is a thought I had many times, since I heard about the Fibers library.


A fiber is just a coroutine ... implemented with continuations and a 
nicer API.



Regards,
Zelphir


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 

[racket-users] Re: General ways and concrete examples of approaching web dev

2019-10-09 Thread George Neuner


Rearranged a bit for continuity ... 


On Tue, 8 Oct 2019 19:44:55 +0200, Marc Kaufmann
 wrote:

>Thanks for the response to a rather general question. I'll definitely have
>a look at your code for Racket stories, which is live now if I see
>correctly. Nice!
>
>I guess one concrete thing that I find surprisingly hard in my code is to
>get rid of the number of times I repeat the structure of the data:
>
>1. write the SQL code to create the database
>2. write the interface in Racket that deals with the database directly
>(transform into Racket values, but it's still in the same groups)
>3. write functions that need to know about this structure, because they
>extract the information from part 2, but different fields for different uses
>4. write the view that - quite often - looks like a subset of the database
>and in my case calls functions from part 3, which again repeats huge parts
>of what is in part 1
>
>So if I have a user with 5 fields I am interested in, I find that if I
>change part of my database schema, I usually update 3 (or more) places,
>which tells me that I didn't get the abstractions right. (And I haven't
>added tests, or else I'm sure I'd have another layer or 2 of repetition.)
>  :
>
>My guess is that I don't grok MVC, and therefore end up with all these
>repetitions ...

It remains to be seen whether you really understand what MVC is about
... but repetition unfortunately is a major issue with it, as it is
with many other application design patterns.

In general, embracing MVC as a design philosophy won't reduce your
work at all - in fact it likely will increase it.  MVC does nothing
whatsoever to reduce the application's unique processing - it only
addresses ways to structure the application.  But usually it will
produce a program that is more modular and clearer to understand.  
[But your observations about maintenance are quite valid.]


One of the issues I have with MVC is the way it typically is
presented: data flow in the tutorials tends to be exaggerated and
overly complicated, and the explanation typically revolves around DBMS
and graphical UIs that simply aren't relevant to it.

As a design pattern, MVC dates from the 1960s, from the era of CRT
display/edit form-based applications.  The View and Controller
historically were integrated, and the "Model" was a memory cache of
one or more data records.
[Relational DBMS didn't exist in the 60's, but there were many
varieties of file based record systems.  Dedicated DBMS software based
on network/graph and hierarchical models appeared in the 70's, and
then relational models appeared in the 80's.]

Obviously MVC can be - and has been - generalized to separate the
various concerns, divorce the "Model" from its "data record" origins,
and to allow more complex communication/control patterns.  But the
modern notion of MVC has become so interwoven with DBMS, graphical
UIs, event handling, reactive programming and web services that people
learning about it often have a hard time figuring out what it really
means and how to use it effectively for their own programs.

MVC is simple when you understand what it was designed for originally.


Then there is the proliferation of simplistic MVC object "frameworks".
These typically address DBMS backing storage for the Model and little
or nothing else.  Trying to use them for rapid application development
too often results in your application doing all the work, and your
high powered DBMS server being turned into little more than a very
expensive file server.  


> :
>The continuation passing style actually suits my use cases much better
>than storing state in the database -- except that I need to be able 
>later on to recreate the path a user took, in order to figure out what
>happened, so I have to store it in an easy-to-interpret way in the 
>database.

> ... part of the reason I don't grok it may be that most
>beginner resources have websites that are less stateful than what I
>do, which is much more like a game with many action nodes and 
>randomization. I should probably have a look at Realm of Racket and
>see if I can't port the big-bang ideas to the web server. 

MVC per se has no problem with large amounts of state - the scope of
the Model, and how and where it is maintained, largely is irrelevant.
There doesn't need to be one big unified data store - there can be
many little ones.

I think part of your problem it is that you are integrating/conflating
what are purely implementation issues - such as whether to pass state
via continuations vs storing it in DBMS - with higher level design
issues like whether to use MVC vs some other equivalent architecture.




On the subject of database development, your best bet for reducing
effort is to invest in a database modeling tool.

There are many free and/or reasonably priced (for single developer)
tools that will generate DDL and simple select/update DML or view code
for you.  The better ones also can generate morphing DDL for
structural alterations 

[racket-users] Re: Structured Concurrency in Racket

2019-10-08 Thread George Neuner
On Tue, 8 Oct 2019 10:36:42 -0400, Luke Whittlesey
 wrote:

>I think the ceu language has a nice model of what I would consider
>"structured". http://ceu-lang.org/ It has automatic cancellation and
>finalization. Racket can easily support this model. Await statements
>are captured through delimited continuations and processes are managed
>in a tree. If a parent process exits the children are canceled and
>finalized.

Interesting.  It appears - to me, anyway - that Ceu took some
inspiration from Occam, but is implemented with coroutines instead of
threads or light-weight processes.  Ceu programs are limited to a
single core/CPU ... so there is no real parallelism possible other
than by a multiple process approach.

Racket's threads have similar single core/CPU limitations, but futures
and places do not - they can run simultaneously on a multicore CPU.
Whatever "structure" model might be adopted for Racket would need to
account for the semantic differences.

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/u6hqpehe84ngfk8ackss2r7g74jg99ma9v%404ax.com.


Re: [racket-users] Some guidance in setting up Racket as a game scripting language.

2019-10-07 Thread George Neuner


On 10/7/2019 4:30 PM, George Neuner wrote:


Visual Studio's compile and link options are output in log files in 
the *.tlog*  sub-directory under the build (debug or 
release) directory.  See *CL.command.?.log* and *link.command.?.log*  
where '?' is some number.   [I don't know what that number represents 
- on my system I have only ever seen '1'.]


Sorry, should have been a little more explicit.

By default the logs and build information are in the *_source_* tree in 
sub-directories that are named corresponding to the desired build:  
debug, release, x64/debug, x64/release.  The .tlog directory 
and the logs for each build that has happened will be under those.


If the project is customized for different output locations, then 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/a352c46c-1688-d26b-1544-79721f2e59ef%40comcast.net.


Re: [racket-users] Some guidance in setting up Racket as a game scripting language.

2019-10-07 Thread George Neuner


On 10/7/2019 3:47 PM, Jens Axel Søgaard wrote:
Den man. 7. okt. 2019 kl. 20.15 skrev Hans Sjunnesson 
mailto:hans.sjunnes...@gmail.com>>:


I'm sorry Jens - I'm using Visual Studio on Windows to compile
this project.
I've initially built libracket, and SDL, which I'm linking against.
I can zip the entire solution and upload it somewhere for you to
have a look, but you'll need Visual Studio on Windows for that to
work.


I don't have a windows machine - but your test example only have two 
files. Is there a way to see

what options are applied (in a log perhaps)?

/Jens Axel


Visual Studio's compile and link options are output in log files in the 
*.tlog*  sub-directory under the build (debug or release) 
directory.  See *CL.command.?.log* and *link.command.?.log*  where '?' 
is some number.   [I don't know what that number represents - on my 
system I have only ever seen '1'.]


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/171a0c22-5bde-e9ec-d684-5fdd0c8621a7%40comcast.net.


Re: [racket-users] Structured Concurrency in Racket

2019-10-07 Thread George Neuner



On 10/7/2019 1:46 PM, jab wrote:

Coming across 
https://trio.discourse.group/t/structured-concurrency-and-delimited-continuations/
 just provoked me to search for discussion of structured concurrency in Racket. 
I didn’t immediately find much.* I hope that doesn’t mean that the interesting 
work that’s being discussed over in 
https://trio.discourse.group/c/structured-concurrency etc. has been largely 
unknown by the Racket community. Trio is having a profound impact on the future 
of concurrency, not just in Python but in many other languages. There’s even a 
post on Wikipedia now: https://en.wikipedia.org/wiki/Structured_concurrency

(For anyone new to the term, 
https://vorpus.org/blog/notes-on-structured-concurrency-or-go-statement-considered-harmful/
 might be the best starting point. One persuasive example shows Nathaniel live 
coding a correct implementation of RFC 655 “Happy Eyeballs” in 40 lines of 
Python: 
https://github.com/python-trio/trio-talks/tree/master/njsmith-async-concurrency-for-mere-mortals
  (For comparison, Twisted’s implementation took hundreds of lines and still 
had a logic bug after years of work.) There is also some related reading in 
https://github.com/python-trio/trio/wiki/Reading-list.)

I hope this post provokes discussion of structured concurrency in Racket. It’d 
be fascinating to read more of your thoughts!

Thanks,
Josh

* For example, Googling “structured concurrency racket” turned up mostly just a 
brief mention of Racket’s custodians in the bottom-most comment on this post: 
http://250bpm.com/blog:71


"Structured concurrency" as defined by those articles really applies 
only to programs that operate in distinct phases -  which is a pretty 
good description of many science programs  - but such programs represent 
a (important, but) small subset of all parallel programs.


Racket's APIs are designed to support general parallelism, not just 
phased parallelism.


I suppose an argument could be made for syntax explicitly aimed at 
phased parallelism ... but using macros, such syntax could be built on 
top of the existing parallel (future, thread, place) APIs - so there is 
nothing stopping you, or anyone else, from creating a "structured 
concurrency" package that everyone can use.



One problem I foresee is defining a reasonable syntax and semantics.   
Most of the languages that promote "structured" concurrency have C-like 
syntax.  Moreover they vary considerably in semantics - in some of them 
the spawning thread stops immediately and can't continue until its 
children exit, but other allow the spawning thread to continue until it 
executes an explicit join / wait for its children.


The Lisp/Scheme based idioms of S-expr Racket are very different from 
those of C-like languages, and whether or not some "Racket2" 
materializes having a more C-like syntax, many people like Racket just 
the way it is.  I can envision heated debates about what should be the 
proper "structuring" semantics and what syntax best represents them.


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/8b83ff75-7b57-f3f1-0514-46170c9c3141%40comcast.net.


Re: [racket-users] How do I secure secrets in memory?

2019-09-27 Thread George Neuner



On 9/27/2019 12:56 PM, Sage Gerard wrote:
I got sloppy here in a Stripe integration: 
https://github.com/zyrolasting/stripe-integration/blob/master/main.rkt#L31


I'm not an InfoSec expert, but I know I'd like to secure the secret 
key used here in memory instead of using a parameter.


I'd probably encrypt the value provided by a client module and store 
it (write-only from the client's perspective) using set-box!. But I 
have several other questions:


1. Does the garbage collector keep a clear text copy of the secret in 
memory before I encrypt it? If so, how can I make it easy for a client 
module to set the secret key AND make it such that a garbage 
collection pass will remove the clear secret from RAM?


Obviously the plaintext must be kept until the crypttext exists.   I 
assume you are asking if the plaintext will persist AFTER encryption, 
and that answer is "yes".  The plaintext string will persist until the 
collection following the point where the program abandons it - but 
program can overwrite the string immediately after encrypting to erase 
the original value.  There still would be a small window of 
vulnerability, before/during encryption, but you can minimize it as much 
as possible.



2. Are there any existing /cross-platform/ Racket projects that can 
proactively keep secrets away from the garbage collector and swap 
space? Nothing relevant comes up for "secret", "security" or "swap" on 
the package index.


Sorry, no clue.


3. Are there any other intermediaries in a Racket process that might 
keep a copy of a cleartext secret?


Not 100% certain, but I don't think so ... not unless the program itself 
makes copies.



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/0f0f6530-7b4e-f093-1fc3-a57abe5936ba%40comcast.net.


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] Re: Confusion with udp-receive!

2019-09-25 Thread George Neuner




On 9/25/2019 2:57 PM, Matthew Flatt wrote:

At Wed, 25 Sep 2019 12:49:36 -0400, David Storrs wrote:
> 1) Is it possible that there is a bug in the underlying C code?

It's always possible. But if I understand the original problem, it
seems unlikely that a bug manages to exactly reconstruct a port number
that has been replaced in a UDP packet by a NAT.


The NAT  [or last router]  port will be in the IP header, not the UDP 
header - the UDP header contains the address:port of the remote client.
AFAIK, the IP (level 3) information is not passed up to the application 
by the network stack when the application is using a level 4 protocol: 
UDP or TCP.


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/0059b3b1-9a79-69a5-db60-697cb6a5e837%40comcast.net.


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

2019-09-25 Thread George Neuner

Hi David,

On 9/25/2019 1:08 AM, 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.


NAT routing is transparent:  you are - or at least, should be - seeing 
the port number of the remote machine.


But remember that - unlike TCP - UDP can send on the same port that it 
listens to.  If the "client" is sending on the same port as the server 
is listening, you won't be able to distinguish them by port alone.




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:  


You won't get the address of the router - you'll get the address of the 
client.  (see below)




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.


What you are overlooking is that UDP is a level 4 [end-to-end] protocol, 
but you are trying to get level 3 [routing] information.


Neither UDP nor TCP normally records the path a packet takes - only the 
routers themselves know what they do to forward the packet.  The path 
between 2 machines is never fixed, and it may change abruptly due to 
congestion or outage along the way.    "traceroute" uses a special 
(level 3) IP packet which explicitly commands each router along the way 
... and the end destination as well if the packet gets there ... to send 
back a response to the traceroute initiator.  The path is discovered 
dynamically from the responses.



Hope this helps,
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/a0373ae3-5246-8b06-ea58-6689059d4d3c%40comcast.net.


Re: [racket-users] transparency in Pict

2019-09-10 Thread George Neuner


On 9/10/2019 11:23 AM, Jens Axel Søgaard wrote:
Den tir. 10. sep. 2019 kl. 17.04 skrev Hendrik Boom 
mailto:hend...@topoi.pooq.com>>:


On Tue, Sep 10, 2019 at 03:23:43PM +0200, Jens Axel Søgaard wrote:

> I have extended "clipped" to handle regions defined by more than
one path.
> Now (clipped c ... p) will make a region from the curves c ...
and use
> the region to clip the pict p. Most common uses:
>
>    (clipped c p)          the part of p inside c
>    (clipped c1 c2 p)   the part of p between c1 and c2 (if c2 is
inside c1)

Does that mean the part of p that is inside c1 and outside c2? (which
would be meaningful even if c1 and c2 intersect?  That might happen
because of numerical instability.)


Whether is point is inside or outside the region given by the
two curves is decided by the "winding rule". See the
discussion on fill (which also uses the winding rule):

https://docs.racket-lang.org/metapict/index.html?q=metapict#%28def._%28%28lib._metapict%2Fdraw..rkt%29._fill%29%29

For filling with the even-odd rule I have an eofill, but I haven't 
written an eoclipped yet.


/Jens Axel


Just a couple of points relevant to using regions in general:

 - any region can be selected as the clipping region for drawing.

 - a region can be created from any closed figure: a rectangle, an 
ellipse, a looping point path, etc.


 - a region can be created by combining other regions using union, 
subtraction, and intersection.


 - a single region can cover multiple disjoint areas.

And a hint:
If you are attempting to "shade" objects by painting them with a partly 
transparent brush, you may (and probably will) end up with Moire 
patterns where objects overlay / intersect each other.  The way to apply 
shade without worrying about Moire is to create a single region that 
simultaneously covers all the to-be-shaded areas, and then to fill/paint 
that region with your chosen shading brush.


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/d201f4a1-5de0-e540-c1ae-8ac02c4d981e%40comcast.net.


Re: [racket-users] transparency in Pict

2019-09-10 Thread George Neuner


Or create a region with a hole through it and use it to clip the drawing.
George


On 9/10/2019 8:12 AM, Robby Findler wrote:
Another trick I use is to crop the picture that is nominally below the 
image and then just draw it again, but this time on top.


Robby

On Mon, Sep 9, 2019 at 2:15 PM Jens Axel Søgaard 
mailto:jensa...@soegaard.net>> wrote:


You can use a path with an even-odd-fill to cut out parts.

An example:

#lang racket
(require metapict metapict/polygons)

(define (cutout p x y r)
  (defv (w h) (pict-size p))
  (with-window (window 0 w 0 h)
    (brushstipple (pict->bitmap p)
                  (eofill (rectangle (pt 0 0) (pt w h))
                          (circle x y r)

(set-curve-pict-size 400 400)
(def p (brushcolor "red" (fill (regular-polygon 5
(cutout p 200 200 50)

/Jens Axel

The result (the yellowish color is the background color in my editor):

image.png


Den man. 9. sep. 2019 kl. 20.20 skrev Hendrik Boom
mailto:hend...@topoi.pooq.com>>:

I'm wondering how to cut a transparent hole in something.

Say I have a rectangle and I want to make part of it
transparent so
that I cn see what's behind it.
Drawing a transparent rectangle on top of it won't workm
because it'll
just reveal the original rectangle.
The only way I cn see it to draw the original rectangle in
pieces,
careful avoiding the area I want to make transparent. (that
may be
tricky if the transparent area is, say, a circle).

Is there some convenient operation in Pict that can accomplish
this
more directly?  Kind of the union and intersection and
complementation
on constructive solid geometry, but now 2D.

My guess is no.  I haven't found it.  So I ask.

Maybe I'll need some other drawing tool than Pict. Suggestions
welcome.

-- hendrik

-- 
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/20190909182018.74o322qfwehrmqaz%40topoi.pooq.com.



-- 
-- 
Jens Axel Søgaard


-- 
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/CABefVgy0cxZD1dJv6dA51_rTEFqk3wu-zBSpGdQV-eD1fmurag%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/CAL3TdOMM1rPLCGyicrcEv50USDaHmtOs-hPo4r%2BaKCACAgJw%3Dw%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/a8e5c22e-08d6-0839-1b22-cebe912aa409%40comcast.net.


Re: [racket-users] Would it help to call racket2 something else?

2019-08-28 Thread George Neuner



On 8/28/2019 10:56 PM, Sage Gerard wrote:

#lang new-coke

-slg


"New Coke" was horrible ... tasted like the bastard child of Pepsi and 
Dr. Pepper.


And no matter what they claim, "Classic Coke" never was (and still 
isn't) the same as the original.  Classic Coke hit shelves a mere 3 
months after the original was discontinued.  I had cases of original 
stockpiled and was able to do side by side comparison.  Classic tasted 
like original diluted with extra water.  Probably it was deliberately 
diluted to enhance profit and they hoped no one would notice.


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/d2be1ddf-9c83-2641-7e89-c2f61a993bd7%40comcast.net.


Re: [racket-users] Quadruple-precision floating-point support?

2019-08-28 Thread George Neuner

Hi,

On 8/28/2019 11:49 AM, Shaobo He wrote:
Let me describe my use case first so that it's easier to clarify why 
bigfloat or double-double don't work for me. The program I've been 
working on requires emulation of arbitrary-precision *IEEE 754* 
floating-point arithmetic (the maximum precision is double, for now) 
and easy/efficient access to the bit representations of floating-point 
values. Therefore, bigfloat is generally too slow just for my use case 
since I don't need so much precision and it doesn't provide functions 
to access the bit representations. Double-double is good enough to 
emulate the floating-point arithmetic but I think it's also not 
trivial to access the bit representations of the floating-point 
formats I want to emulate.


MPFR does have optimizations for power of 2 mantissa lengths, but it's 
easy to see that a dedicated IEEE quad emulation (that most likely uses 
CPU SIMD ops) might be faster.



Low level bit access from Racket will not be trivial in any case: Racket 
can extract and set bit fields only within exact integers, and integers 
larger than platform fixnums will be in GMP bigint format (an array of 
longs representing base 10**9 values).


Contiguous foreign data buffers can be made visible to Racket as byte 
strings and manipulated that way, but it can be tricky to work with 
fields larger that span multiple bytes, and slow to work with fields 
that are larger than platform fixnums.



Quad-precision format fits my purpose nicely because it's sufficiently 
precise to emulate all the floating-point formats I'm interested in 
and obtaining the bit representations of these formats based on the 
bit representations of quad-precision numbers is easy.


More important is how closely you really want to emulate IEEE 
functionality.  I don't see anywhere that IEEE-754/854 conformance is 
documented for libquadmath.   There are numerous high and/or arbitrary 
precision math libraries, but many use their own ad hoc format 
internally rather than IEEE interchange formats, and they don't 
faithfully implement IEEE bitwise underflow.  Many also don't implement 
all the possible IEEE-754 rounding modes ... what constitutes "correct" 
rounding behavior depends on the problem, and in any case is a matter of 
opinion.


Most people don't think about (or really care much) about IEEE 
conformance, but if you are aiming to produce bitwise accurate results 
... albeit with arbitrary precision ... then maybe you do need to worry 
about these things.


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/ea09776e-7d49-de88-4012-532162d73cf0%40comcast.net.


Re: [racket-users] Quadruple-precision floating-point support?

2019-08-25 Thread George Neuner



On 8/23/2019 8:39 PM, Shaobo He wrote:

Hello everyone,

I'm in need of quad-precision floating-point type/operations in Racket 
(the bigfloat module doesn't work for me). It appears there's none, am 
I right?


The only hardware I am aware of with IEEE compatible quad precision is 
POWER9  (Vaxen had quad precision, but not IEEE compatible).  So on most 
platforms any implementation necessarily will be software: either an 
emulation of quad or double-double.


Just out of curiosity, may I ask why bigfloat doesn't work for your 
purpose?  I know the range will be different between a quad and a 
bigfloat having the same precision, but that seems like it ought to be 
relatively easy to work around.


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/ba384d7e-92c1-304f-7b5d-07267a780a65%40comcast.net.


Re: [racket-users] Re: The case, and a proposal, for elegant syntax in #lang racket2

2019-08-22 Thread George Neuner



On 8/21/2019 3:25 PM, Jon Zeppieri wrote:

Racket's `case` is an implementation of this approach:
http://scheme2006.cs.uchicago.edu/07-clinger.pdf

It is not significantly complicated by `else`. And that approach was
created in the context of Scheme, which leaves the return value
unspecified when none of the tests are successful. That seems like it
should offer more opportunities for optimization, but I don't think
this approach is any less efficient when the unsuccessful result is
specified as # (as it is in Racket) than when it is not.

- Jon


Thanks for the pointer!

'case' in Scheme is an interesting challenge for compilation because it 
can involve dispatching on multiple types, each having its own 
comparison ordering.  I would hope that Racket leverages generic table 
searches where possible - depending on the use, generating a complete 
static dispatch routine everywhere can result in explosive growth of the 
code.  [Not that I've seen this happen, but I haven't had occasion to 
experiment in Racket with extremely large or complicated 'case'  
constructs.]


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/a8dd208d-dd3f-a2a7-3d20-3c1027932ac9%40comcast.net.


Re: [racket-users] Re: The case, and a proposal, for elegant syntax in #lang racket2

2019-08-21 Thread George Neuner



On 8/21/2019 1:13 PM, Gustavo Massaccesi wrote:

The expander in racket adds something equivalent to
    [else (void)]
if there is no else clause. (Try an example with the Macro Stepper.) 
So an explicit else clause would not change the speed of the programs.


In some cases the compiler can prove that the else part is not 
necessary and drop it, Also, I think that the compiler in RacketCS can 
notice that it has no side effects and also drop it if the result is 
ignored (but I'm not 100% sure).


Yes.  But in most cases, it is impossible to prove that the 'else' is 
unnecessary.  And as I mentioned in my reply to Hendrick, 'cond' is 
pretty simple, but an 'else' - implicit or explicit - can screw up 
optimizing tests in a 'case'.


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/931ae453-8d87-5ee1-f8e1-ab23466a3647%40comcast.net.


Re: [racket-users] Re: The case, and a proposal, for elegant syntax in #lang racket2

2019-08-21 Thread George Neuner

On 8/21/2019 11:01 AM, Hendrik Boom wrote:

On Wed, Aug 21, 2019 at 10:52:57AM -0400, George Neuner wrote:

> 
> I don't like the idea of compulsory 'else' - for 'cond' or 'case' or

> 'match' or ...
> 
> 'Else' isn't needed if all input cases are covered, but in almost all

> real world uses, the compiler is not able to prove the 'else' is
> unneeded so as to prevent emitting code for it.  And depending on how
> the compiler structures the tests (cond is simple, case less so),
> adding 'else' into the mix may increase execution time as well.

What about treating a missing 'else' as a run-time error if and only
if control gets that far.

That would require code that intends nothing to be done to have an
explicit 'else' saying so.

Except for notation, this would seem to meet your demands for semantic
expressibility.


Not at all.  Obviously, I'm not a beginner:  when I choose to leave out 
'else', it is not a mistake - I intend that nothing should happen if no 
explicit case was matched.  An implicit runtime error would represent 
completely different semantics ... well defined maybe, but completely 
different nonetheless.


More importantly, the code generation consequences exist regardless of 
whether the 'else' is explicit or implicit:  it requires extra tests 
which may affect the overall structuring and performance of the [set of] 
tests.  As I alluded to above, 'cond' wouldn't be affected very much 
because it compiles quite straightforwardly into a series of 'if's' that 
correspond directly to the source.  However 'case' is a different matter.


I admit that I haven't looked to see how Racket compiles 'case' ... and 
there are many possible variations due to the flexibility of the 
construct.  However, I have some non-Scheme-related experience with 
compiler implementation, and in general, 'case' presents many more 
opportunities wrt 'cond' to generate better optimized, out-of-order (wrt 
the source) testing.  Requiring an implicit 'else' introduces 
considerable extra complexity, and may (not necessarily will, but may) 
hamper generating an optimal test sequence for the explicit cases.



This is something that may become more apparent with the switch to 
RacketCS because the Chez compiler does much more optimization and 
produces native code.  From a compiler implementor's view, the surface 
syntax of the language largely is irrelevant - it impacts introspection 
and metaprogramming, but quite a lot of syntax related stuff has little 
or no effect on generated code.  However, some of the things that have 
been mentioned (at various times) have very real consequences for 
generated code: things like automatic currying, 'statement' vs 
'expression', arbitrary numbers of return values, implicit 'else', 
generic stream access to (raw) collections, generic port access to 
strings, N-dimension arrays vs vectors of vectors, incremental typing, 
etc.  It's the features themselves which affect the generated code that 
I worry about much more than what syntax is used.



That said, I *like* the Lispy syntax.  I do think there are some 
opportunities to reduce the number of parentheses needed, but the 
consistent prefix nature of S-exprs is - I think - what makes Racket 
(and Scheme and Lisp) *easier* to learn than many other languages. 
Remembering all the operator precedences in infix languages is a PITA.


I dislike in some FPLs remembering that I *must* use parentheses in 
certain cases, while in other cases they are optional (or even 
disallowed).  I loathe significant whitespace (indentation) as in Python 
- counting spaces is just as stupid as counting parentheses [and yes, a 
decent editor can address either problem, but jeez ... even Fortran 
dropped its indentation requirements decades ago].


I don't think "popularity" is a very good reason to change language 
syntax - but as long as S-expr Racket remains a viable, completely 
*supported*, language, then I don't have a problem with development of a 
parallel infix version.


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/1ebfcd3b-80da-1abf-9dff-e2a3dec62f20%40comcast.net.


[racket-users] Re: The case, and a proposal, for elegant syntax in #lang racket2

2019-08-21 Thread George Neuner
On Wed, 21 Aug 2019 03:48:29 -0700, Sorawee Porncharoenwase
 wrote:

> On Wed, 21 Aug 2019 02:55:46 -0700 (PDT), Chris Stephenson 
>  wrote:

>> (b)  Conds allowed without else. Even beginner student allows this. It
>> causes bugs. In htdp/universe you can end up with a void universe or a void
>> somewhere in univers. the error emerges a long distance in space and time
>> from the code that causes it. Make else clauses compulsory.
>>
>
>A lot of people agree with you. Here's a (pre-) RFC on the issue:
>https://github.com/racket/racket2-rfcs/issues/39


I don't like the idea of compulsory 'else' - for 'cond' or 'case' or
'match' or ...

'Else' isn't needed if all input cases are covered, but in almost all
real world uses, the compiler is not able to prove the 'else' is
unneeded so as to prevent emitting code for it.  And depending on how
the compiler structures the tests (cond is simple, case less so),
adding 'else' into the mix may increase execution time as well.


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/esjqledhdohgt3eogv6s9sjvfibml0dgkf%404ax.com.


Re: [racket-users] web-server: how to save database results in memory across all requests?

2019-08-13 Thread George Neuner



On 8/13/2019 2:24 PM, 'Wayne Harris' via Racket Users wrote:

With Chrome, I visited localhost:/main a first time and refreshed it.  (So 
I got a cache miss followed by a cache hit.)  With Firefox, I did the same and 
got a cache miss on the first request.  I expected a cache hit.

$ racket share.rkt
Now serving...
Your Web application is running at http://localhost:.
Stop this program at any time to terminate the Web Server.
database: cache miss
database: cache hit
database: cache miss
database: cache hit


Sorry ... I don't use parameters much and had to look up them up. The 
problem is that each browser request is handled by a separate thread, so 
the 2 browsers are using different threads and different instances of 
the parameter (which defaults to #f = miss).


TCP connections are (relatively) heavy weight, so browsers try to keep 
server connections open for subsequent requests.  When you refresh the 
page relatively quickly, it's likely you get an already existing handler 
thread back again.  If you wait a bit before refreshing the page - so 
the connection closes - you may see multiple misses even with just one 
browser.


The answer is don't use parameters for this purpose - use some other 
object such as a hash table or other thread-safe object that is defined 
in terms of with get/set accessors.  Something I have used for this in 
the past is:


;;
;;  mutual exclusion shared object
;;
(define-syntax getter/setter!
  (syntax-rules ()
    ((getter/setter!)
 ; -- start template

 (let* [
    (mtx (make-semaphore 1))
    (var null)
   ]
   (lambda x
 (call-with-semaphore mtx
   (lambda ()
 (cond
 ([null? x] var)
 ([pair? x] (set! var (car x)) var)
 (else (error))
 
 )

 ; -- end template
 )))


You define shared objects as getter/setter!  and then use them similar 
to Racket's parameters, except that there is only one instance of each 
object shared by all its users.  E.g.,


If you were to add the macro above into "shared-model.rkt" and use it like:

    (define in-memory-database (getter/setter!))
    (in-memory-database #f)  ;; set initial value

then it all should act as you expect.  Since the macro actually creates 
a closure (which is a function), you can directly export the shared 
"object" from the module without needing other wrapper functions to use it.



Hope this helps,
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/2aee0d5f-df4c-9d11-a9c9-98b211fb9b21%40comcast.net.


Re: [racket-users] web-server: how to save database results in memory across all requests?

2019-08-13 Thread George Neuner



On 8/13/2019 11:47 AM, 'Wayne Harris' via Racket Users wrote:
I'd like to save database results in memory because my database only 
changes between long time intervals.  By building a minimum 
application, I see my cache-strategy seems to work per servlet: by 
opening a new browser, the first request yields a cache-miss.
Looking through the documentation, I got the idea that perhaps I 
should serve/servlet using


   #:servlet-namespace '("shared-model.rkt")

where shared-model.rkt is the module that talks to the database and 
implements the caching-strategy.  But adding this keyword to 
serve/servlet did not make any perceived difference.


What should I do to save results in memory across all requests?


AFAIK #:servlet-namespace isn't necessary -  you can share data (via 
access functions) among different instances of request handlers just by 
requiring the modules (files) that define the common objects wherever 
you need them.


If I'm not mistaken about the serve/servlet call in your code below, you 
are relying on the application to open the new browser window ... 
terminating and restarting the application each time.  That clears your 
"cache", guaranteeing that it misses the first time. You should set  
#:launch-browser? #f  , start the application and connect to it *from* 
your browser with the URL http://localhost:.


That said:

What DBMS are you using?  Server based DBMS like Oracle, Postgresql, 
MySQL, SQLServer, etc.  automatically cache query results in case the 
same query is run again.  If the server is well provisioned memory-wise, 
it can take a long time for a popular query to age out the cache.   If 
your application is co-resident (on the same machine) with the server, 
caching results yourself would be duplicating effort.


Hope this helps,
George



--- server.rkt
--
#lang racket/base
(require
web-server/servlet
web-server/servlet-env
(prefix-in model: "shared-model.rkt"))

(define-values (dispatch url)
  (dispatch-rules
   (("main") db->response)
   (("update" (string-arg)) update->response)))

(define (update->response r s)
  (define str (model:in-memory-db-set-and-get s))
  (displayln str)
  (string->response str))

(define (db->response r)
  (string->response (model:get-in-memory-results)))
;; no more api endpoints ==/==

(define (string->response s)
  (response/full 200 #"Okay" (current-seconds)
 TEXT/HTML-MIME-TYPE '() (list (string->bytes/utf-8 s

(define (file-not-found r)
  (response/xexpr "File not found."))

(module+ main
  (file-stream-buffer-mode (current-output-port) 'line)
  (define (main)
    (displayln "Now serving...")
    (serve/servlet dispatch
   ;; #:servlet-namespace '("shared-model.rkt")
   #:stateless? #t
   #:log-file (build-path "logs/httpd.log")
   #:port 
   #:listen-ip "127.0.0.1"
   #:servlet-path "/"
   #:servlet-regexp #rx""
   #:extra-files-paths (list (build-path "pub/"))
   #:server-root-path (build-path "/")
   #:file-not-found-responder file-not-found))
  (main))
---

--- shared-model.rkt
---
#lang racket/base
(define in-memory-database (make-parameter #f))
(define (in-memory-db-set-and-get x)
  (in-memory-database (format "~a: data to be shared across servlets" x))
  (in-memory-database))

(define (get-in-memory-results [refresh? #f])
  (if refresh?
  (begin (displayln "database: force refresh")
 (in-memory-db-set-and-get "forced"))
  (let ([in-memory-db (in-memory-database)])
    (if in-memory-db
    (begin (displayln "database: cache hit")
   in-memory-db)
    (begin (displayln "database: cache miss")
   (in-memory-db-set-and-get "miss"))
(provide (all-defined-out))
---



--
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/73404053-1ed7-92c5-f9ad-16eed1af8e2c%40comcast.net.


  1   2   3   4   5   >