[racket-users] test user-interact function dont work

2019-02-16 Thread Joao Pedro Abreu De Souza
Hi everyone. I have a test of a user-related function that I don't can see
why don't work :

#lang racket

(require rackunit)
(require "../../main.rkt")




(check-equal?
(with-output-to-string (lambda ()
(with-input-from-string
"exit 0"
(lambda () 
(refine-main)
""
"Consigo sair antes de comecar o tutorial")




I think that this will call refine-main and, when refine-main do a
readline, will receive "exit 0" as string, and when display something, will
appear as return of with-output-to-string, but this code don't work :(

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Python's append vs Racket's append and helping novices understand the implications

2019-02-16 Thread David Van Horn
I've updated the docs to get to the point faster with some early examples.

http://dvanhorn.github.io/ralist/

David


On Sat, Feb 16, 2019 at 5:21 PM John Clements 
wrote:

> I struggled with whether to send that message… I saw the name, “random
> access lists”, thought, “hmm, I wonder what that would like”, and clicked
> on the link. I wound up reading a bit about whether I should use (first
> impresssion) superficial or in-depth contracts, and ran out of steam pretty
> quickly. Ultimately, of course, the real issue is that your documentation
> wasn’t designed to help python programmers jump into their first experience
> with Racket, but a link to your documentation has essentially just made you
> an involuntary ambassador.
>
>
> John
>
> > On Feb 16, 2019, at 14:00, David Van Horn  wrote:
> >
> > There are several examples for every function provided by the ralist
> library.  (And it's almost verbatim what's in the Racket reference for
> pairs and lists.)
> >
> > But... I can add some early examples.  No problem.
> >
> > David
> >
> > On Sat, Feb 16, 2019, 4:00 PM John Clements 
> wrote:
> > The pointer to RaLists would be much more enticing if we could convince
> David Van Horn to begin his documentation with a couple of small examples….
> >
> > John
> >
> > > On Feb 13, 2019, at 14:35, Stephen De Gabrielle <
> spdegabrie...@gmail.com> wrote:
> > >
> > > Thanks
> > >
> > > I should note that anyone with a GitHub account can edit
> https://github.com/racket/racket/wiki/Python-to-Racket
> > >
> > > S.
> > >
> > > On Wed, 13 Feb 2019 at 21:26, Matthias Felleisen <
> matth...@felleisen.org> wrote:
> > >
> > > Not until there’s demand. I think we do see demand for Python
> transfers.
> > >
> > >
> > >
> > > > On Feb 13, 2019, at 3:11 PM, Stephen De Gabrielle <
> spdegabrie...@gmail.com> wrote:
> > > >
> > > > Should there be similar pages for Javascript, Java,C#, C/C++, Ruby,
> PHP, Visual Basic, Scratch and Haskell?
> > > >
> > > > S.
> > > >
> > > > On Wed, Feb 13, 2019 at 8:03 PM Stephen De Gabrielle <
> spdegabrie...@gmail.com> wrote:
> > > > I created a DRAFT page on the Racket GitHub wiki:
> > > >   https://github.com/racket/racket/wiki/Python-to-Racket
> > > > It links to a 'Choosing a data structure' page
> https://github.com/racket/racket/wiki/Choosing-a-data-structure
> > > > - this just as copy of the table created by Jens Axel Søgaard at:
> https://stackoverflow.com/questions/27584416/in-racket-what-is-the-advantage-of-lists-over-vectors/27589146#27589146
> )
> > > >
> > > > Please edit/delete as you see fit
> > > >
> > > > Kind regards
> > > > Stephen
> > > >
> > > >
> > > > On Tue, Feb 12, 2019 at 5:20 PM Matthias Felleisen <
> matth...@felleisen.org> wrote:
> > > >
> > > > This is perfect! Thanks — Matthias
> > > >
> > > >
> > > >
> > > >
> > > > > On Feb 11, 2019, at 11:04 PM, Claes Wallin (韋嘉誠) 
> wrote:
> > > > >
> > > > > For anyone creating such a web page for Python to Racket
> specifically,
> > > > > there is probably a great deal of inspiration, and reminders of
> > > > > stumbling blocks, to be found in Arne Babenhauserheide's
> > > > > https://www.draketo.de/py2guile book (available online for free)
> about
> > > > > going from Python to Guile Scheme.
> > > > >
> > > > > --
> > > > >   /c
> > > > >
> > > > > On Sun, Feb 3, 2019 at 7:00 AM Matthias Felleisen
> > > > >  wrote:
> > > > >> Racket needs *you*. Please.
> > > > >>
> > > > >> The proper approach is to have short pages for different language
> immigration groups: Python and R come to mind as obvious examples but I am
> sure there are others.
> > > > >>
> > > > >> What I mean is we need help and *you* can help. Let me explain it
> with the Python example:
> > > > >>
> > > > >> 1. Set up a page (wiki?) called “From Python to Racket”
> > > > >>
> > > > >> 2. Create two sections that are immediately visible from the top:
> > > > >>
> > > > >>— idioms
> > > > >>— performance pitfalls
> > > > >>
> > > > >> 3. In the specific case of Python, the second subsection needs to
> start with a subsection on
> > > > >>
> > > > >>— Python Lists aren’t Racket Lists
> > > > >>— then point to data/ralis and show how to transliterate
> the loop/append example like this
> > > > >>— optionally also show the more native Racket idiom
> > > > >>
> > > > >> 4. When anyone observers another blog/social media/whatever post
> on Racket is slow because I come from Python,
> > > > >>
> > > > >>(a) point the posters to the page  or
> > > > >>(b) if it is a new case, write a section for this example
> then do (a)
> > > > >>
> > > > >>
> > > > >> If you want to help advertise Racket to others, this is an
> excellent way of helping out.
> > > > >>
> > > > >> Thanks — Matthias
> > > > >>
> > > > >> [[ p.s. For my very first Python program (a couple of days before
> meeting with GvR), I used Python’s append and was annoyed beyond belief. ]]
> > > > >>
> > > > >>
> > > > >> --
> > > > >> You received th

Re: [racket-users] Questions about Scribble docs

2019-02-16 Thread David Storrs
On Sat, Feb 16, 2019 at 9:18 PM Greg Hendershott
 wrote:
>
> The package web site seems to think no packages have been built: The
> "Most recent build results" item is blank for every of the dozen
> packages I just checked.

Ah, that would do it.  Thanks.

>
> So I think that's one problem.
>
>
> When that's working normally, as it usually does, there are two levels
> of refresh:
>
> 1. The package catalog server points to e.g. your most recent commit
> on Git{Hub Lab}.com. You push a new commit. The package catalog might
> take an hour before it notices. This is the thing you can "kick" by
> logging in and choosing "Rescan my packges".
>
> 2. The build server runs daily. This is what builds your docs as part
> of building your package. So, even if it were working, now, it might
> take 24 hours. There's no way to nudge this AFAIK.
>
>
> On Sat, Feb 16, 2019 at 8:21 PM David Storrs  wrote:
> >
> > Do I need to do something particular to make the package server notice
> > my documentation?  I've got a scribblings/struct-plus-plus.scrbl file
> > but the package server is still listing it as "needs documentation".
> >
> > Separate but related, when I install a module and it builds the
> > documentation, is there a way to make it integrate with the built-in
> > docs so that I can load it in the browser and search?
> >
> > --
> > 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.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Running raco setup from within DrRacket?

2019-02-16 Thread Greg Hendershott
p.s. If you wanted to do a general thing, for DrRacket, this is what I
was referring to. The README is probably enough of a hint, you don't
need to read the Emacs Lisp. :)

https://github.com/purcell/exec-path-from-shell

On Sat, Feb 16, 2019 at 10:07 PM Greg Hendershott
 wrote:
>
> From unsophisticated searching the source, it looks like the code to
> implement deps checking is in setup/private/pkg-deps.rkt -- "private"
> meaning you're not supposed to use it directly.
>
> It seems to be called from the `setup-core` function provided by
> (non-private) setup/setup-core.rkt. That seems to be controlled by a
> variety of parameters, including `check-dependencies`. You could
> probably figure out which ones to set, to approximate `raco setup
> ` as opposed to `raco setup` everything.
>
> Or...  system* raco is sounding nicer. But how to find its path.
>
> Are you on macOS?  If so, that's probably why raco isn't on the PATH.
> Every OS has odd things. Windows has it's share. macOS has one, which
> is that GUI apps' PATH doesn't inherit what you see in bash. (That's
> why emacs has exec-path-from-shell.)
>
> I'd suggest (find-system-path 'exec-file), which would be great in
> command-line racket. But in DrR that's something like
> "/Applications/Racket 7.0/DrRacket.app/Contents/MacOS/DrRacket".  Well
> I suppose you could do something like:
>
>(build-path (find-system-path 'exec-file) 'up 'up 'up 'up "racket"
> "bin" "raco")
>
> On Sat, Feb 16, 2019 at 12:34 AM  wrote:
> >
> > Using setup/setup works partially, but it doesn't seem to support package 
> > dependency checking (and the #:pkgs keyword argument isn't documented). I 
> > can't seem to find any programmatic alternative to the --check-pkg-deps and 
> > --unused-pkg-deps flags.
> >
> > On Friday, February 15, 2019 at 8:35:17 PM UTC-8, Matthias Felleisen wrote:
> >>
> >> See 
> >> https://docs.racket-lang.org/raco/setup-plt-plt.html?q=setup#%28def._%28%28lib._setup%2Fsetup..rkt%29._setup%29%29
> >>
> >> (require setup/setup)
> >>
> >> I think that’s what you want — Matthias
> >
> > --
> > 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.
> > For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Running raco setup from within DrRacket?

2019-02-16 Thread Greg Hendershott
>From unsophisticated searching the source, it looks like the code to
implement deps checking is in setup/private/pkg-deps.rkt -- "private"
meaning you're not supposed to use it directly.

It seems to be called from the `setup-core` function provided by
(non-private) setup/setup-core.rkt. That seems to be controlled by a
variety of parameters, including `check-dependencies`. You could
probably figure out which ones to set, to approximate `raco setup
` as opposed to `raco setup` everything.

Or...  system* raco is sounding nicer. But how to find its path.

Are you on macOS?  If so, that's probably why raco isn't on the PATH.
Every OS has odd things. Windows has it's share. macOS has one, which
is that GUI apps' PATH doesn't inherit what you see in bash. (That's
why emacs has exec-path-from-shell.)

I'd suggest (find-system-path 'exec-file), which would be great in
command-line racket. But in DrR that's something like
"/Applications/Racket 7.0/DrRacket.app/Contents/MacOS/DrRacket".  Well
I suppose you could do something like:

   (build-path (find-system-path 'exec-file) 'up 'up 'up 'up "racket"
"bin" "raco")

On Sat, Feb 16, 2019 at 12:34 AM  wrote:
>
> Using setup/setup works partially, but it doesn't seem to support package 
> dependency checking (and the #:pkgs keyword argument isn't documented). I 
> can't seem to find any programmatic alternative to the --check-pkg-deps and 
> --unused-pkg-deps flags.
>
> On Friday, February 15, 2019 at 8:35:17 PM UTC-8, Matthias Felleisen wrote:
>>
>> See 
>> https://docs.racket-lang.org/raco/setup-plt-plt.html?q=setup#%28def._%28%28lib._setup%2Fsetup..rkt%29._setup%29%29
>>
>> (require setup/setup)
>>
>> I think that’s what you want — Matthias
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Questions about Scribble docs

2019-02-16 Thread Greg Hendershott
p.s. As another example of the current breakage: All my own packages
that do have documentation, have yellow "This package needs
documentation" demerit badges, at the moment.

On Sat, Feb 16, 2019 at 9:17 PM Greg Hendershott
 wrote:
>
> The package web site seems to think no packages have been built: The
> "Most recent build results" item is blank for every of the dozen
> packages I just checked.
>
> So I think that's one problem.
>
>
> When that's working normally, as it usually does, there are two levels
> of refresh:
>
> 1. The package catalog server points to e.g. your most recent commit
> on Git{Hub Lab}.com. You push a new commit. The package catalog might
> take an hour before it notices. This is the thing you can "kick" by
> logging in and choosing "Rescan my packges".
>
> 2. The build server runs daily. This is what builds your docs as part
> of building your package. So, even if it were working, now, it might
> take 24 hours. There's no way to nudge this AFAIK.
>
>
> On Sat, Feb 16, 2019 at 8:21 PM David Storrs  wrote:
> >
> > Do I need to do something particular to make the package server notice
> > my documentation?  I've got a scribblings/struct-plus-plus.scrbl file
> > but the package server is still listing it as "needs documentation".
> >
> > Separate but related, when I install a module and it builds the
> > documentation, is there a way to make it integrate with the built-in
> > docs so that I can load it in the browser and search?
> >
> > --
> > 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.
> > For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Questions about Scribble docs

2019-02-16 Thread Greg Hendershott
The package web site seems to think no packages have been built: The
"Most recent build results" item is blank for every of the dozen
packages I just checked.

So I think that's one problem.


When that's working normally, as it usually does, there are two levels
of refresh:

1. The package catalog server points to e.g. your most recent commit
on Git{Hub Lab}.com. You push a new commit. The package catalog might
take an hour before it notices. This is the thing you can "kick" by
logging in and choosing "Rescan my packges".

2. The build server runs daily. This is what builds your docs as part
of building your package. So, even if it were working, now, it might
take 24 hours. There's no way to nudge this AFAIK.


On Sat, Feb 16, 2019 at 8:21 PM David Storrs  wrote:
>
> Do I need to do something particular to make the package server notice
> my documentation?  I've got a scribblings/struct-plus-plus.scrbl file
> but the package server is still listing it as "needs documentation".
>
> Separate but related, when I install a module and it builds the
> documentation, is there a way to make it integrate with the built-in
> docs so that I can load it in the browser and search?
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Questions about Scribble docs

2019-02-16 Thread David Storrs
Do I need to do something particular to make the package server notice
my documentation?  I've got a scribblings/struct-plus-plus.scrbl file
but the package server is still listing it as "needs documentation".

Separate but related, when I install a module and it builds the
documentation, is there a way to make it integrate with the built-in
docs so that I can load it in the browser and search?

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Python's append vs Racket's append and helping novices understand the implications

2019-02-16 Thread 'John Clements' via Racket Users
I struggled with whether to send that message… I saw the name, “random access 
lists”, thought, “hmm, I wonder what that would like”, and clicked on the link. 
I wound up reading a bit about whether I should use (first impresssion) 
superficial or in-depth contracts, and ran out of steam pretty quickly. 
Ultimately, of course, the real issue is that your documentation wasn’t 
designed to help python programmers jump into their first experience with 
Racket, but a link to your documentation has essentially just made you an 
involuntary ambassador.


John

> On Feb 16, 2019, at 14:00, David Van Horn  wrote:
> 
> There are several examples for every function provided by the ralist library. 
>  (And it's almost verbatim what's in the Racket reference for pairs and 
> lists.)
> 
> But... I can add some early examples.  No problem.
> 
> David
> 
> On Sat, Feb 16, 2019, 4:00 PM John Clements  wrote:
> The pointer to RaLists would be much more enticing if we could convince David 
> Van Horn to begin his documentation with a couple of small examples…. 
> 
> John
> 
> > On Feb 13, 2019, at 14:35, Stephen De Gabrielle  
> > wrote:
> > 
> > Thanks 
> > 
> > I should note that anyone with a GitHub account can edit 
> > https://github.com/racket/racket/wiki/Python-to-Racket
> > 
> > S.
> > 
> > On Wed, 13 Feb 2019 at 21:26, Matthias Felleisen  
> > wrote:
> > 
> > Not until there’s demand. I think we do see demand for Python transfers. 
> > 
> > 
> > 
> > > On Feb 13, 2019, at 3:11 PM, Stephen De Gabrielle 
> > >  wrote:
> > > 
> > > Should there be similar pages for Javascript, Java,C#, C/C++, Ruby, PHP, 
> > > Visual Basic, Scratch and Haskell?
> > > 
> > > S.
> > > 
> > > On Wed, Feb 13, 2019 at 8:03 PM Stephen De Gabrielle 
> > >  wrote:
> > > I created a DRAFT page on the Racket GitHub wiki:
> > >   https://github.com/racket/racket/wiki/Python-to-Racket
> > > It links to a 'Choosing a data structure' page 
> > > https://github.com/racket/racket/wiki/Choosing-a-data-structure
> > > - this just as copy of the table created by Jens Axel Søgaard at: 
> > > https://stackoverflow.com/questions/27584416/in-racket-what-is-the-advantage-of-lists-over-vectors/27589146#27589146)
> > > 
> > > Please edit/delete as you see fit
> > > 
> > > Kind regards
> > > Stephen
> > > 
> > > 
> > > On Tue, Feb 12, 2019 at 5:20 PM Matthias Felleisen 
> > >  wrote:
> > > 
> > > This is perfect! Thanks — Matthias
> > > 
> > > 
> > > 
> > > 
> > > > On Feb 11, 2019, at 11:04 PM, Claes Wallin (韋嘉誠)  
> > > > wrote:
> > > > 
> > > > For anyone creating such a web page for Python to Racket specifically,
> > > > there is probably a great deal of inspiration, and reminders of
> > > > stumbling blocks, to be found in Arne Babenhauserheide's
> > > > https://www.draketo.de/py2guile book (available online for free) about
> > > > going from Python to Guile Scheme.
> > > > 
> > > > -- 
> > > >   /c
> > > > 
> > > > On Sun, Feb 3, 2019 at 7:00 AM Matthias Felleisen
> > > >  wrote:
> > > >> Racket needs *you*. Please.
> > > >> 
> > > >> The proper approach is to have short pages for different language 
> > > >> immigration groups: Python and R come to mind as obvious examples but 
> > > >> I am sure there are others.
> > > >> 
> > > >> What I mean is we need help and *you* can help. Let me explain it with 
> > > >> the Python example:
> > > >> 
> > > >> 1. Set up a page (wiki?) called “From Python to Racket”
> > > >> 
> > > >> 2. Create two sections that are immediately visible from the top:
> > > >> 
> > > >>— idioms
> > > >>— performance pitfalls
> > > >> 
> > > >> 3. In the specific case of Python, the second subsection needs to 
> > > >> start with a subsection on
> > > >> 
> > > >>— Python Lists aren’t Racket Lists
> > > >>— then point to data/ralis and show how to transliterate the 
> > > >> loop/append example like this
> > > >>— optionally also show the more native Racket idiom
> > > >> 
> > > >> 4. When anyone observers another blog/social media/whatever post on 
> > > >> Racket is slow because I come from Python,
> > > >> 
> > > >>(a) point the posters to the page  or
> > > >>(b) if it is a new case, write a section for this example then 
> > > >> do (a)
> > > >> 
> > > >> 
> > > >> If you want to help advertise Racket to others, this is an excellent 
> > > >> way of helping out.
> > > >> 
> > > >> Thanks — Matthias
> > > >> 
> > > >> [[ p.s. For my very first Python program (a couple of days before 
> > > >> meeting with GvR), I used Python’s append and was annoyed beyond 
> > > >> belief. ]]
> > > >> 
> > > >> 
> > > >> --
> > > >> 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.
> > > >> For more options, visit https://groups.google.com/d/optout.
> > > > 
> > > > -- 
> > > > You received

Re: [racket-users] Python's append vs Racket's append and helping novices understand the implications

2019-02-16 Thread David Van Horn
There are several examples for every function provided by the ralist
library.  (And it's almost verbatim what's in the Racket reference for
pairs and lists.)

But... I can add some early examples.  No problem.

David

On Sat, Feb 16, 2019, 4:00 PM John Clements 
wrote:

> The pointer to RaLists would be much more enticing if we could convince
> David Van Horn to begin his documentation with a couple of small examples….
>
> John
>
> > On Feb 13, 2019, at 14:35, Stephen De Gabrielle 
> wrote:
> >
> > Thanks
> >
> > I should note that anyone with a GitHub account can edit
> https://github.com/racket/racket/wiki/Python-to-Racket
> >
> > S.
> >
> > On Wed, 13 Feb 2019 at 21:26, Matthias Felleisen 
> wrote:
> >
> > Not until there’s demand. I think we do see demand for Python transfers.
> >
> >
> >
> > > On Feb 13, 2019, at 3:11 PM, Stephen De Gabrielle <
> spdegabrie...@gmail.com> wrote:
> > >
> > > Should there be similar pages for Javascript, Java,C#, C/C++, Ruby,
> PHP, Visual Basic, Scratch and Haskell?
> > >
> > > S.
> > >
> > > On Wed, Feb 13, 2019 at 8:03 PM Stephen De Gabrielle <
> spdegabrie...@gmail.com> wrote:
> > > I created a DRAFT page on the Racket GitHub wiki:
> > >   https://github.com/racket/racket/wiki/Python-to-Racket
> > > It links to a 'Choosing a data structure' page
> https://github.com/racket/racket/wiki/Choosing-a-data-structure
> > > - this just as copy of the table created by Jens Axel Søgaard at:
> https://stackoverflow.com/questions/27584416/in-racket-what-is-the-advantage-of-lists-over-vectors/27589146#27589146
> )
> > >
> > > Please edit/delete as you see fit
> > >
> > > Kind regards
> > > Stephen
> > >
> > >
> > > On Tue, Feb 12, 2019 at 5:20 PM Matthias Felleisen <
> matth...@felleisen.org> wrote:
> > >
> > > This is perfect! Thanks — Matthias
> > >
> > >
> > >
> > >
> > > > On Feb 11, 2019, at 11:04 PM, Claes Wallin (韋嘉誠) 
> wrote:
> > > >
> > > > For anyone creating such a web page for Python to Racket
> specifically,
> > > > there is probably a great deal of inspiration, and reminders of
> > > > stumbling blocks, to be found in Arne Babenhauserheide's
> > > > https://www.draketo.de/py2guile book (available online for free)
> about
> > > > going from Python to Guile Scheme.
> > > >
> > > > --
> > > >   /c
> > > >
> > > > On Sun, Feb 3, 2019 at 7:00 AM Matthias Felleisen
> > > >  wrote:
> > > >> Racket needs *you*. Please.
> > > >>
> > > >> The proper approach is to have short pages for different language
> immigration groups: Python and R come to mind as obvious examples but I am
> sure there are others.
> > > >>
> > > >> What I mean is we need help and *you* can help. Let me explain it
> with the Python example:
> > > >>
> > > >> 1. Set up a page (wiki?) called “From Python to Racket”
> > > >>
> > > >> 2. Create two sections that are immediately visible from the top:
> > > >>
> > > >>— idioms
> > > >>— performance pitfalls
> > > >>
> > > >> 3. In the specific case of Python, the second subsection needs to
> start with a subsection on
> > > >>
> > > >>— Python Lists aren’t Racket Lists
> > > >>— then point to data/ralis and show how to transliterate the
> loop/append example like this
> > > >>— optionally also show the more native Racket idiom
> > > >>
> > > >> 4. When anyone observers another blog/social media/whatever post on
> Racket is slow because I come from Python,
> > > >>
> > > >>(a) point the posters to the page  or
> > > >>(b) if it is a new case, write a section for this example
> then do (a)
> > > >>
> > > >>
> > > >> If you want to help advertise Racket to others, this is an
> excellent way of helping out.
> > > >>
> > > >> Thanks — Matthias
> > > >>
> > > >> [[ p.s. For my very first Python program (a couple of days before
> meeting with GvR), I used Python’s append and was annoyed beyond belief. ]]
> > > >>
> > > >>
> > > >> --
> > > >> 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.
> > > >> For more options, visit https://groups.google.com/d/optout.
> > > >
> > > > --
> > > > 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.
> > > > For more options, visit https://groups.google.com/d/optout.
> > >
> > > --
> > > 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.
> > > For more options, visit https://groups.google.com/d/optout.
> >
> > --
> > 
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.

Re: [racket-users] Contracts question on structs

2019-02-16 Thread David Storrs
Hi Chris,

I just pushed an update to struct-plus-plus that I think does what you
want.  https://pkgd.racket-lang.org/pkgn/package/struct-plus-plus

The package server is telling me "This package needs documentation".
I'm not sure why that is, since I've got
scribblings/strut-plus-plus.scrbl and I thought that was all I needed.
Regardless, here's the link to the HTML file until I can get it
sorted:  https://www.dropbox.com/s/qj1krqau8nonhxq/struct-plus-plus.html?dl=0

Here's how to implement what you were looking for:
#lang racket

(require struct-plus-plus)

(struct Temp (val))
(struct Label (val))
(struct VarValue (val))

; The requirements you gave were:
;; "In this case, if name is Temp? then global? has to be #f."
;; "If name is Label? then global? can be #t or #f."

(struct++ Result
  ([name (or/c Temp? Label?)]
   [global? any/c (negate false?)] ; coerce to #t or #f
   [value (or/c VarValue? #f)])
  (#:rule ("check name" #:check (name global?) [(or (Label? name)
(and (Temp? name)
 (false? global?)))]))
  #:transparent
  )

; Just for fun, I've contracted global? to accept any value but coerce
; it to #t / #f.  It's effectively still a boolean field but it's more
; convenient.

(Result++ #:name (Temp 7)  #:global? #f  #:value #f)
(with-handlers ([identity identity]) (Result++ #:name (Temp 7)
#:global? #t  #:value #f))
(Result++ #:name (Label "foo") #:global? #f  #:value #f)
(Result++ #:name (Label "foo") #:global? #t  #:value #f)
(Result++ #:name (Label "foo") #:global? 'ok #:value #f) ; 'ok is coerced to #t


Output if you run the above:

(Result # #f #f)
(exn:fail:contract "check name: check failed\n  name: #\n
global?: #t" #)
(Result # #f #f)
(Result # #t #f)
(Result # #t #f)

On Fri, Feb 15, 2019 at 7:53 AM Chris GauthierDickey  wrote:
>
> Still having trouble though, can't get struct/dc to work in the way I'd like. 
> I tried to simplify my example:
>
> (define Result/c
>   (struct/dc Result
>  (a number?)
>  (b boolean?)
>  ; in other words, if a is 0, then b must be
>  ; false or the contract is broken
>  #:inv (a b) (if (= a 0)
>  (eq? b #f)
>  #t)))
> (provide (contract-out [Result Result/c]))
>
> The documentation on #:inv says it must return a non-#f value, which I assume 
> means it acts like a predicate? #f if the contract fails, something else 
> otherwise? In any case, this doesn't work because it says:
>
> Result: broke its own contract
>   promised: Result?
>   produced: #
>   in: (struct/dc
>Result
>(a number?)
>(b boolean?)
>#:inv
>(a b)
>...)
>
> I also tried specifying all of the struct functions that are created with 
> their own contracts, like Result-a, Result-b, Result? and then using Result/c 
> for Result, and this fails too.
>
> I think I understand how this is being used in the example in the 
> documentation with #:lazy, but it's not quite what I'm looking for: I'm 
> looking to use a contract on the struct constructor (in particular, which is 
> why I thought #:inv would be the way to go) where one field initialization 
> depends on another.
>
> As an aside, I also tried the following:
>
> (provide (contract-out [Result (or/c (number? boolean? . -> . Result?)
>  (0 #f . -> . Result?))]))
>
> But the contract system complained that both might match (I mean I can see 
> that one is more specific, but I understand it's not a theorem prover, haha).
>
> Thoughts?
> Chris
>
> On Fri, Feb 15, 2019 at 7:56 AM Chris GauthierDickey  
> wrote:
>>
>> I believe it should be since bst/c is supposed to be a contract. Also I 
>> noticed the docs at 
>> https://docs.racket-lang.org/reference/data-structure-contracts.html show a 
>> similar example:
>>
>> ; bst-between : number number -> contract
>> ; builds a contract for binary search trees
>> ; whose values are between low and high
>> (define (bst-between/c low high)
>>   (or/c null?
>> (struct/dc node [val (between/c low high)]
>> [left (val) #:lazy (bst-between/c low val)]
>> [right (val) #:lazy (bst-between/c val high)])))
>>
>>
>> On Fri, Feb 15, 2019 at 1:31 AM David Storrs  wrote:
>>>
>>> On Fri, Feb 15, 2019 at 12:18 AM David Storrs  
>>> wrote:
>>> >
>>> > On Thu, Feb 14, 2019 at 9:08 PM Robby Findler
>>> >  wrote:
>>> > >
>>> > > This is what struct/dc is for. Let me know if the docs let you down!
>>> > >
>>> > > Robby
>>> >
>>> > This is good to hear about, because I'm actually in the middle of
>>> > writing something that it will help with.  Thanks, Robby.
>>> >
>>> > One question:  Is there a typo in the example code or am I missing 
>>> > something?
>>> >
>>> > (struct bt (val left right))
>>> > (define (bst/c lo hi)
>>> > (or/c #f
>>> > (struct/dc bt
>>> > [va

Re: [racket-users] raco distribute creating too many subdirectories

2019-02-16 Thread 'John Clements' via Racket Users
Good to know; I also use define-runtime-path with abandon, and was not aware of 
possible consequences of casting too wide a net.

Thanks!

John

> On Feb 10, 2019, at 09:49, Philip McGrath  wrote:
> 
> I think this is probably a consequence of the quirk of `define-runtime-path` 
> with directories that I reported at: 
> https://github.com/racket/racket/issues/2336
> 
> I'm still not clear on whether the current behavior is intended and, if so, 
> how one ought to do this sort of thing to work robustly with the executable 
> creator.
> 
> -Philip
> 
> 
> On Sun, Feb 10, 2019 at 6:14 AM P. Baillet  wrote:
> Hello,
> 
> After some analysis, I found out this is because I was using 
> (define-runtime-path the wrong way. My code uses FFI and at some point, I 
> thought it would be wise to use code I didn’t understand.
> 
> The following snippet reproduces the issue:
> 
> #lang racket
> (require racket/runtime-path)
> 
> (define-runtime-path here ".")
> (displayln "Hi!")
> 
> I have reworked my code to no longer use this and it can now distribute my 
> application without problems.
> 
> On 9 Feb 2019, at 2:28, George Neuner wrote:
> 
> Why not build the executable separately and just copy it into the image?
> 
> Because I’m targeting another architecture.
> 
> Have a nice Sunday!
> -- 
> P.
> 
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/d/optout.



-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Python's append vs Racket's append and helping novices understand the implications

2019-02-16 Thread 'John Clements' via Racket Users
The pointer to RaLists would be much more enticing if we could convince David 
Van Horn to begin his documentation with a couple of small examples…. 

John

> On Feb 13, 2019, at 14:35, Stephen De Gabrielle  
> wrote:
> 
> Thanks 
> 
> I should note that anyone with a GitHub account can edit 
> https://github.com/racket/racket/wiki/Python-to-Racket
> 
> S.
> 
> On Wed, 13 Feb 2019 at 21:26, Matthias Felleisen  
> wrote:
> 
> Not until there’s demand. I think we do see demand for Python transfers. 
> 
> 
> 
> > On Feb 13, 2019, at 3:11 PM, Stephen De Gabrielle  
> > wrote:
> > 
> > Should there be similar pages for Javascript, Java,C#, C/C++, Ruby, PHP, 
> > Visual Basic, Scratch and Haskell?
> > 
> > S.
> > 
> > On Wed, Feb 13, 2019 at 8:03 PM Stephen De Gabrielle 
> >  wrote:
> > I created a DRAFT page on the Racket GitHub wiki:
> >   https://github.com/racket/racket/wiki/Python-to-Racket
> > It links to a 'Choosing a data structure' page 
> > https://github.com/racket/racket/wiki/Choosing-a-data-structure
> > - this just as copy of the table created by Jens Axel Søgaard at: 
> > https://stackoverflow.com/questions/27584416/in-racket-what-is-the-advantage-of-lists-over-vectors/27589146#27589146)
> > 
> > Please edit/delete as you see fit
> > 
> > Kind regards
> > Stephen
> > 
> > 
> > On Tue, Feb 12, 2019 at 5:20 PM Matthias Felleisen  
> > wrote:
> > 
> > This is perfect! Thanks — Matthias
> > 
> > 
> > 
> > 
> > > On Feb 11, 2019, at 11:04 PM, Claes Wallin (韋嘉誠)  wrote:
> > > 
> > > For anyone creating such a web page for Python to Racket specifically,
> > > there is probably a great deal of inspiration, and reminders of
> > > stumbling blocks, to be found in Arne Babenhauserheide's
> > > https://www.draketo.de/py2guile book (available online for free) about
> > > going from Python to Guile Scheme.
> > > 
> > > -- 
> > >   /c
> > > 
> > > On Sun, Feb 3, 2019 at 7:00 AM Matthias Felleisen
> > >  wrote:
> > >> Racket needs *you*. Please.
> > >> 
> > >> The proper approach is to have short pages for different language 
> > >> immigration groups: Python and R come to mind as obvious examples but I 
> > >> am sure there are others.
> > >> 
> > >> What I mean is we need help and *you* can help. Let me explain it with 
> > >> the Python example:
> > >> 
> > >> 1. Set up a page (wiki?) called “From Python to Racket”
> > >> 
> > >> 2. Create two sections that are immediately visible from the top:
> > >> 
> > >>— idioms
> > >>— performance pitfalls
> > >> 
> > >> 3. In the specific case of Python, the second subsection needs to start 
> > >> with a subsection on
> > >> 
> > >>— Python Lists aren’t Racket Lists
> > >>— then point to data/ralis and show how to transliterate the 
> > >> loop/append example like this
> > >>— optionally also show the more native Racket idiom
> > >> 
> > >> 4. When anyone observers another blog/social media/whatever post on 
> > >> Racket is slow because I come from Python,
> > >> 
> > >>(a) point the posters to the page  or
> > >>(b) if it is a new case, write a section for this example then do 
> > >> (a)
> > >> 
> > >> 
> > >> If you want to help advertise Racket to others, this is an excellent way 
> > >> of helping out.
> > >> 
> > >> Thanks — Matthias
> > >> 
> > >> [[ p.s. For my very first Python program (a couple of days before 
> > >> meeting with GvR), I used Python’s append and was annoyed beyond belief. 
> > >> ]]
> > >> 
> > >> 
> > >> --
> > >> 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.
> > >> For more options, visit https://groups.google.com/d/optout.
> > > 
> > > -- 
> > > 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.
> > > For more options, visit https://groups.google.com/d/optout.
> > 
> > -- 
> > 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.
> > For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> 
> 
> -- 
> 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.
> For more options, visit https://groups.google.com/d/optout.



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

[racket-users] Re: Little language design/implementation guidance

2019-02-16 Thread George Neuner
On Wed, 13 Feb 2019 15:24:41 +, Stephen De Gabrielle
 wrote:

>As far as when to consult a specialist/expert I didn't mean a programming
>languages researcher, I was more referring to when you were designing a
>little language like a templating system or config file.  Would that be
>covered by the compilers course? My alma-mater doesn't offer a compilers
>course in their compsci degree
>


Disclaimer: I'm not an academic, and my own CS education was ~30 years
ago ... but I do look up occasionally to see what is being taught to
modern CS students.

Compiler courses usually are much more about the compiler than the
language being compiled.  Most often the students work to implement
some subset of an existing language, rather than designing a new one.

IMO, a compiler course or three is not going to make a good language
designer.  What makes a good designer is a lot of personal experience
with many different languages - and with different KINDS of languages
- seeing what works, what doesn't work, and what is confusing to
themselves and others.


>I suppose there is a scale:
>
>   1. programmer (without compilers course)

I began as a self taught programmer:  I knew several languages already
and had read texts on compilers and operating systems before I took my
first CS course.

At one time or another I have learned and used:

   BASIC   BASIC-11 [PDP],Commodore,Apple,Microsoft
   assembler   6502,8086,68K,ADSP21K
   Pascal  UCSD, Borland
   C   K&R .. current, 
   Modula-2 
   Scheme  R3RS .. R5RS, PLT, Racket
   Smalltalk   PARC Place
   C++ 2.0 (pre ANSI) .. current
   C*  Connection Machine C
   SQL SQL-86 .. current
   Common Lisp 
   ML  Edinburgh
   Prolog  Edinburgh
   Modula-3
   Java1.4 .. current
   Python  2.6 / 3.0 .. current

This list includes only languages I've actually learned enough to use:
for school, for work, or for my own hacking.  I've investigated more
languages than I've bothered to really learn.

The order I learned them in sort of is reflected in the list above.
Obviously variants were picked up along the way as languages evolved
and as I encountered new implementations.  But I knew 3 varieties of
BASIC, 6502 assembler, UCSD and Borland Pascal, and ANSI C(89) before
I took any CS courses.


Even with this experience, I would hesitate before taking on design of
a new language.  Certainly I would draw from existing languages I
thought were relevant, and unless I strongly disagreed with some
choice they made, I would try to stick to their existing syntax and
semantics as much as possible.



>   2. did compilers at degree level (can still remember it and it covered
>   design decisions, as opposed to algorithms and data structures)

My course covered compiler implementation, not language design.
Obviously, by implementing a compiler for a language you can get a
feel for what is right and wrong with it.


>   3. Beautiful Racket and/or/ https://school.racket-lang.org/#brw
>   4. Racket School 'How to design Languages'
>   https://school.racket-lang.org/#htdl
>   5. http://cs.brown.edu/courses/cs173/ , PLAI, PAPL or a postgraduate
>   level (masters?)
>   6. PhD and beyond
>
>( I have no idea if the order I made up is right - and I don't remember the
>dragon book covering the HCI aspects of language design)

I have the 2nd edition and I've seen the 1st.  There was little or
nothing said in either about user issues.  I haven't seen the 3rd
edition. [Are there more now?]


On my shelf, I have 7 texts on compilers ranging from beginner to
advanced;  3 texts covering computation theory, type theory, and
semantics;  2 texts on garbage collection;  and the classics: SICP and
EoPL.

For the most part, the compiler books cover only how various language
design decisions affect the compiler and/or runtime support for the
language.  The only mention of how language features affect the user
is to note that if a feature presents ambiguity problems for the
compiler [in parsing or understanding], then that feature probably
also will be confusing to the user.


>I suppose if you are If you are at (1) and you need help you ask someone at
>(2) or above.
>
>I'd pay if PLT/Racket offered different levels of certification in
>DSL/Language design at different levels, or licensed someone do do it on
>their behalf for a percentage of the income.  (I regret not doing the mooc
>version of cs173/ PLAI when it was
>offered)
>
>S.


I would have little problem coding a standalone compiler in Racket, or
translating some other language into Racket as the target.

But so far as #lang or other advanced macrology intended to integrate
with other Racket code ... there I still would have to call myself an
amateur: for whatever reason I have yet to fully grasp Racket's syntax
objects and (meta)programming with them.


YMMV,
George

-- 
You

[racket-users] Compiler Fundamentals: Closure Conversion

2019-02-16 Thread rain1

Hello everybody,

I wanted to share this short literate program/article I wrote that 
teaches the closure conversion compiler pass. I hope it's useful or 
interesting to some of you. It is done using the nanopass style. If 
you've got any questions I will try to answer!




#lang racket

;; this is a stand alone simple version of the closure conversion part 
of the hoist pass from the tarot compiler

;; see https://rain-1.github.io/scheme for more.

(require data/queue)

;; closure conversion for lambda calculus
;;
;; the input language is:
;;
;;  ::= 
;;   | 
;;   | (lambda ( ...)  ...)
;;   | (begin  ...)
;;   | (  ...)
;;
;; the output language is
;;
;;  ::= (var loc )
;;| (var env )
;;| (var glo )
;;| 
;;| (closure ( ...) )
;;| (begin  ...)
;;| (  ...)
;;
;;  ::= (var loc )
;; | (var env )
;;
;; Variables have been annotated with their storage type and
;; lambda functions have been replaced with closure objects
;; all of the variables captured by a lambda have been packaged
;; up with the closure object


 HELPERS

(define (every p l)
  (if (null? l)
  #t
  (and (p (car l)) (every p (cdr l)

(define (index v l)
  (for/first ([i (in-naturals)]
  [elt (in-list l)]
  #:when (equal? elt v))
i))

(define (queue-index v q)
  (for/first ([i (in-naturals)]
  [elt (in-queue q)]
  #:when (equal? elt v))
i))

(define-syntax mapply
  (syntax-rules ()
((mapply f xs arg ...)
 (map (lambda (x) (f x arg ...)) xs


 SHAPES

(define (var? x) (symbol? x))
(define (datum? x) (or (boolean? x) (number? x)))
(define (lambda? x)
  (if (and (pair? x) (eq? 'lambda (car x)))
  (if (and (every symbol? (cadr x))
   (not (null? (cddr x
  #t
  (error "malformed lambda expression" x))
  #f))
(define (lambda-bindings x) (cadr x))
(define (lambda-body x) (implicit-begin (cddr x)))
(define (begin? x) (and (pair? x) (eq? 'begin (car x
(define (application? x) (pair? x))

(define (implicit-begin xs)
  (if (null? xs)
  (error "empty expression list")
  (if (null? (cdr xs))
  (car xs)
  `(begin . ,xs


;; CLOSURE CONVERSION

(struct scope (locals env captures globals))
;;
;; locals is a list of symbols
;; - it's the variables bound by the current lambda alternatively the 
top stack frame

;;
;; env is a list of symbols
;; - is a list of every non-global variable that has been brought into 
scope by lambda binders
;;   for example in (lambda (a b) (lambda (x y) )) at the point 
 the env is (x y a b)

;;
;; captures is a queue of symbols
;; - If you reference a variable that isn't global or local it'll be 
captured and put into this queue
;;   at the end of processing a subexpression, this queue becomes the 
closure environment

;;
;; globals is a list of symbols
;; - car, cdr, cons etc.

(define (classify var scope)
  ;; classify a variable with its storage type based on a scope
  (cond ((index var (scope-locals scope))
 => (lambda (i) `(var loc ,i)))
((member var (scope-env scope))
 (cond ((queue-index var (scope-captures scope))
=> (lambda (i) `(var env ,i)))
   (else
(enqueue! (scope-captures scope) var)
(let ((i (- (queue-length (scope-captures scope)) 1)))
  `(var env ,i)
((member var (scope-globals scope))
 `(var glo ,var))
(else (error "unbound variable error" var

(define (cc exp sc)
  (cond ((var? exp) (classify exp sc))

((datum? exp) exp)

((lambda? exp)
 (let* ((vars (lambda-bindings exp))
(body (lambda-body exp))
(captures^ (make-queue))
(sc^ (scope vars
(append (scope-locals sc) (scope-env sc))
captures^
(scope-globals sc)))
(body^ (cc body sc^)))
   `(closure ,(mapply cc (queue->list captures^) sc) ,body^)))

((begin? exp)
 `(begin . ,(mapply cc (cdr exp) sc)))

((application? exp)
 (mapply cc exp sc))

(else (error "malformed expression in cc" exp


 TESTING, EXAMPLES

(define (print x) (display x) (newline))

(define (go exp)
  (let ((res
 (cc exp (scope '()
'()
(make-queue)
'(car cdr cons)
(print exp)
(display "==> ")
(print res)
(newline)))

(define (test)
  (go '3)
  (go '(lambda (x) x))
  (go '(lambda (x) (car x)))
  (go '(lambda (x) (x 5 x 7)))
  (go '(lambda (x y) (x y)))
  (go '(lambda (x y) (y x)))
  (go '(lambda (z) (lambda (x y) (y x
  (go '(lambda (x y) (lambda (z) (y x
  (go '(lambda (x) (lambda (y) (lambda (z) (x y z))

(test)

;; 3
;; ==> 3
;;
;; (lambda (x) x)
;; ==> (closure () (var loc 0))
;;
;; (lambda (x) (car 

Re: [racket-users] [macro help] How can I render a parenthesized set of elements optional?

2019-02-16 Thread David Storrs
Thank you both -- Jon for the code and Alexis for the thorough description.

Alexis, this was exactly what I was looking for.  I've been frustrated
with macros because I kept trying and failing to figure out a mental
model of what the heck was going on under the hood.  I had some of the
basics, but anything more sophisticated I was basically guessing and
cargo-culting.

I think it would help a lot of future people if your explanation got
pasted verbatim into the docs.

On Sat, Feb 16, 2019 at 1:53 AM Alexis King  wrote:
>
> Jon is right. Here’s an explanation why.
>
> Think of `...` as a postfix operator. It repeats what comes before it a 
> certain number of times. In order for `...` to know how many times to repeat 
> the previous head template, it looks inside the head template for any 
> attributes bound at the appropriate ellipsis depth, and it repeats the head 
> template once for each value of the attributes. The `...` operator 
> essentially creates a loop, iterating through each value of the attribute.
>
> The value of attributes bound under ellipses are therefore lists. You can see 
> this for yourself if you use the `attribute` accessor to explicitly get at 
> the value of an attribute matched under an ellipsis:
>
>   > (syntax-parse #'(a b c)
>   [(x:id ...)
>(attribute x)])
>   '(#
> #
> #)
>
> But what happens to the value of an attribute when it is completely 
> unspecified, since it has been marked `~optional`? If the `~optional` wraps 
> the whole sequence, such that the ellipsis is inside the `~optional` pattern, 
> then the attribute is not a list at all, but `#f`:
>
>   > (syntax-parse #'()
>   [({~optional (x:id ...)})
>(attribute x)])
>   #f
>
> This causes problems. If we were to write #'(x ...) when `x` is bound to 
> `#f`, then the template will raise an error, since `x` isn’t a list, and 
> therefore the ellipses don’t know how many times to repeat the preceding 
> template.
>
> What you tried to do is silence that error by wrapping the offending template 
> with `~?`. This is a natural thing to try, but it doesn’t work. Why? Well, 
> it’s true that {~? x} turns into {~@} when `x` is `#f`, but this does not 
> matter, since you essentially wrote ({~? x} ...). This means that the `x` 
> under the ellipsis doesn’t refer to the attribute `x` as a whole, but instead 
> refers to each *element* of `x`, since `...` creates a loop. So the template 
> attempts to iterate through the values of (attribute x), but it finds that 
> value isn’t a list at all, gets confused, and explodes.
>
> Jon’s fix changes this. It moves the looping *inside* the `~?`, which means 
> that `~?` is now looking at `x` as a whole (not each element of `x`), and 
> just skips the loop altogether, avoiding the error. It’s morally the 
> difference between this code:
>
>   (for/list ([x (in-list (attribute x))])
> (if x x #'{~@}))
>
> and this code:
>
>   (if (attribute x)
>   (for/list ([x (in-list (attribute x))])
> x)
>   #'{~@})
>
> ---
>
> A secondary question: is the template #'({~? x} ...) ever useful? And the 
> answer is: YES! It just does something different.
>
> Since #'({~? x} ...) iterates through the values of `x` before checking for 
> `#f`-ness, then it is useful when `x` itself is never `#f`, but elements of 
> it may be. This can appear when parsing, say, a list of pairs, where the 
> second element of each pair is optional:
>
>   > (define parse-pairs
>   (syntax-parser
> [([x:id {~optional n:nat}] ...)
>  #'([x ...]
> [{~? n} ...])]))
>   > (parse-pairs #'([a 1] [b] [c 3]))
>   #
>   > (parse-pairs #'([a] [b] [c]))
>   #
>
> Note that when there are no numbers in the input, the output list is still 
> present but is simply empty, while when some but not all numbers are 
> provided, the missing numbers are simply skipped in the output.
>
> ---
>
> One final point: you may think to yourself “all of this is confusing and 
> procedural, why should I have to think about attributes?” While I think 
> understanding what’s going on internally can be helpful, it isn’t strictly 
> necessary. There’s actually a declarative intuition to guide whether you 
> should write #'({~? {~@ x ...}}) or #'({~? x} ...). This intuition is as 
> follows.
>
> There is a dualism in `syntax-parse`’s pattern language and in the `syntax` 
> form’s template language. For example:
>
>   - Writing `x` in a pattern, where `x` is an identifier, matches a term, and 
> writing `x` in a template constructs the same term.
>
>   - Writing (a . b) in a pattern matches a pair, and writing (a . b) in a 
> template constructs a pair.
>
>   - Writing `p ...` in a pattern matches zero or more occurrences of the 
> pattern `p`, and writing `t ...` in a template that contains variables bound 
> in `p` constructs the same number of occurrences in the template.
>
> To put things another way:
>
>   - Variables in patterns correspond to variables in templates.
>   -

[racket-users] Alpine-based docker racket images

2019-02-16 Thread Tony Garnock-Jones
Hi all,

Just a quick note to let anyone interested know I've built some Racket 7.2 
docker images: one "full" and one "minimal", from the respective source 
tarballs, and for both "x86_64" and "aarch64". I'm still working on armhf.

There's also a manifest set up against tags "latest" (for full) and 
"minimal" that will automatically pick the right architecture.

To try them:

docker run -it --rm leastfixedpoint/racket

or

docker run -it --rm leastfixedpoint/racket:minimal

The docker hub page is here:

https://hub.docker.com/r/leastfixedpoint/racket

Cheers,
  Tony

-- 
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.
For more options, visit https://groups.google.com/d/optout.