[racket-users] Changing the charset/encoding when using the db library

2020-07-11 Thread Bonface Munyoki
Hi all.

I'm using racket to connect to mysql using the db library. I'd like to
do something like:

--8<---cut here---start->8---
`sqlalchemy.create_engine(SQL_URI+'?charset=latin1_unicode=0')`
--8<---cut here---end--->8---

basically adding the equivalent of "charset=latin1_unicode=0" in the
SQL_URI. I can't seem to find a way to do that in racket. Would anyone
have an idea of how I would do that?
---
Bonface M. K.(https://www.bonfacemunyoki.com/)
One Emacs to rule them all
GPG key = D4F09EB110177E03C28E2FE1F5BBAE1E0392253F

-- 
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/CABAzU5te7aqX%2B6oxUTK8qKr1XA%3DTL1TEL-Eco1s0_vBEC2F09Q%40mail.gmail.com.


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

2020-07-11 Thread Ryan Culpepper
Great, I'm glad it was useful!

Ryan


On Sat, Jul 11, 2020 at 12:27 PM Peter W A Wood 
wrote:

> Dear Ryan
>
> Thank you for both your full, complete and understandable explanation and
> a working solution which is more than sufficient for my needs.
>
> I created a very simple function based on the reg=exp that you suggested
> and tested it against a number of cases:
>
>
> #lang racket
> (require test-engine/racket-tests)
>
> (check-expect (alpha? "") #f)   ;
> empty string
> (check-expect (alpha? "1") #f)
> (check-expect (alpha? "a") #t)
> (check-expect (alpha? "hello") #t)
> (check-expect (alpha? "h1llo") #f)
> (check-expect (alpha? "\u00E7c\u0327") #t)   ; çç
> (check-expect (alpha? "noe\u0308l") #t) ; noél
> (check-expect (alpha? "\U01D122") #f)   ; 턢 (bass
> clef)
> (check-expect (alpha? "\u216B") #f)   ; Ⅻ (roman
> numeral)
> (check-expect (alpha? "\u0BEB") #f)   ; ௫ (5 in
> Tamil)
> (check-expect (alpha? "二の句") #t); Japanese
> word "ninoku"
> (check-expect (alpha? "مدينة") #t); Arabic
> word "madina"
> (check-expect (alpha? "٥") #f) ;
> Arabic number 5
> (check-expect (alpha? "\u0628\uFCF2") #t); Arabic letter
> beh with shaddah
> (define (alpha? s)
>  (regexp-match? #px"^\\p{L}+$" (string-normalize-nfc s)))
> (test)
>
> I suspect that there are some cases with scripts requiring multiple code
> points to render a single character such as Arabic with pronunciation marks
> e.g. دُ نْيَا. At the moment, I don’t have the time (or need) to
> investigate further.
>
> The depth of Racket’s Unicode support is impressive.
>
> Once again, thanks.
>
> Peter
>
>
> > On 10 Jul 2020, at 15:47, Ryan Culpepper  wrote:
> >
> > (I see this went off the mailing list. If you reply, please consider
> CCing the list.)
> >
> > Yes, I understood your goal of trying to capture the notion of Unicode
> "alphabetic" characters with a regular expression.
> >
> > As far as I know, Unicode doesn't have a notion of "alphabetic", but it
> does assign every code point to a "General category", consisting of a main
> category and a subcategory. There is a category called "Letter", which
> seems like one reasonable generalization of "alphabetic".
> >
> > In Racket, you can get the code for a character's category using
> `char-general-category`. For example:
> >
> >   > (char-general-category #\A)
> >   'lu
> >   > (char-general-category #\é)
> >   'll
> >   > (char-general-category #\ß)
> >   'll
> >   > (char-general-category #\7)
> >   'nd
> >
> > The general category for "A" is "Letter, uppercase", which has the code
> "Lu", which Racket turns into the symbol 'lu. The general category of "é"
> is "Letter, lowercase", code "Ll", which becomes 'll. The general category
> of "7" is "Number, decimal digit", code "Nd".
> >
> > In Racket regular expressions, the \p{category} syntax lets you
> recognize characters from a specific category. For example, \p{Lu}
> recognizes characters with the category "Letter, uppercase", and \p{L}
> recognizes characters with the category "Letter", which is the union of
> "Letter, uppercase", "Letter, lowercase", and so on.
> >
> > So the regular expression #px"^\\p{L}+$" recognizes sequences of one or
> more Unicode letters. For example:
> >
> >   > (regexp-match? #px"^\\p{L}+$" "héllo")
> >   #t
> >   > (regexp-match? #px"^\\p{L}+$" "straße")
> >   #t
> >   > (regexp-match? #px"^\\p{L}+$" "二の句")
> >   #t
> >   > (regexp-match? #px"^\\p{L}+$" "abc123")
> >   #f ;; No, contains numbers
> >
> > There are still some problems to watch out for, though. For example,
> accented characters like "é" can be expressed as a single pre-composed code
> point or "decomposed" into a base letter and a combining mark. You can get
> the decomposed form by converting the string to "decomposed normal form"
> (NFD), and the regexp above won't match that string.
> >
> >   > (map char-general-category (string->list (string-normalize-nfd "é")))
> >   '(ll mn)
> >   > (regexp-match? #px"^\\p{L}+$" (string-normalize-nfd "héllo"))
> >   #f
> > 
> > One fix would be to call `string-normalize-nfc` first, but some
> letter-modifier pairs don't have pre-composed versions. Another fix would
> be to expand the regexp to include modifiers. You'd have to decide which is
> better based on your application.
> >
> > Ryan
> >
>
> --
> 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/09B244A4-89C5-4B5C-97E7-5487059125F6%40gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket 

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

2020-07-11 Thread Peter W A Wood
Dear Ryan

Thank you for both your full, complete and understandable explanation and a 
working solution which is more than sufficient for my needs.

I created a very simple function based on the reg=exp that you suggested and 
tested it against a number of cases:


#lang racket
(require test-engine/racket-tests)

(check-expect (alpha? "") #f)   ; empty 
string
(check-expect (alpha? "1") #f)   
(check-expect (alpha? "a") #t)
(check-expect (alpha? "hello") #t)
(check-expect (alpha? "h1llo") #f)
(check-expect (alpha? "\u00E7c\u0327") #t)   ; çç
(check-expect (alpha? "noe\u0308l") #t) ; noél
(check-expect (alpha? "\U01D122") #f)   ; 턢 (bass clef)
(check-expect (alpha? "\u216B") #f)   ; Ⅻ (roman 
numeral)
(check-expect (alpha? "\u0BEB") #f)   ; ௫ (5 in Tamil)
(check-expect (alpha? "二の句") #t); Japanese word 
"ninoku"
(check-expect (alpha? "مدينة") #t); Arabic word 
"madina"
(check-expect (alpha? "٥") #f) ; Arabic 
number 5
(check-expect (alpha? "\u0628\uFCF2") #t); Arabic letter beh 
with shaddah
(define (alpha? s)
 (regexp-match? #px"^\\p{L}+$" (string-normalize-nfc s)))
(test)

I suspect that there are some cases with scripts requiring multiple code points 
to render a single character such as Arabic with pronunciation marks e.g. دُ 
نْيَا. At the moment, I don’t have the time (or need) to investigate further.  

The depth of Racket’s Unicode support is impressive.

Once again, thanks.

Peter


> On 10 Jul 2020, at 15:47, Ryan Culpepper  wrote:
> 
> (I see this went off the mailing list. If you reply, please consider CCing 
> the list.)
> 
> Yes, I understood your goal of trying to capture the notion of Unicode 
> "alphabetic" characters with a regular expression.
> 
> As far as I know, Unicode doesn't have a notion of "alphabetic", but it does 
> assign every code point to a "General category", consisting of a main 
> category and a subcategory. There is a category called "Letter", which seems 
> like one reasonable generalization of "alphabetic".
> 
> In Racket, you can get the code for a character's category using 
> `char-general-category`. For example:
> 
>   > (char-general-category #\A)
>   'lu
>   > (char-general-category #\é)
>   'll
>   > (char-general-category #\ß)
>   'll
>   > (char-general-category #\7)
>   'nd
> 
> The general category for "A" is "Letter, uppercase", which has the code "Lu", 
> which Racket turns into the symbol 'lu. The general category of "é" is 
> "Letter, lowercase", code "Ll", which becomes 'll. The general category of 
> "7" is "Number, decimal digit", code "Nd".
> 
> In Racket regular expressions, the \p{category} syntax lets you recognize 
> characters from a specific category. For example, \p{Lu} recognizes 
> characters with the category "Letter, uppercase", and \p{L} recognizes 
> characters with the category "Letter", which is the union of "Letter, 
> uppercase", "Letter, lowercase", and so on.
> 
> So the regular expression #px"^\\p{L}+$" recognizes sequences of one or more 
> Unicode letters. For example:
> 
>   > (regexp-match? #px"^\\p{L}+$" "héllo")
>   #t
>   > (regexp-match? #px"^\\p{L}+$" "straße")
>   #t
>   > (regexp-match? #px"^\\p{L}+$" "二の句")
>   #t
>   > (regexp-match? #px"^\\p{L}+$" "abc123")
>   #f ;; No, contains numbers
> 
> There are still some problems to watch out for, though. For example, accented 
> characters like "é" can be expressed as a single pre-composed code point or 
> "decomposed" into a base letter and a combining mark. You can get the 
> decomposed form by converting the string to "decomposed normal form" (NFD), 
> and the regexp above won't match that string.
> 
>   > (map char-general-category (string->list (string-normalize-nfd "é")))
>   '(ll mn)
>   > (regexp-match? #px"^\\p{L}+$" (string-normalize-nfd "héllo"))
>   #f
> 
> One fix would be to call `string-normalize-nfc` first, but some 
> letter-modifier pairs don't have pre-composed versions. Another fix would be 
> to expand the regexp to include modifiers. You'd have to decide which is 
> better based on your application.
> 
> Ryan
> 

-- 
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/09B244A4-89C5-4B5C-97E7-5487059125F6%40gmail.com.


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

2020-07-11 Thread Shriram Krishnamurthi
I'm running headless Racket from a Docker container for auto-grading 
assignments in Gradescope.

The students are writing BSL programs with 2htdp/image. This does not cause 
any problems for most of them.

Two students, however, get an error in file loading with the error message 
in the subject line («Gtk initialization failed for display ":0"»).

I finally localized the problem: it's because they are using the universe 
Teachpack.

I don't know what in universe is causing this, but it seems rather weird 
that *image*, which is fundamentally graphical, does not cause this problem 
but *universe*, which is it fundamentally not, does.

Furthermore, this dependency means that any program that depends on 
universe would likely not be able to be auto-graded (at least in a 
Gradescope-like headless context), which seems a rather severe restriction. 
(And ironic, given that the design of universe is to enable testing, and 
hence also auto-grading.) I don't know how Northeastern does auto-grading 
of universe that gets around this, but it's clearly in a different setting.

I don't have a "question" because I seem to have identified the base issue 
here. This is mostly here for future reference, since I saw some posts from 
looking for that string that didn't answer my need (but were still useful 
in indicating it might be a dependency), so I'm leaving this here for a 
future person who might be searching.

However, it would also be nice if the universe Teachpack could avoid this 
dependency entirely or refactor it into parts that do and don't need it.

Shriram

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/7e2da814-25e5-4547-b5d9-2c66c087f37eo%40googlegroups.com.


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

2020-07-11 Thread Sam Tobin-Hochstadt
The usual solution to this problem is to use xvfb to create a virtual
display, which works great in this situation when the display is not really
needed anyway. This is how we run the handin server headless and how all
the racket CI works.

Sam

On Sat, Jul 11, 2020, 12:26 PM Shriram Krishnamurthi 
wrote:

> I'm running headless Racket from a Docker container for auto-grading
> assignments in Gradescope.
>
> The students are writing BSL programs with 2htdp/image. This does not
> cause any problems for most of them.
>
> Two students, however, get an error in file loading with the error message
> in the subject line («Gtk initialization failed for display ":0"»).
>
> I finally localized the problem: it's because they are using the universe
> Teachpack.
>
> I don't know what in universe is causing this, but it seems rather weird
> that *image*, which is fundamentally graphical, does not cause this
> problem but *universe*, which is it fundamentally not, does.
>
> Furthermore, this dependency means that any program that depends on
> universe would likely not be able to be auto-graded (at least in a
> Gradescope-like headless context), which seems a rather severe restriction.
> (And ironic, given that the design of universe is to enable testing, and
> hence also auto-grading.) I don't know how Northeastern does auto-grading
> of universe that gets around this, but it's clearly in a different setting.
>
> I don't have a "question" because I seem to have identified the base issue
> here. This is mostly here for future reference, since I saw some posts from
> looking for that string that didn't answer my need (but were still useful
> in indicating it might be a dependency), so I'm leaving this here for a
> future person who might be searching.
>
> However, it would also be nice if the universe Teachpack could avoid this
> dependency entirely or refactor it into parts that do and don't need it.
>
> Shriram
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/7e2da814-25e5-4547-b5d9-2c66c087f37eo%40googlegroups.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/CAK%3DHD%2Bbac1M7NcL3RtGFdrC8G%2BsadT-J3mjXiWPe%3Do8t6pXDOQ%40mail.gmail.com.


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

2020-07-11 Thread Matthew Flatt
At Sat, 11 Jul 2020 09:26:47 -0700 (PDT), Shriram Krishnamurthi wrote:
> I'm running headless Racket from a Docker container for auto-grading 
> assignments in Gradescope.
> 
> The students are writing BSL programs with 2htdp/image. This does not cause 
> any problems for most of them.
> 
> Two students, however, get an error in file loading with the error message 
> in the subject line («Gtk initialization failed for display ":0"»).
> 
> I finally localized the problem: it's because they are using the universe 
> Teachpack.
> 
> I don't know what in universe is causing this, but it seems rather weird 
> that *image*, which is fundamentally graphical, does not cause this problem 
> but *universe*, which is it fundamentally not, does.

It's helpful help to distinguish between "images" and "GUIs". The
`2htdp/image` library is only about drawing images, so it doesn't need
a GUI context. The `2htdp/universe` library deals with windows and
mouse clicks, so it needs a GUI context.

> Furthermore, this dependency means that any program that depends on 
> universe would likely not be able to be auto-graded (at least in a 
> Gradescope-like headless context), which seems a rather severe restriction. 
> (And ironic, given that the design of universe is to enable testing, and 
> hence also auto-grading.) I don't know how Northeastern does auto-grading 
> of universe that gets around this, but it's clearly in a different setting.

Following up on Sam's suggestion, I recommend `xfvb-run` as something
like

 xfvb-run racket -l handin-server


Matthew

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


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

2020-07-11 Thread Matthew Flatt
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.

-- 
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/20200711104107.126%40sirmail.smtp.cs.utah.edu.


[racket-users] nested-flow and inset

2020-07-11 Thread Shriram Krishnamurthi
My reading of the documentation for `nested-flow`

https://docs.racket-lang.org/scribble/core.html#%28def._%28%28lib._scribble%2Fcore..rkt%29._make-nested-flow%29%29

is that I can use 'inset as the first argument. However, when I try to do 
so, I get a contract error:

make-nested-flow: contract violation

  expected: style?

  given: 'inset

  in: the 1st argument of

  (-> style? (listof block?) nested-flow?)

  contract from: 

  /scribble-lib/scribble/core.rkt

This *looks* like it contradicts the documentation, which says that the 
first argument is any/c:



Even if the documentation is wrong, I'm not sure why 'inset is being 
rejected…

Thanks,
Shriram

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/6b1fd9c4-b3ef-4a3f-a95a-05f913a0afcbo%40googlegroups.com.


Re: [racket-users] nested-flow and inset

2020-07-11 Thread Matthew Flatt
At Sat, 11 Jul 2020 10:41:27 -0700 (PDT), Shriram Krishnamurthi wrote:
> My reading of the documentation for `nested-flow`
> 
> https://docs.racket-lang.org/scribble/core.html#%28def._%28%28lib._scribble%2Fc
> ore..rkt%29._make-nested-flow%29%29
> 
> is that I can use 'inset as the first argument. However, when I try to do 
> so, I get a contract error:
> 
> make-nested-flow: contract violation
> 
>   expected: style?
> 
>   given: 'inset
> 
>   in: the 1st argument of
> 
>   (-> style? (listof block?) nested-flow?)
> 
>   contract from: 
> 
>   /scribble-lib/scribble/core.rkt
> 
> This *looks* like it contradicts the documentation, which says that the 
> first argument is any/c:

You're right that the documentation is incorrect: It should say
`style?`. I'll fix that.

To construct a style that has 'nested as a property, use `(style #f
'(nested))` with `style` from `scribble/core`.

Helper functions like `nested` are more flexible and will auto-convert
a style-property symbol to a style, but the `nested-flow` constructor
isn't meant to do that.

-- 
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/2020074722.116%40sirmail.smtp.cs.utah.edu.


Re: [racket-users] Changing the charset/encoding when using the db library

2020-07-11 Thread Ryan Culpepper
The db library expects to talk to the MySQL server using utf8. If you
manage to change the connection encoding (eg with SET NAMES), it is likely
to confuse the db library and either corrupt data or make the connection
fail with an error.

Can you explain what you want to accomplish?

Ryan

On Sat, Jul 11, 2020 at 12:06 PM Bonface Munyoki 
wrote:

> Hi all.
>
> I'm using racket to connect to mysql using the db library. I'd like to
> do something like:
>
> --8<---cut here---start->8---
> `sqlalchemy.create_engine(SQL_URI+'?charset=latin1_unicode=0')`
> --8<---cut here---end--->8---
>
> basically adding the equivalent of "charset=latin1_unicode=0" in the
> SQL_URI. I can't seem to find a way to do that in racket. Would anyone
> have an idea of how I would do that?
> ---
> Bonface M. K.(https://www.bonfacemunyoki.com/)
> One Emacs to rule them all
> GPG key = D4F09EB110177E03C28E2FE1F5BBAE1E0392253F
>
> --
> 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/CABAzU5te7aqX%2B6oxUTK8qKr1XA%3DTL1TEL-Eco1s0_vBEC2F09Q%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/CANy33q%3DZS7AXaiHFHMuKkf3o7jr2BQ_zQzK9djmUCqXHn0x4Cw%40mail.gmail.com.


Re: [racket-users] nested-flow and inset

2020-07-11 Thread Matthew Flatt
At Sat, 11 Jul 2020 11:47:22 -0600, Matthew Flatt wrote:
> To construct a style that has 'nested as a property, use `(style #f
> '(nested))` with `style` from `scribble/core`.

Wrong again: That should have been be 'inset as a name, not 'nested as
a property, so `(style 'inset ())`.

-- 
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/2020075028.2ee%40sirmail.smtp.cs.utah.edu.


[racket-users] racket_boot out of memory

2020-07-11 Thread Nate Griswold
Has anyone run into an out of memory exit when calling racket_boot on mac
os x?

Mine was working fine until i turned system integrity protection back on,
now i can't seem to get it to work.

Anyway, just wanted to check here before i dig further. Please lmk if you
have run into this...

Nate

-- 
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/CAM-xLPqAObJ5NUcQgGG0hG_S9dAfigXmmkAMSOyo-iF-gGehBw%40mail.gmail.com.