Re: [racket-users] [racket users] Macro literal "|"

2020-02-03 Thread Stephen Chang
As mentioned, to get your macro to work, you have to change how the
reader behaves on "|".

You might be interested in the (implementation of) no-vert-bar reader lang:

https://docs.racket-lang.org/no-vert-bar-lang/index.html

On Mon, Feb 3, 2020 at 6:27 PM Kevin Forchione  wrote:
>
> Hi guys,
> I’ve been  trying to figure out how to use “|” in a macro. I’ve got syntax 
> like this in mind:
>
> (foo A | B)
>
> Not sure if I can do this because the reader expects a pair. If “|” isn’t a 
> convenient literal to work with is there an alternative others have used that 
> represents more or less the idea of “or” or “alternate”?
>
> Thanks!
>
> Kevin
>
> --
> 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/447100AA-DB45-46C3-A7DC-2705A1668302%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/CAFfiA1%2Br-Hg_yn-hhbEaZBjTLn8-v5MvqqAVitMrjj7BEGi40w%40mail.gmail.com.


Re: [racket-users] [racket users] Macro literal "|"

2020-02-03 Thread Philip McGrath
You're right that `|` isn't a valid terminal with the normal reader, but,
as it happens, the zero-length identifier can be written as `||`. (I don't
think the concept of a zero-length identifier is common in other languages:
it corresponds to the empty string.)

-Philip


On Mon, Feb 3, 2020 at 6:27 PM Kevin Forchione  wrote:

> Hi guys,
> I’ve been  trying to figure out how to use “|” in a macro. I’ve got syntax
> like this in mind:
>
> (foo A | B)
>
> Not sure if I can do this because the reader expects a pair. If “|” isn’t
> a convenient literal to work with is there an alternative others have used
> that represents more or less the idea of “or” or “alternate”?
>
> Thanks!
>
> Kevin
>
> --
> 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/447100AA-DB45-46C3-A7DC-2705A1668302%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/CAH3z3gbfU7x6y_XHmK-uKUeH%3D4exbnvw8wUNzNnipzOMeC7bbQ%40mail.gmail.com.


[racket-users] [racket users] Macro literal "|"

2020-02-03 Thread Kevin Forchione
Hi guys,
I’ve been  trying to figure out how to use “|” in a macro. I’ve got syntax like 
this in mind:

(foo A | B) 

Not sure if I can do this because the reader expects a pair. If “|” isn’t a 
convenient literal to work with is there an alternative others have used that 
represents more or less the idea of “or” or “alternate”?

Thanks!

Kevin

-- 
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/447100AA-DB45-46C3-A7DC-2705A1668302%40gmail.com.


Re: [racket-users] Rolling dice game

2020-02-03 Thread Ryan Culpepper

On 2/3/20 12:31 PM, Wilzoo wrote:
Hi guys, so I am working on rolling dice game in GUI, the game rules 
will be something like rolling 3 dices and then giving out points to 2 
players based on the rolled values.


Im now stuck on the showing value in GUI. Basically what I need is to 
show rolled value somewhere in frame.


This is my rolling dice code:

(define (nrandom n)
     (if (= n 0 ) '() (cons (random 1 7) (nrandom (- n 1)

this is my callback function which i know is wrong:

(new button% [parent gamew]
              [label "roll dice"]
              [min-width 150]
              ; Callback procedure for a button click:
              [callback (lambda (b e) (send (nrandom 3) show #t))])

So by using this im getting my 3 values in IDE window. Where should I 
look for information how to get them in frame in some kind of box?


I just started my programming journey and racket documentation is not 
easy for me to get any information from there tbh. Just figuring out how 
to make frame and buttons + callback functions took me good few hours.


(Warning: I haven't tested this code.)

One thing you could do is add a new message% widget to the frame. For 
example, change your callback to the following:


  ;; button callback:
  (lambda (b e)
;; creating the widget has the side effect of adding it
;; to the parent container (gamew)
(new message%
  (parent gamew)
  (label (format "Rolled a ~s" (nrandom 3
(void))

Adding a new widget to the game frame may change its size or layout. You 
can control layout with containers (see pane%, panel%, and their 
subclasses).


But message% widgets aren't very flexible in how they display text. 
Another thing you could do is add a single editor canvas and write all 
of the die-roll messages to its editor. That would look something like this:


  ;; one text% and editor-canvas% per game frame:
  (define t (new text%))
  (define ec (new editor-canvas% (parent gamew) (editor t)))

  ;; the button callback:
  ... (lambda (b e)
(send t insert (format "Rolled a ~s\n" (nrandom 3)))
(void))

You can refine this version by disallowing user edits (see `lock`), 
reliably placing the insertion point at the end of the editor before 
writing, adding styles to the die roll result, etc. See the text% 
documentation.


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/66512696-4249-88d0-3d17-80942cee2a41%40gmail.com.


[racket-users] Rolling dice game

2020-02-03 Thread Wilzoo
Hi guys, so I am working on rolling dice game in GUI, the game rules will 
be something like rolling 3 dices and then giving out points to 2 players 
based on the rolled values. 

Im now stuck on the showing value in GUI. Basically what I need is to show 
rolled value somewhere in frame. 

This is my rolling dice code:

(define (nrandom n)
(if (= n 0 ) '() (cons (random 1 7) (nrandom (- n 1)

this is my callback function which i know is wrong:

(new button% [parent gamew]
 [label "roll dice"]
 [min-width 150]
 ; Callback procedure for a button click:
 [callback (lambda (b e) (send (nrandom 3) show #t))])

So by using this im getting my 3 values in IDE window. Where should I look 
for information how to get them in frame in some kind of box?

I just started my programming journey and racket documentation is not easy 
for me to get any information from there tbh. Just figuring out how to make 
frame and buttons + callback functions took me good few hours.

Thanks for help

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