[racket-users] looking for advice on a web background process manager

2021-12-30 Thread 'Wayne Harris' via Racket Users
I'm considering writing a manager for background processes --- such as send a 
batch of e-mail or other process that takes a while to finish --- for a web 
system.

I see the challenge here as just writing something that will look like a
very basic UNIX shell --- so I'll call it ``web-api-shell'' from now on.
(``Web'' because it will be used by a web system through some HTTP API.)

This thing has to be flawless. I'm looking for design principles and advice.

I don't know which language I will use, but I'd like to use Racket at
least as a prototype. I am looking at section 15.4 at

https://docs.racket-lang.org/reference/os.html

and I'm not sure it gives me all the control I need. I have a more
lower view of the job --- fork(), execve(), waitpid(), SIGCHLD. But I
suppose Racket handles this much more elegantly that I would in C.

Your advice will be very appreciated.

(*) Where will it run

It will run on GNU systems running the Linux kernel.

(*) My own thoughts

The interface to shell will be through HTTP requests, so this shell will
likely be a web server of some sort. But before I get involved in the
web at all, I need the shell working flawlessly.

So I need a laboratory first. I could write a program that reads some
named pipe on disk to get commands such as ``run this or that'' while I
work. (Later I can write a web server replacing this named-pipe
interface.)

Just like a UNIX shell, this web-api-shell must know all every process
it runs. I suppose the work is essentially fork(), execve() followed by
waitpid().

One concern I have is the following. Is it possible for a process to
simply ``get out of'' the shell? What do I mean by that? A process
that does fork() and puts itself into background would leave the
web-api-shell's control, wouldn't it?

I think I must avoid that. Perhaps I can't let just any process run.
Perhaps the web-api-shell must only offer a few processes carefully
written by myself --- so that I know they won't put themselves in
background. (For instance, I can't let them change PIDs, otherwise I
won't have any idea who they are and that's a mess. I'd love to somehow
restrict system calls such as fork().)

(*) Serialization

I also think this web-api-shell must not be invoked in parallel. So I
guess I must use some queue of requests with no race condition and
pull each request as it comes. Any pointers on how to do this basic
thing with my zero experience?

(*) What is my level of training?

In the past I've studied many parts of

Advanced Programming in the UNIX Environment
W. Richard Stevens

I will definitely have to read it again to get work on this project.
Can you mention any UNIX concepts that are of great relevance for this
project? I don't think I ever got my mind wrapped around things like
sessions, session leaders and so on. Are these concepts relevant to
this application?

Thank you very much.

-- 
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/hRIrZF2NP2tUKP8_HV2lLkFr95li_XmhSrzbJCuR1ruwDxy2qyWgC-vREZPyrJMn0oUWj3N6gzSlQ1PBvs_FrwErvOInegt-CQGpPjDG2gw%3D%40protonmail.com.


[racket-users] Re: Understanding recursion in the function normalize-definition form the racket sources

2021-04-20 Thread 'Wayne Harris' via Racket Users
On Sat, 17 Apr 2021 05:02:00 -0700 (PDT)
Dan Synek  wrote:

> I am trying to implement a variation of define. In order to do that I am 
> trying to understand the source of the define macro in racket.
>  It calls a function normalize-definition which looks like this:
>   (define-values (normalize-definition)
> (case-lambda 
>  [(stx lambda-stx check-context? allow-key+opt?)
>   (let-values ([(id mk-rhs body)
> (normalize-definition/mk-rhs stx lambda-stx 
> check-context? allow-key+opt? #t)])
> (values id (mk-rhs body)))]
>  [(stx lambda-stx check-context?) (normalize-definition stx lambda-stx 
> check-context? #f)]
>  [(stx lambda-stx) (normalize-definition stx lambda-stx #t #f)])))
> 
> In the two last cases of the case-lambda there is a call to 
> normalize-definition. It is not a recursive call, since define-values 
> cannot be used recursively. I cannot find any other normalize-definition in 
> the modules required by the norm-define module.
>  If I try to enter a copy of the definition (renamed to 
> normalize-definition1) I get (as expected) that normalize-definition1 is 
> undefined.
> What is going on?

Beginner here.  I don't see the problem you seem to be referring to
here.  In this example below, I recursively define arglen using
define-values.  

#lang racket/base

(define-values (arglen)
  (case-lambda
[() 'no-list]
[(ls) (if (null? ls)
  0
  (+ 1 (arglen (cdr ls]))

case-lambda-recursion.rkt> (arglen)
'no-list
case-lambda-recursion.rkt> (arglen (list))
0
case-lambda-recursion.rkt> (arglen (list 1))
1
case-lambda-recursion.rkt> (arglen (list 1 1))
2
case-lambda-recursion.rkt> (arglen (list 1 1 1))
3
case-lambda-recursion.rkt> 


-- 
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/20210417093414.7527%40protonmail.com.


[racket-users] Re: Racket on Corporate Desktop Windows

2021-03-30 Thread 'Wayne Harris' via Racket Users
"Bruce O'Neel" 
writes:

[...]

> But no GUI of course.
>   
> Well I had been building on MacOS for years following the instructions
> to build a Minimal Racket and then run
>   
> raco pkg install -i main-distribution
>   
> and it finally clicked that the instructions were almost identical for
> Windows.
>   
> raco pkg update --auto racket-lib raco pkg install -i
> main-distribution
>   
> just like the instructions said.  In my mind I thought "I don't have a
> build toolchain on Windows, so that won't work."  And I was wrong.  It
> works just fine on my locked down desktop and now I have a GUI Dr
> Racket as well.

Cool!  Thanks for sharing!

-- 
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/86h7kw7b91.fsf%40protonmail.com.


[racket-users] Re: Gtk initialization failed for display ":0"

2020-07-14 Thread 'Wayne Harris' via Racket Users
Matthew Flatt  writes:

> At Sat, 11 Jul 2020 10:36:33 -0600, Matthew Flatt wrote:
>> Following up on Sam's suggestion, I recommend `xfvb-run` as something
>> like
>> 
>>  xfvb-run racket -l handin-server
>
> Should be `xvfb-run`. I always have trouble getting those letters in
> the right order.

We'll post on [f]ace[b]ook all your spelling mistakes!

-- 
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/86365vx85y.fsf%40example.com.


[racket-users] Re: Gtk initialization failed for display ":0"

2020-07-14 Thread 'Wayne Harris' via Racket Users
Matthew Flatt  writes:

> At Sat, 11 Jul 2020 10:36:33 -0600, Matthew Flatt wrote:
>> Following up on Sam's suggestion, I recommend `xfvb-run` as something
>> like
>> 
>>  xfvb-run racket -l handin-server
>
> Should be `xvfb-run`. I always have trouble getting those letters in
> the right order.

We'll post on [f]ace[b]ook all your spelling mistakes!  You'll be horrified!

-- 
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/86ft9uwgg0.fsf%40example.com.


Re: [racket-users] Gtk initialization failed for display ":0"

2020-07-14 Thread 'Wayne Harris' via Racket Users
Matthew Flatt  writes:

> At Sat, 11 Jul 2020 10:36:33 -0600, Matthew Flatt wrote:
>> Following up on Sam's suggestion, I recommend `xfvb-run` as something
>> like
>>
>>  xfvb-run racket -l handin-server
>
> Should be `xvfb-run`. I always have trouble getting those letters in
> the right order.

We'll post on [f]ace[b]ook all your spelling mistakes!  (You'll be
horrified!)

-- 
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/_p7fgT5MC2Uaec8DDU4q-o1fRzW_QEtkW4kuQzty4UYcQBpHTd8rN6MkAEErD-jOHFyg9x4Lcf5BrmcQbgV_2nrA7gJQtRb3nQmfTU9XOzQ%3D%40protonmail.com.


Re: [racket-users] windows, file-or-directory-modify-seconds, can't find errno set to ENOENT

2019-11-01 Thread 'Wayne Harris' via Racket Users
‐‐‐ Original Message ‐‐‐
On Friday, November 1, 2019 6:40 PM, 'Wayne Harris' via Racket Users 
 wrote:

> ‐‐‐ Original Message ‐‐‐
> On Friday, November 1, 2019 5:46 PM, Matthew Flatt mfl...@cs.utah.edu wrote:
>
> > Racket uses the native Windows API for filesystem operations, so it
> > generally creates exceptions with a 'windows value in the `errno` field
> > instead of a 'posix value. The `UNC_stat` function is also implemented
> > in "rktio_fs.c".
> > But you don't seem to be getting a 'windows error, either, and I
> > haven't been able to replicate that behavior. Just to make sure I'm
> > trying with a relevant version, which version of Racket are you
> > running?
>
> Hm. That must be the difference. I'm running Racket v6.6 which must
> really old for the speed of life nowadays.

Yes, that's an old problem.  Sorry about that.

Welcome to Racket v7.0.
racket@> ,enter "c:/somewhere/util.rkt"
rac...@util.rkt> (older-than-days? 30 "c:/whatever")
file-or-directory-modify-seconds: error getting file/directory time
  path: c:/whatever
  system error: The system cannot find the specified file.; errid=2
#f
rac...@util.rkt>

-- 
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/6vLRBKTelLp31asvDIE8TML4RGujD1oAnqA2Lqg7xkOtYtbwD4FWgtNbtUv_Ku5BjFre_5deisxAzjCfwJ3eRYl6xwWZeVtuF8IxVyz4nug%3D%40protonmail.com.


Re: [racket-users] windows, file-or-directory-modify-seconds, can't find errno set to ENOENT

2019-11-01 Thread 'Wayne Harris' via Racket Users
‐‐‐ Original Message ‐‐‐
On Friday, November 1, 2019 5:46 PM, Matthew Flatt  wrote:

> Racket uses the native Windows API for filesystem operations, so it
> generally creates exceptions with a 'windows value in the `errno` field
> instead of a 'posix value. The `UNC_stat` function is also implemented
> in "rktio_fs.c".
>
> But you don't seem to be getting a 'windows error, either, and I
> haven't been able to replicate that behavior. Just to make sure I'm
> trying with a relevant version, which version of Racket are you
> running?

Hm.  That must be the difference.  I'm running Racket v6.6 which must
really old for the speed of life nowadays.

-- 
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/Up-lI-qG0BOvZYbiEx5UyR2CYriTWNPL03T1Su1nb7wc4c4TKUrmskPH3pkLc__WeutFn-AvRqVG9KnfhNPbzQmO3zxrfO4AoqNVtOh8RB8%3D%40protonmail.com.


[racket-users] windows, file-or-directory-modify-seconds, can't find errno set to ENOENT

2019-11-01 Thread 'Wayne Harris' via Racket Users
I have a function called ``older-than-days?'' which produces true if a
path is older than a number of days.  (Source code at the end of the
message.)

rac...@util.rkt> (older-than-days? 30 "c:/autoexec.bat")
#t

On Windows, if I give it a non-existent file, I can't seem to get an
errno set to ENOENT.

--8<---cut here---start->8---
rac...@util.rkt> (older-than-days? 30 "c:/whatever")
file-or-directory-modify-seconds: error getting file/directory time
  path: c:/whatever
  system error: Unknown error; errno=-1
#f
rac...@util.rkt>
--8<---cut here---end--->8---

I looked at the source code for file-or-directory-modify-seconds at

  
https://github.com/racket/racket/blob/136ea767e2f76aa3785ebd1ca214411cc68b4533/racket/src/rktio/rktio_fs.c#L1034

Here's the relevant passage:

--8<---cut here---start->8---
rktio_timestamp_t *rktio_get_file_modify_seconds(rktio_t *rktio, const char 
*file)
{
#ifdef RKTIO_SYSTEM_WINDOWS
  rktio_timestamp_t *secs;
  if (UNC_stat(rktio, file, NULL, NULL, NULL, , NULL, NULL, -1))
return secs;
  return NULL;
#else
 [...]
#endif
--8<---cut here---end--->8---

(I couldn't locate UNC_stat.  Where is it?)  I guessed it some stat()
C function was called.  Microsoft seems to say stat does set errno in
cases such as ENOENT.

  
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019

So I expected to see errno set to ENOENT in that example above.

Can you educate me on this?  Thank you.

--8<---cut here---start->8---
My ``older-than-days?'' source code:

(define (older-than-days? days path)
  (define timeline-mark (- (current-seconds) (* days 24 3600)))
  (define path-mark
(with-handlers
([exn:fail:filesystem?
  (lambda (e) ;; where's my errno?
(displayln (exn-message e))
+inf.0)])
  (file-or-directory-modify-seconds path)))
  (< path-mark timeline-mark))
--8<---cut here---end--->8---

-- 
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/lwnybyElykkp86XSbAc727heWInydkLJUXrd65QEXw1OMznXm0sEQBwoHJV9e5hpA2N4sX5uoODUptUhmCGHHZIv7hqWZtwFCB1lUSDDzJQ%3D%40protonmail.com.


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

2019-09-27 Thread 'Wayne Harris' via Racket Users
‐‐‐ Original Message ‐‐‐
On Thursday, September 26, 2019 9:56 AM, Matthew Flatt  
wrote:

> At Thu, 26 Sep 2019 00:46:23 +, "'Wayne Harris' via Racket Users" wrote:
>
> > I think my message below neither asked any question nor did it contain the
> > adequate politeness which I so much think every e-mail should have.
>
> I don't see any problem with your message. It's more that the handin
> server doesn't get a lot of love. I know the little part that I use,
> and not much else...

I guess there wasn't technically, but it did lack the care that is usual of me, 
so I didn't really like it and wanted to express that.  Thanks for your 
attention.

> > > I haven't figured out how to forbid the use of length in submitted code.
> > > I'm a little lost with
> > > :language
> > > :with-submission-bindings
> > > I did understand
> > > :requires
> > > so I'm able to let submissions use extra libraries, but I'd like to 
> > > forbid,
> > > say, length in '(special beginner) too.
>
> There doesn't seem to be a simple way of disallowing the use of
> `length`. Since `submission` is bound to the whole submission content,
> you could have `pre:` action that reads and searches for the symbol
> 'length:
>
> #lang s-exp handin-server/checker
> (require racket/gui/base)
>
> (check: :language '(special beginner))
>
> (pre:
> (define (mentions-length? r)
> (cond
> [(eq? r 'length) #t]
> [(pair? r) (or (mentions-length? (car r))
> (mentions-length? (cdr r)))]
> [else #f]))
> (define-values (defns interactions) (unpack-submission submission))
> (define p (open-input-text-editor defns))
> (parameterize ([read-accept-reader #t])
> (let loop ()
> (define r (read p))
> (unless (eof-object? r)
> (when (mentions-length? r)
> (error "length not allowed"))
> (loop)

(I think ``my editor'' couldn't help but destroy your indentation.  I wonder if 
there anything I could do.  Sorry about that.)

I think you're scanning the user code and looking for any mention of length.  
That is nice!  I can use that for many other things.  Thanks!

> A more precise approach would be to expand the program and check
> whether there's any identifier bound to `length` that was part of the
> original program (as opposed to introduced by a macro), but that's
> probably more than you need.

I'm not sure I get this idea, but let me take one thing at a time.  Let me 
study and investigate the first approach which seems to suffice for now.  
Thanks!

> Or, of course, you could have a language
> that's like Beginner without `length`, but that's probably too much
> trouble for your students to set up.

I suppose it would --- if they'd submit from home, say.

-- 
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/CBDxkV-H6eGfxTHxroWHOk7PEiKvAyFFHsfjlcbww4dNxIoZZF3a-mXJ-ETXE0gAQZ6hcfATO3cNXYH8L-C061cxASI1jxr3FsmEP4huhS0%3D%40protonmail.com.


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

2019-09-25 Thread 'Wayne Harris' via Racket Users
I think my message below neither asked any question nor did it contain the 
adequate politeness which I so much think every e-mail should have.  Looking at 
it in retrospective, it seems wild that *I* did let a message like that go by.  
Do believe me that I'm not saying this because I need help, but because I 
really consider a privilege to have access to a mail list of what I consider 
outstanding researchers.  (And I'd set myself to the highest standards even if 
it were not.)  (Yes, I'm still looking for a way to forbid the use of certain 
functions in code submissions of the handin-server.  I'm not in a hurry.  My 
objective is to prepare my tools now.  When the time comes, I'll be ready.)  
Thank you and do please forgive me if my words lacked the proper adequacy.

‐‐‐ Original Message ‐‐‐
On Saturday, September 21, 2019 1:17 PM, 'Wayne Harris' via Racket Users 
 wrote:

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

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


Re: [racket-users] Re: drracket: disabling tools in edit -> preferences -> tools

2019-09-21 Thread 'Wayne Harris' via Racket Users
‐‐‐ Original Message ‐‐‐
On Friday, September 20, 2019 3:04 PM, gfb  wrote:

> Yes, the  How To Design Programs  (and possibly  DeinProgramm ) tool relies 
> on the  Test Engine  tool.
>
> If you have a moment to do so, I'd encourage filing this consequence as an 
> issue on GitHub.

Done.

  https://github.com/racket/drracket/issues/308

Thanks!

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


[racket-users] drracket: disabling tools in edit -> preferences -> tools

2019-09-20 Thread 'Wayne Harris' via Racket Users
FWIW, I opened DrRacket (on a Windows system) and disabled some tools in 
preference -> tools.  On restart, I got a dialog with title DrRacket Internal 
Error saying

  preferences:get: tired to get a preference but not default set for 
'test-engine:enable?'.

Pressing okay on the dialog window, just closed it.  A black-console window 
stayed open, but DrRacket wouldn't start.  I opened racket-prefs.rktd and 
removed the line

 (((lib "test-engine") ("test-tool.scm")) skip)

and restarted it.  It came back alive.

I then disabled all tools and restarted.  That worked.  So maybe I disabled a 
tool that another one needed.

-- 
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/5LnFNGMZEjOuiF1v1ej53jN1fmbVwzieTgcSP9cDY40T4Go2ufM_b-fKW7AwMML09bwibSspRDv9Z_5xg75LWlUoyxinVBCKwnwXy3FJCqs%3D%40protonmail.com.


Re: [racket-users] handin-server: writing a first checker

2019-08-23 Thread 'Wayne Harris' via Racket Users
On Friday, August 23, 2019 2:59 PM, Shu-Hung You 
 wrote:

> I forgot to CC my reply to the list. The case here is that the user
> account data in `users.rktd` only contain one field but the default
> `extra-fields` configuration requires 3 extra fields. The error
> message probably comes from some (map cons  ...)
> expression that resides in the server code.

And I, in turn, probably only followed up to Shu-Hung.  The problem was a bad 
users.rktd which was solved after Shu-Hung's remark.  The software runs fine 
and I'm studying how to customize checkers.  Thank you!

-- 
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/FGWty_xOz_qnSmVsSa8helRfEXwSljx0Y84va2ohTF-hnZ4O82SmCOkhlCyTDVk3dcXhXOXbK-paRMquT3fbOnFNFHvY_gpuf7wPUECnITc%3D%40protonmail.com.


[racket-users] handin-server: writing a first checker

2019-08-21 Thread 'Wayne Harris' via Racket Users
I haven't been able to write a first checker.  I'm always getting

  map: all lists must have same size

in the server's log.

The submission always shows this in the log file:

[16|2019-08-21T21:12:35] connect from 191.35.15.190
[16|2019-08-21T21:12:39] running 12KB (123MB 133MB)
[16|2019-08-21T21:12:39] login: (wharr...@protonmail.com)
[16|2019-08-21T21:12:39] assignment for (wharr...@protonmail.com): assignment-1
[16|2019-08-21T21:12:40] timeout-control: reset
[16|2019-08-21T21:12:40] checking assignment-1 for (wharr...@protonmail.com)
[16|2019-08-21T21:12:42] running 37KB (123MB 133MB)
[16|2019-08-21T21:12:46] running 37KB (123MB 133MB)
[16|2019-08-21T21:12:49] running 39KB (123MB 133MB)
[16|2019-08-21T21:12:52] ERROR: map: all lists must have same size
[16|2019-08-21T21:12:52]   first list length: 3
[16|2019-08-21T21:12:52]   other list length: 1
[16|2019-08-21T21:12:52]   procedure: #

It also pops up the message error message to the student in DrRacket.

Any ideas what's causing this?

Taking the typical checker from the documentation, I started with:

(module checker handin-server/checker
  (check: :language  '(special intermediate)
(!procedure Fahrenheit->Celsius 1)
(!test (Fahrenheit->Celsius  32)   0)
(!test (Fahrenheit->Celsius 212) 100)
(!test (Fahrenheit->Celsius  -4) -20)))

My student code in DrRacket is set to intermediate language and the
code is:

(define (Fahrenheit->Celsius x)
  (* 5/9 (- x 32)))

(check-expect (Fahrenheit->Celsius 32) 0)

Here's my server configuration:

$ cat config.rktd
 ((active-dirs ("assignment-1"))
  (allow-web-upload #t)
  (allow-new-users #t)
  (master-password "4c96f8324e3ba54a99e78249b95daa30"))
$

$ cat users.rktd
(
 (wharr...@protonmail.com ("4c96f8324e3ba54a99e78249b95daa30" "Wayne Harris"))
)
$

$ cat assignment-1/checker.rkt
(module checker handin-server/checker
  (check: :language  '(special intermediate)
(!procedure Fahrenheit->Celsius 1)
(!test (Fahrenheit->Celsius  32)   0)
(!test (Fahrenheit->Celsius 212) 100)
(!test (Fahrenheit->Celsius  -4) -20)))
$

-- 
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/Le2v4fuorTS76ru-EzIcXTxB9t0I3wyV56qTFtRFY8cErV3l4mIJVUsi-s9qSlv7Q_2PVix-prxqDh5noOcmrlm3yyeB7gdBx02fwaUICW8%3D%40protonmail.com.


Re: [racket-users] does handin-server really need racket/gui/base?

2019-08-21 Thread 'Wayne Harris' via Racket Users
On Monday, August 19, 2019 10:40 PM, John Clements  
wrote:

> I’m not looking at the code here, but I believe the issue here is that the 
> handin-server receives user code in a serialized-could-contain-images-format 
> that can’t be decoded properly without importing the gui libraries.

That makes sense.

> It seems not implausible to me that you could special-case all-text 
> submissions to build a handin-server that doesn’t require the gui pieces.

That'd be an interesting addition to handin-server.  I'd love to contribute 
that, but I need to see if I can understand enough to make it.  Thanks for the 
idea!

> BUT,
>
> I’m here to tell you that I also run the handin server on a headless UNIX 
> system (currently Debian 9) with no problems.
>
> Specifically, I use tigervnc to create an x session, then connect to it 
> remotely (using a local vnc client) and start the handin server with an 
> active X connection.
>
> Let me know if you need more clues on this setup; there are a whole bunch of 
> things that can go wrong.

Thanks a lot!  I did make it: I installed Xming on my Windows system and used 
PuTTY's X11-configuration.  The server ran fine!  (Now I'm free to study how to 
implement a checker!)  Thanks for your help!

-- 
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/FgpfMl4f7STt9TrXMSVMGIggf3c9PgLQB2k9HEm-6uEBUzlCYcRwUKPdr71pnBPRhLW07rVERtA7uWXQePv0r5mM6EzaofLb70OUN-7kxLc%3D%40protonmail.com.


[racket-users] does handin-server really need racket/gui/base?

2019-08-16 Thread 'Wayne Harris' via Racket Users
I tried the handin-server on a Windows computer and it worked just
fine.  Now I'm trying it on a headless UNIX system and, upon first run,
I got:

$ racket -l handin-server
Unable to init server: Could not connect: Connection refused
Gtk initialization failed for display ":0"
  context...:
   "/usr/share/racket/pkgs/gui-lib/mred/private/wx/gtk/queue.rkt": [running 
body]
   temp37_0
   for-loop
   run-module-instance!125
   for-loop
   [repeats 1 more time]
   run-module-instance!125
   for-loop
   [repeats 1 more time]
   run-module-instance!125
   do-dynamic-require5
   "/usr/share/racket/pkgs/gui-lib/mred/private/wx/platform.rkt": [running body]
   temp37_0
   for-loop
   run-module-instance!125
   for-loop
   ...

Then taking a peek at

  ~/.racket/7.2/pkgs/handin/handin-server/main.rkt

I saw

  (require ...
 ;; workaround for a confusing problem: without this, the gui
 ;; gets initialized in a handler (since checks use it, and
 ;; they're being required dynamically), and further handlers
 ;; will fail with "queue-callback: eventspace is shutdown",
 ;; requiring it here makes it avoids killing the eventspace
 racket/gui/base)

Just to see what happens, I commented out the racket/gui/base
requirement and the server ran, but the comment says there'll be a
confusing problem.

$ racket -l handin-server
[-|2019-08-17T01:52:22] *** embedded web server started
[-|2019-08-17T01:52:22] Cleaning up all submission directories
[-|2019-08-17T01:52:22] *** handin server started on port 7979

Why does the server need anything GUI-related?  How do you run this
server in production?

-- 
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/RxyC6B4i7HgNSuVjlatCo9H-fgEEC2x2L38zkodCjrx8FqWGGkkBEIhW-ndhGc-ieeByffOnG81S9kvYd-PHt1J5wfO1cTvZko8OgqCdXL8%3D%40protonmail.com.


Re: [racket-users] web-server: how to save database results in memory across all requests?

2019-08-14 Thread 'Wayne Harris' via Racket Users
On Tuesday, August 13, 2019 5:46 PM, George Neuner  wrote:

> 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.

Very cool solution.  It works as expected.  Thanks for sharing!  That gives
us closures which are thread-global.  Cool!

-- 
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/O98QMFkv0sRRg3Dik8724-0tXMjSLk8s_OO8qAq36EsixyLDDE06W0QNBeGFXrFap6yRKG_y82eGdunArcrBLpCuB2NT3XaHIPflFMtWe10%3D%40protonmail.com.


Re: [racket-users] web-server: how to save database results in memory across all requests?

2019-08-13 Thread 'Wayne Harris' via Racket Users
On Tuesday, August 13, 2019 9:51 PM, Philip McGrath  
wrote:

> The relevant chapter of the reference is "Concurrency and Parallelism" 
> (https://docs.racket-lang.org/reference/threads.html):
>
>> All constant-time procedures and operations provided by Racket are 
>> thread-safe because they are atomic. For example, 
>> [set!](https://docs.racket-lang.org/reference/set_.html#%28form._%28%28quote._~23~25kernel%29._set%21%29%29)
>>  assigns to a variable as an atomic action with respect to all threads, so 
>> that no thread can see a “half-assigned” variable. Similarly, 
>> [vector-set!](https://docs.racket-lang.org/reference/vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-set%21%29%29)
>>  assigns to a vector atomically. The 
>> [hash-set!](https://docs.racket-lang.org/reference/hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash-set%21%29%29)
>>  procedure is not atomic, but the table is protected by a lock; see [Hash 
>> Tables](https://docs.racket-lang.org/reference/hashtables.html) for more 
>> information.

How can I tell a procedure is constant-time?

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


Re: [racket-users] web-server: how to save database results in memory across all requests?

2019-08-13 Thread 'Wayne Harris' via Racket Users
Thanks!  Here's what I did in shared-model.rkt:

(define *db* (box #f))
(define (get-in-memory-results)
  (let ([in-mem (unbox *db*)])
(if in-mem
(begin (displayln "database: cache hit")
   in-mem)
(begin (displayln "database: cache miss")
   (set-box! *db* "initial data")
   (unbox *db*)

(define (set-in-memory-results! s)
  (set-box! *db* s))

The only place in

  https://docs.racket-lang.org/reference/boxes.html

that mentions the word "atomic" is in box-cas!

  
https://docs.racket-lang.org/reference/boxes.html#%28def._%28%28quote._~23~25kernel%29._box-cas%21%29%29

How would I know box mutation is atomic?

Is structure mutation atomic?  After sending my previous message, I
remembered reading about structure mutation in How to Design Programs.
I looked it up again and had written this following code, which also
worked as I expected --- but I don't know if the mutation is atomic.

(define-struct database (data) #:mutable #:transparent)
(define *db* (make-database #f))

(define (get-in-memory-results)
  (let ([in-mem (database-data *db*)])
(if (string? in-mem)
(begin (displayln "database: cache hit")
   in-mem)
(begin (displayln "database: cache miss")
   (set-database-data! *db* "fresh data")
   (database-data *db*)

(define (set-in-memory-results! s)
  (set-database-data! *db* s))

On Tuesday, August 13, 2019 9:16 PM, Jay McCarthy  
wrote:

> I think it is pretty simple.
>
> (define (make-periodically-updating-value compute1)
>   (define the-data (box (compute1)))
>   (define the-updater-t
> (thread
>  (λ ()
>(let loop ()
>  (set-box! the-data (compute1))
>  (sleep interval)
>  (loop)
>   (λ ()
> (unbox the-data)))
>
> (define get-the-data/cache
>   (make-periodically-updating-value get-the-data/for-realsies))
>
>
> Box mutation is atomic, so you don't need locks or anything. It would
> be more complicated if you want to not compute it initially.
>
> -
>
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
>
> On Tue, Aug 13, 2019 at 7:53 PM Wayne Harris wharr...@protonmail.com wrote:
>
> > Is there an example somewhere showing how this could be done? My wish is to 
> > have one thing (a thread or something) periodically updating data (say 
> > every 30 minutes) and all servlets handling http connections reading. It is 
> > perfectly fine for me if while something writes the data, everything else 
> > is blocked waiting.
> > Having said that, I think this might be getting out of my league. (I'm 
> > reading about events in the hope I can find a way.) I have very basic 
> > understanding of Racket's primitives; never done anything involving threads 
> > or any kind of concurrency. If there's no trivial way to do that, I'll 
> > leave it for some other future project.
> > On Tuesday, August 13, 2019 5:07 PM, Jay McCarthy jay.mccar...@gmail.com 
> > wrote:
> >
> > > Hi Wayne,
> > > Your `in-memory-database` is a parameter. Parameters are
> > > thread-specific storage [1]. Every request in the web-server is
> > > handled by a different thread, so I think this will not work how you
> > > think it should.
> > > Jay
> > >
> > > 1.  
> > > https://docs.racket-lang.org/reference/parameters.html#(form._((lib._racket%2Fprivate%2Fmore-scheme..rkt)._parameterize))


-- 
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/Cm8bvFYZUclwV5V1ClD-Sbs4XzxatJq43MwxAQpI2fB2qOfXLuTsedDO5ZiUlsSPFx8YskXTReXys6-BlA36DLg9Nm_FcNhIsm32cgCQwrI%3D%40protonmail.com.


Re: [racket-users] web-server: how to save database results in memory across all requests?

2019-08-13 Thread 'Wayne Harris' via Racket Users
Is there an example somewhere showing how this could be done?  My wish is to 
have one thing (a thread or something) periodically updating data (say every 30 
minutes) and all servlets handling http connections reading.  It is perfectly 
fine for me if while something writes the data, everything else is blocked 
waiting.

Having said that, I think this might be getting out of my league.  (I'm reading 
about events in the hope I can find a way.)  I have very basic understanding of 
Racket's primitives; never done anything involving threads or any kind of 
concurrency.  If there's no trivial way to do that, I'll leave it for some 
other future project.

On Tuesday, August 13, 2019 5:07 PM, Jay McCarthy  
wrote:

> Hi Wayne,
>
> Your `in-memory-database` is a parameter. Parameters are
> thread-specific storage [1]. Every request in the web-server is
> handled by a different thread, so I think this will not work how you
> think it should.
>
> Jay
>
> 1.  
> https://docs.racket-lang.org/reference/parameters.html#(form._((lib._racket%2Fprivate%2Fmore-scheme..rkt)._parameterize))

-- 
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/Leya9p_dgjiIHEA6QW9U66OciCvpvlplGQxoloBk95YjLTvUbV-dnf2lRStEN-qBn4929FUlMf1bIFcrgnDBRXOdO0k9hy3WvByoJ67T6Ws%3D%40protonmail.com.


Re: [racket-users] web-server: how to save database results in memory across all requests?

2019-08-13 Thread 'Wayne Harris' via Racket Users
On Tuesday, August 13, 2019 2:17 PM, George Neuner  wrote:

> 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.

I think it's what I'm doing below --- I require shared-model.rkt and call

  (get-in-memory-results)

when I need it.

> 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:.

The documentation doesn't say that #:launch-browser? would have this effect.  
Nevertheless, I tried it with #:launch-browser? #f, but the behavior was the 
same.

(define (main)
(displayln "Now serving...")
(serve/servlet dispatch
   #:launch-browser? #f
   #: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))

A browser window didn't open.  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

> That said:
>
> What DBMS are you using? 

I'm using sqlite and in other applications I store lists on disk.  These are 
very small applications and it's useful not to depend on other software and 
libraries.

> [...] 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.

Thanks for the info!

> > --- 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")
>

[racket-users] web-server: how to save database results in memory across all requests?

2019-08-13 Thread 'Wayne Harris' via Racket Users
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?

--- 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/Xuxg1t5egDEkFLVsH-Ch9KZyTqtLjhATNOPD-HeXZgcOc2mXr8qlXS3fZTZRh90xd2kvhdILhNjKwUllUirBcnTrEzPDTiw_hJDVEp5FjpM%3D%40protonmail.com.