Re: [racket-users] Syntax Parse Bee 2021

2021-08-03 Thread Stephen De Gabrielle
The bee is still on!
Have you made a contribution yet?

Write a macro with Racket this summer! Win stickers!

The purpose of this event is to grow the syntax-parse-example documentation
and repository to grow as a resource for the Racket community. (You can
also contribute directly to the syntax parse examples repository)

It's like a Quilting Bee, but for syntax parse macros!

Submit by opening an issue here:
https://github.com/syntax-objects/Summer2021/issues/new?assignees==entry=enter-the-syntax-parse-bee.md=%5Bentry+-+name%2Fdescription+of+macro%5D



On Tue, 13 Jul 2021 at 09:06, Stephen De Gabrielle 
wrote:

> It’s very exciting seeing the entries pouring in.
>
> Reminder: Racket includes a macro debugger
>  to make it
> easier for the experienced to debug their macros and for beginners to study
> their behaviour: https://docs.racket-lang.org/macro-debugger/index.html
>
> Click ‘Macro Stepper’ in DrRacket or M-x  racket-stepper-mode in Racket
> Mode if you prefer Emacs: https://www.racket-mode.com/#Macro-expand
>
> Bw
> Stephen
>
> On Thu, 1 Jul 2021 at 01:23, Ben Greenman 
> wrote:
>
>> Hi folks,
>>
>> *Write a macro with Racket this summer! Win stickers!*
>>
>> The purpose of this event is to grow the syntax-parse-example
>> documentation and repository to grow as a resource for the Racket
>> community. But you do not need to submit a full example to win stickers ---
>> any syntax-parse macro counts.
>>
>> *It's like a Quilting Bee, but for syntax parse macros!*
>>
>> Ground Rules:
>>
>>- you can write any macro as long as it uses syntax-parse somehow
>>- enter as many times as you like
>>- the first 20 individuals who enter will win exclusive stickers
>>- open July 1 to September 1
>>
>> Submit by opening an issue here:
>>
>>
>> https://github.com/syntax-objects/Summer2021/issues/new?assignees==entry=enter-the-syntax-parse-bee.md=%5Bentry+-+name%2Fdescription+of+macro%5D
>>
>> To help you get started, we suggest two categories of before-and-after
>> macro:
>>
>>1. *Code Cleaning* : Introduce a macro where there was none before.
>>Look for ways to make your source code more beautiful and/or less
>>repetitive.
>>2. *Macro Engineering* : Use the tools in syntax-parse to improve an
>>existing  macro (which may or may not currently use syntax-parse). Try to
>>make the old macro more maintainable, more robust against errors, and/or
>>more flexible.
>>
>> Updates will be via Racket News, Racket-Users, Slack, Discord & Reddit.
>>
>> Whatever you decide, we hope that you learn and have fun!
>>
>> - Ben + Stephen
>>
>>
>> PS a 'Bee' is a community effort toward a common goal. A quilting bee is
>> for
>> making a quilt. In this case the quilt is a patchwork of syntax-parse
>> macros.
>>
>> - - -
>>
>> Syntax parse docs:
>>  https://docs.racket-lang.org/syntax/stxparse.html
>>
>> Syntax parse examples:
>>  https://docs.racket-lang.org/syntax-parse-example/
>>
>> Extra syntax classes:
>>  https://docs.racket-lang.org/syntax-classes/
>>
>> Mythical Macros tutorial:
>>  https://soegaard.github.io/mythical-macros/
>>
>> Macros and Languages in Racket book draft:
>>  http://rmculpepper.github.io/malr/
>>
>> Fine print:
>>
>>- this is an UNOFFICIAL event run by Racket users (@spdegabrielle and
>>@bennn)
>>- entries must be submitted under the MIT license [1] for code and
>>under CC [2] for accompanying prose
>>- stickers will be mailed via USPS; international entries are allowed
>>- please abide by the Racket Friendly Environment Policy [3]
>>
>>
>> [1]
>> https://github.com/racket/racket/blob/master/racket/src/LICENSE-MIT.txt
>> [2] http://creativecommons.org/licenses/by/4.0/
>> [3] https://racket-lang.org/friendly.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/CAFUu9R6kCG%2BXFnYwOnD_9XyfNq%2BNbJnPVA_rpD4vGKPkzSXBDA%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/CAGHj7-JNyHedprSQp1hbKO4JvovG%3DNsrxTdCqYOu0xO-3CKTRQ%40mail.gmail.com.


Re: [racket-users] Equivalent of exec

2021-08-03 Thread Shu-Hung You
On Tue, Aug 3, 2021 at 1:13 PM George Neuner  wrote:
>
>
> On 8/3/2021 1:03 PM, Norman Gray wrote:
> > On 3 Aug 2021, at 17:38, George Neuner wrote:
> >
> >> Racket is multi-platform and tries to present a common API for
> >> dealing with underlying operating systems.  Windows is an important
> >> platform, but Windows does not have the concept of fork/exec ... so
> >> Racket doesn't offer it either.
> >
> > Ah: good point.  That said, I'd have guessed that similar behaviour --
> > 'invoke and don't return' -- would be at least emulatable on Windows,
> > though.
>
> Well, yes, but the behavior of  'CreateProcess'  is quite different from
> the combination of  'forkv/execv'.
>
> In Windows, the new child is not (even virtually) a copy of its parent -
> it is a completely new process context.  Although it is possible for the
> parent to pass to and/or share resources with the child, this doesn't
> include a copy of its memory context [so no 'fork'].  The parent
> receives several handles to the new child process that must explicitly
> be closed in order to detach it.
>
> As a technical matter, emulating Unix 'fork' in Windows ... i.e. making
> an independent copy of the parent process that continues running from
> where the parent stopped ... is possible, but it is difficult and
> requires debugger like behavior to manipulate the child's memory map and
> copy data from one process to the other.
>
>
> >> The closest (and simplest) you can achieve, I think, would to start
> >> Vi asynchronously using 'process*' and then terminate the Racket script.
> >
> > I don't think that works, since terminating the Racket process would
> > also terminate its child (unless I were to do something similar to the
> > usual extra fork to disconnect the child from its parent, and... hmmm,
> > this isn't sounding very rackety).
> >
> > Doing the next simplest thing -- using (process* "/usr/bin/vi"
> > '("foo")) and calling (control 'wait) using the result -- doesn't seem
> > to work, but instead just hangs, until I kill the vi child process.
> > Without digging into it too deeply, I'd guess that's because of the
> > usual problems about wiring up FDs and buffers and so on, which I was
> > rather hoping to avoid.
> >
>
> Hmm.  According to the docs  'process'  (no asterisk) executes the
> command asynchronously ... I assumed  'process*' would do the same.
> Unfortunately 'process' returns ports that must be closed explicitly.
>
> Sorry if I led you astray.
>

I tried directly passing the current input port and the current output
port in Racket to the subprocess. As long as they are the original
standard input and the standard output ports, the program seems to
work.

*However*, I am not sure if Racket's runtime still manages the input
and the output.

#lang racket/base

(require racket/match
 racket/system)

(match-define (list subprocess-stdout subprocess-stdin system-pid
subprocess-stderr procctl)
  (process*/ports (current-output-port) (current-input-port)
(current-error-port)
  "/usr/bin/vim"))

(procctl 'wait)

The following variant prevents Racket from terminating the spawn
subprocess. Sadly, it did not work when I changed sh to vim. The error
message from vim was 'Vim: Error reading input, exiting...'.

#lang racket/base

(require racket/match
 racket/system)

(match-define (list subprocess-stdout subprocess-stdin system-pid
subprocess-stderr procctl)
  (parameterize ([current-subprocess-custodian-mode #f])
(process*/ports (current-output-port) (current-input-port)
(current-error-port)
"/bin/sh"
"-c"
"echo sh sleeping; sleep 5; echo sh alive and well")))

(displayln "leave racket")



>
> > Best wishes,
> >
> > Norman
>
> 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/720fc753-7972-b8c1-76ec-4d2a65a763f2%40comcast.net.

-- 
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/CAMTzy%2BYdHfw718MkhW7MRTtgSyKZ1rgPrWZD%2B47bXS%2B2JGzFLQ%40mail.gmail.com.


Re: [racket-users] Equivalent of exec

2021-08-03 Thread George Neuner



On 8/3/2021 1:03 PM, Norman Gray wrote:

On 3 Aug 2021, at 17:38, George Neuner wrote:

Racket is multi-platform and tries to present a common API for 
dealing with underlying operating systems.  Windows is an important 
platform, but Windows does not have the concept of fork/exec ... so 
Racket doesn't offer it either.


Ah: good point.  That said, I'd have guessed that similar behaviour -- 
'invoke and don't return' -- would be at least emulatable on Windows, 
though.


Well, yes, but the behavior of  'CreateProcess'  is quite different from 
the combination of  'forkv/execv'.


In Windows, the new child is not (even virtually) a copy of its parent - 
it is a completely new process context.  Although it is possible for the 
parent to pass to and/or share resources with the child, this doesn't 
include a copy of its memory context [so no 'fork'].  The parent 
receives several handles to the new child process that must explicitly 
be closed in order to detach it.


As a technical matter, emulating Unix 'fork' in Windows ... i.e. making 
an independent copy of the parent process that continues running from 
where the parent stopped ... is possible, but it is difficult and 
requires debugger like behavior to manipulate the child's memory map and 
copy data from one process to the other.



The closest (and simplest) you can achieve, I think, would to start 
Vi asynchronously using 'process*' and then terminate the Racket script.


I don't think that works, since terminating the Racket process would 
also terminate its child (unless I were to do something similar to the 
usual extra fork to disconnect the child from its parent, and... hmmm, 
this isn't sounding very rackety).


Doing the next simplest thing -- using (process* "/usr/bin/vi" 
'("foo")) and calling (control 'wait) using the result -- doesn't seem 
to work, but instead just hangs, until I kill the vi child process.  
Without digging into it too deeply, I'd guess that's because of the 
usual problems about wiring up FDs and buffers and so on, which I was 
rather hoping to avoid.




Hmm.  According to the docs  'process'  (no asterisk) executes the 
command asynchronously ... I assumed  'process*' would do the same. 
Unfortunately 'process' returns ports that must be closed explicitly.


Sorry if I led you astray.



Best wishes,

Norman


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/720fc753-7972-b8c1-76ec-4d2a65a763f2%40comcast.net.


Re: [racket-users] Equivalent of exec

2021-08-03 Thread Norman Gray



George, hello.

On 3 Aug 2021, at 17:38, George Neuner wrote:

Racket is multi-platform and tries to present a common API for dealing 
with underlying operating systems.  Windows is an important platform, 
but Windows does not have the concept of fork/exec ... so Racket 
doesn't offer it either. 


Ah: good point.  That said, I'd have guessed that similar behaviour -- 
'invoke and don't return' -- would be at least emulatable on Windows, 
though.


The closest (and simplest) you can achieve, I think, would to start Vi 
asynchronously using 'process*' and then terminate the Racket script.


I don't think that works, since terminating the Racket process would 
also terminate its child (unless I were to do something similar to the 
usual extra fork to disconnect the child from its parent, and... hmmm, 
this isn't sounding very rackety).


Doing the next simplest thing -- using (process* "/usr/bin/vi" '("foo")) 
and calling (control 'wait) using the result -- doesn't seem to work, 
but instead just hangs, until I kill the vi child process.  Without 
digging into it too deeply, I'd guess that's because of the usual 
problems about wiring up FDs and buffers and so on, which I was rather 
hoping to avoid.


Best wishes,

Norman


--
Norman Gray  :  http://www.astro.gla.ac.uk/users/norman/it/
Research IT Coordinator  :  School of Physics and Astronomy

--
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/D9F0F60A-D41F-454B-AC8C-9E9FD140F9D9%40glasgow.ac.uk.


Re: [racket-users] Equivalent of exec

2021-08-03 Thread George Neuner

On 8/3/2021 12:14 PM, Norman Gray wrote:


Greetings.

I can't find a way of doing something equivalent to exec in Racket.  
Is this Hard, or am I just missing it?


By 'exec', I mean the equivalent of replacing the process with a new 
image, as distinct from `system` (and friends) or `process` (and 
friends), which are concerned with creating a subprocess, controlling 
it, and handling its exit.


In my particular case, I want to call vi at the end of a Racket 
script.  I'm sure it's possible to do that with process and friends, 
but it would require being careful about input and output ports, 
worrying about buffering, whether things are terminals or not, and so 
on and on.


I can imagine this isn't trivial as an implementation issue -- I can 
see there would potentially be custodians to worry about (*waves hands 
vaguely*), but I'd be surprised if it were impossible.  However I'm 
completely failing to find anything on [1], searching for eg 'exec' or 
'return' (as in 'does not return'); and 'exec' isn't a very handy 
search term on the web.


Thanks for any pointers,

Norman

[1] https://docs.racket-lang.org/reference/subprocess.html



Hi Norman,

Racket is multi-platform and tries to present a common API for dealing 
with underlying operating systems.  Windows is an important platform, 
but Windows does not have the concept of fork/exec ... so Racket doesn't 
offer it either.  The closest (and simplest) you can achieve, I think, 
would to start Vi asynchronously using 'process*' and then terminate the 
Racket script.


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/2ab522f1-ea58-3a34-3ed5-24998a64da0f%40comcast.net.


[racket-users] Equivalent of exec

2021-08-03 Thread Norman Gray



Greetings.

I can't find a way of doing something equivalent to exec in Racket.  Is 
this Hard, or am I just missing it?


By 'exec', I mean the equivalent of replacing the process with a new 
image, as distinct from `system` (and friends) or `process` (and 
friends), which are concerned with creating a subprocess, controlling 
it, and handling its exit.


In my particular case, I want to call vi at the end of a Racket script.  
I'm sure it's possible to do that with process and friends, but it would 
require being careful about input and output ports, worrying about 
buffering, whether things are terminals or not, and so on and on.


I can imagine this isn't trivial as an implementation issue -- I can see 
there would potentially be custodians to worry about (*waves hands 
vaguely*), but I'd be surprised if it were impossible.  However I'm 
completely failing to find anything on [1], searching for eg 'exec' or 
'return' (as in 'does not return'); and 'exec' isn't a very handy search 
term on the web.


Thanks for any pointers,

Norman


[1] https://docs.racket-lang.org/reference/subprocess.html

--
Norman Gray  :  https://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK

--
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/9CD816A7-8DA1-4C50-9F18-534BFC65750B%40glasgow.ac.uk.