Re: [racket-users] Expanding Macros

2020-07-09 Thread Thomas Del Vecchio
Thanks so much! Using 

(with-syntax ([expanded-b (datum->syntax #'b (local-expand #'b 'expression 
#f))])

worked out great!

On Thursday, July 9, 2020 at 9:44:08 PM UTC-4, William J. Bowman wrote:
>
> You might want `local-expand`. It can still give you something that is 
> expanded 
> further than you want, unless you know exactly which identifier you want 
> to stop 
> at, which you can specify in the stop list. 
>   
> https://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._~23~25kernel%29._local-expand%29%29
>  
>
> -- 
> William J. Bowman 
>
> On Thu, Jul 09, 2020 at 06:30:38PM -0700, Thomas Del Vecchio wrote: 
> > I'm trying to work through expanding a macro to pass the result into 
> > another macro. I've attached and pasted the spec below that is my toy 
> > example. I've tried using expand, but it gives me "(C (#%app (#%top . B) 
> > (quote 1) (quote 2)))" instead of "(C (in 1 2))". I've also tried many 
> > other things, but none seem to do what I expect/want. Any help? 
> > 
> > #lang racket 
> > (require (for-syntax syntax/parse)) 
> >   
> > ; I want A to take a (B x y) expand it to be passed to C. 
> > ; (A (B 1 2)) 
> > ; -> (C (in 1 2)) 
> > (define-syntax (A stx) 
> >   (syntax-case stx (A) 
> > [(A b) 
> >  (with-syntax ([expanded-b #'b]) ; <- what goes here? 
> >  #'(C expanded-b))])) 
> >   
> > (define-syntax (B stx) 
> >   (syntax-case stx (B) 
> > [(B x y) 
> >  #'(in x y)])) 
> >   
> > (define-syntax (C stx) 
> >   (syntax-case stx (C in) 
> > [(C (in x y)) 
> >  #'(printf "~a ~a ~n" x y)])) 
> >   
> > (A (B 1 2)) ; expect to print "1 2 ~n" 
> > 
> > Thanks! 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups "Racket Users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an email to racket...@googlegroups.com . 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/dd6d4e30-9fd9-4e29-9d36-3a4b0935fc4ao%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/ddf07f17-8e0a-4b36-a1ee-90d3ee00464eo%40googlegroups.com.


Re: [racket-users] Expanding Macros

2020-07-09 Thread William J. Bowman
You might want `local-expand`. It can still give you something that is expanded
further than you want, unless you know exactly which identifier you want to stop
at, which you can specify in the stop list.
  
https://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._~23~25kernel%29._local-expand%29%29

--
William J. Bowman

On Thu, Jul 09, 2020 at 06:30:38PM -0700, Thomas Del Vecchio wrote:
> I'm trying to work through expanding a macro to pass the result into 
> another macro. I've attached and pasted the spec below that is my toy 
> example. I've tried using expand, but it gives me "(C (#%app (#%top . B) 
> (quote 1) (quote 2)))" instead of "(C (in 1 2))". I've also tried many 
> other things, but none seem to do what I expect/want. Any help?
> 
> #lang racket
> (require (for-syntax syntax/parse))
>  
> ; I want A to take a (B x y) expand it to be passed to C.
> ; (A (B 1 2))
> ; -> (C (in 1 2))
> (define-syntax (A stx)
>   (syntax-case stx (A)
> [(A b)
>  (with-syntax ([expanded-b #'b]) ; <- what goes here?
>  #'(C expanded-b))]))
>  
> (define-syntax (B stx)
>   (syntax-case stx (B)
> [(B x y)
>  #'(in x y)]))
>  
> (define-syntax (C stx)
>   (syntax-case stx (C in)
> [(C (in x y))
>  #'(printf "~a ~a ~n" x y)]))
>  
> (A (B 1 2)) ; expect to print "1 2 ~n"
> 
> Thanks!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/racket-users/dd6d4e30-9fd9-4e29-9d36-3a4b0935fc4ao%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/20200710014345.GA11314%40williamjbowman.com.


[racket-users] Expanding Macros

2020-07-09 Thread Thomas Del Vecchio
I'm trying to work through expanding a macro to pass the result into 
another macro. I've attached and pasted the spec below that is my toy 
example. I've tried using expand, but it gives me "(C (#%app (#%top . B) 
(quote 1) (quote 2)))" instead of "(C (in 1 2))". I've also tried many 
other things, but none seem to do what I expect/want. Any help?

#lang racket
(require (for-syntax syntax/parse))
 
; I want A to take a (B x y) expand it to be passed to C.
; (A (B 1 2))
; -> (C (in 1 2))
(define-syntax (A stx)
  (syntax-case stx (A)
[(A b)
 (with-syntax ([expanded-b #'b]) ; <- what goes here?
 #'(C expanded-b))]))
 
(define-syntax (B stx)
  (syntax-case stx (B)
[(B x y)
 #'(in x y)]))
 
(define-syntax (C stx)
  (syntax-case stx (C in)
[(C (in x y))
 #'(printf "~a ~a ~n" x y)]))
 
(A (B 1 2)) ; expect to print "1 2 ~n"

Thanks!

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


testing-macros.rkt
Description: Binary data


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

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

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

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

George

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


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

2020-07-09 Thread Sorawee Porncharoenwase
I did in fact try installing readline-gpl (raco pkg install readline-gpl),
but it didn’t change anything. Interestingly, the bug in #3223 persists for
me, too. This suggests that I didn’t install or invoke it correctly. Do you
need to run racket with any flag to make readline-gpl take its effect?

But yes, the problem is definitely due to readline. Sam suggested me
to try racket
-q which suppresses readline, and the result is that there’s no issue.

On Thu, Jul 9, 2020 at 11:43 AM Philip McGrath 
wrote:

> On Thu, Jul 9, 2020 at 10:32 AM Sorawee Porncharoenwase <
> sorawee.pw...@gmail.com> wrote:
>
>> Racket REPL doesn’t handle unicode well. If you try (regexp-match?
>> #px"^[a-zA-Z]+$" "héllo") in DrRacket, or write it as a program in a
>> file and run it, you will find that it does evaluate to #f.
>>
> See this issue for workarounds, including installing the `readline-gpl`
> package: https://github.com/racket/racket/issues/3223
>
> But you may have some other issues: for me, `(regexp-match?
> #px"^[a-zA-Z]+$" "h\U+FFC3\U+FFA9llo")` gives an error saying "read-syntax:
> no hex digit following `\U`"
>
> For the original question:
>
>
>> On Thu, Jul 9, 2020 at 7:19 AM Peter W A Wood 
>> wrote:
>>
>>> I was experimenting with regular expressions to try to emulate the
>>> Python isalpha() String method.
>>>
>>
> You'd want to benchmark, but, for this purpose, I have a hunch you might
> get better performance by using `in-string` with a `for/and` loop (which
> can use unsafe operations internally)—probably especially so if you were
> content to just test `char-alphabetic?`, which follows Unicode's definition
> of "alphabetic" rather that Python's idiosyncratic one. Here's an example:
>
> #lang racket
>>
>> (module+ test
>>   (require rackunit))
>>
>> (define (char-letter? ch)
>>   ;; not the same as `char-alphabetic?`: see
>>   ;; https://docs.python.org/3/library/stdtypes.html#str.isalpha
>>   (case (char-general-category ch)
>> [(lm lt lu ll lo) #t]
>> [else #f]))
>>
>> (define (string-is-alpha? str)
>>   (for/and ([ch (in-string str)])
>> (char-letter? ch)))
>>
>> (module+ test
>>   (check-true (string-is-alpha? "hello"))
>>   (check-false (string-is-alpha? "h1llo"))
>>   (check-true (string-is-alpha? "héllo")))
>>
>
>

-- 
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/CADcuegsvwBVDhnjtR5Gu6itoYWQPiiQHdwcZnaMv1Qvne2dAVg%40mail.gmail.com.


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

2020-07-09 Thread Philip McGrath
On Thu, Jul 9, 2020 at 10:32 AM Sorawee Porncharoenwase <
sorawee.pw...@gmail.com> wrote:

> Racket REPL doesn’t handle unicode well. If you try (regexp-match?
> #px"^[a-zA-Z]+$" "héllo") in DrRacket, or write it as a program in a file
> and run it, you will find that it does evaluate to #f.
>
See this issue for workarounds, including installing the `readline-gpl`
package: https://github.com/racket/racket/issues/3223

But you may have some other issues: for me, `(regexp-match?
#px"^[a-zA-Z]+$" "h\U+FFC3\U+FFA9llo")` gives an error saying "read-syntax:
no hex digit following `\U`"

For the original question:


> On Thu, Jul 9, 2020 at 7:19 AM Peter W A Wood 
> wrote:
>
>> I was experimenting with regular expressions to try to emulate the Python
>> isalpha() String method.
>>
>
You'd want to benchmark, but, for this purpose, I have a hunch you might
get better performance by using `in-string` with a `for/and` loop (which
can use unsafe operations internally)—probably especially so if you were
content to just test `char-alphabetic?`, which follows Unicode's definition
of "alphabetic" rather that Python's idiosyncratic one. Here's an example:

#lang racket
>
> (module+ test
>   (require rackunit))
>
> (define (char-letter? ch)
>   ;; not the same as `char-alphabetic?`: see
>   ;; https://docs.python.org/3/library/stdtypes.html#str.isalpha
>   (case (char-general-category ch)
> [(lm lt lu ll lo) #t]
> [else #f]))
>
> (define (string-is-alpha? str)
>   (for/and ([ch (in-string str)])
> (char-letter? ch)))
>
> (module+ test
>   (check-true (string-is-alpha? "hello"))
>   (check-false (string-is-alpha? "h1llo"))
>   (check-true (string-is-alpha? "héllo")))
>

-- 
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/CAH3z3gYfZqGe5hQheAsSxdX8VzAsGYhi61W5ZpmMkkaRb0F%2B5A%40mail.gmail.com.


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

2020-07-09 Thread Ryan Culpepper
If you want a regular expression that does match the example string, you
can use the \p{property} notation. For example:

  > (regexp-match? #px"^\\p{L}+$" "h\uFFC3\uFFA9llo")
  #t

The "Regexp Syntax" docs have a grammar for regular expressions with links
to examples.

Ryan


On Thu, Jul 9, 2020 at 4:32 PM Sorawee Porncharoenwase <
sorawee.pw...@gmail.com> wrote:

> Racket REPL doesn’t handle unicode well. If you try (regexp-match?
> #px"^[a-zA-Z]+$" "héllo") in DrRacket, or write it as a program in a file
> and run it, you will find that it does evaluate to #f.
>
> On Thu, Jul 9, 2020 at 7:19 AM Peter W A Wood 
> wrote:
>
>> I was experimenting with regular expressions to try to emulate the Python
>> isalpha() String method. Using a simple [a-zA-Z] character class worked for
>> the English alphabet (ASCII characters):
>>
>> > (regexp-match? #px"^[a-zA-Z]+$" "hello")
>> #t
>> > (regexp-match? #px"^[a-zA-Z]+$" "h1llo")
>> #f
>>
>> It then dawned on me that the Python is alpha() method was Unicode aware:
>>
>> >>> "é".isalpha()
>> True
>>
>> I started scratching my head as how to achieve the equivalent using a
>> regular expression in Python. I tried the same regular expression with a
>> non-English character in the string. To my surprise, the regular expression
>> recognised the non-ASCII characters.
>>
>> > (regexp-match? #px"^[a-zA-Z]+$" "h\U+FFC3\U+FFA9llo")
>> #t
>>
>> Are Racket regular expression character classes Unicode aware or is there
>> some other explanation why this regular expression matches?
>>
>> Peter
>>
>> --
>> 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/2197C34F-165D-4D97-97AD-F158153316F5%40gmail.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/CADcuegsvf-hFwofptc2ieKQmqWFzxDnD1Cn8G7bFSzBZ%2BM3EDA%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%3DtBkQYDg-Tv1MEw17P1ipnqUDcDDFmq_%3DTumUAGJrHAA%40mail.gmail.com.


[racket-users] #quickscript-competition week two

2020-07-09 Thread Stephen De Gabrielle
*#quickscript-competition ** 
week 
two*

*Prizes: *In addition to the glory and admiration of your peers…
If you participate once, you get stickers,
if you participate twice time, you get also a mug,
if you participate three times, you get also a t-shirt
(while stocks last)
*You can participate more than once per week. *

*Thank you to the participants in week 1:*

   - Breakout 
    by Jens 
   Axel Søgaard : The classic Breakout game in a single script!
   - Format-selection 
    by Alex 
   Harsányi : Format comments to the Racket Style Guide standard.
   - Robo-Head-Pat 
    by 
   Lambduli 
   

 : 
   It is like a good work sticker on your homework - but for code.
   - Rot13 Decode/Encode 
    by 
Karrq 
   : Fraq naq qrpbqr frperg zrffntrf yvxr Wnzrf Obaq!

*Don’t forget to check them out!*

*PSA: You don’t need to install Quickscript - it is bundled in DrRacket!*

*Week 2…*starts with a bang with two awesome entries by Laurent Orseau:

   - Letterfall: See you code fall like rocks! 
   
   - Run this quickscript to install all scripts from the competition! 
   

*Looking for ideas?*

   - make a Code-Prettify script that uses pretty-print 
   

and *reindent* to prettify code.

More at 
https://github.com/Quickscript-Competiton/July2020entries/blob/master/IDEAS.md

Enjoy!
Stephen

-- 
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/25715172-4cdd-402b-87ac-1c4caaf1a313n%40googlegroups.com.


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

2020-07-09 Thread Sorawee Porncharoenwase
Racket REPL doesn’t handle unicode well. If you try (regexp-match?
#px"^[a-zA-Z]+$" "héllo") in DrRacket, or write it as a program in a file
and run it, you will find that it does evaluate to #f.

On Thu, Jul 9, 2020 at 7:19 AM Peter W A Wood  wrote:

> I was experimenting with regular expressions to try to emulate the Python
> isalpha() String method. Using a simple [a-zA-Z] character class worked for
> the English alphabet (ASCII characters):
>
> > (regexp-match? #px"^[a-zA-Z]+$" "hello")
> #t
> > (regexp-match? #px"^[a-zA-Z]+$" "h1llo")
> #f
>
> It then dawned on me that the Python is alpha() method was Unicode aware:
>
> >>> "é".isalpha()
> True
>
> I started scratching my head as how to achieve the equivalent using a
> regular expression in Python. I tried the same regular expression with a
> non-English character in the string. To my surprise, the regular expression
> recognised the non-ASCII characters.
>
> > (regexp-match? #px"^[a-zA-Z]+$" "h\U+FFC3\U+FFA9llo")
> #t
>
> Are Racket regular expression character classes Unicode aware or is there
> some other explanation why this regular expression matches?
>
> Peter
>
> --
> 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/2197C34F-165D-4D97-97AD-F158153316F5%40gmail.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/CADcuegsvf-hFwofptc2ieKQmqWFzxDnD1Cn8G7bFSzBZ%2BM3EDA%40mail.gmail.com.


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

2020-07-09 Thread Peter W A Wood
I was experimenting with regular expressions to try to emulate the Python 
isalpha() String method. Using a simple [a-zA-Z] character class worked for the 
English alphabet (ASCII characters):

> (regexp-match? #px"^[a-zA-Z]+$" "hello")
#t
> (regexp-match? #px"^[a-zA-Z]+$" "h1llo")
#f 

It then dawned on me that the Python is alpha() method was Unicode aware:

>>> "é".isalpha()
True

I started scratching my head as how to achieve the equivalent using a regular 
expression in Python. I tried the same regular expression with a non-English 
character in the string. To my surprise, the regular expression recognised the 
non-ASCII characters.

> (regexp-match? #px"^[a-zA-Z]+$" "h\U+FFC3\U+FFA9llo")
#t

Are Racket regular expression character classes Unicode aware or is there some 
other explanation why this regular expression matches?

Peter

-- 
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/2197C34F-165D-4D97-97AD-F158153316F5%40gmail.com.