Re: [racket-users] no TR support for streams?

2019-09-10 Thread 'John Clements' via Racket Users
Oh! and in fact, you already bundled it as a pkg: 
https://pkgs.racket-lang.org/package/typed-racket-stream

Thanks!

John

> On Sep 7, 2019, at 2:23 PM, Alex Knauth  wrote:
> 
> 
>> On Sep 6, 2019, at 1:04 PM, 'John Clements' via Racket Users 
>>  wrote:
>> 
>> Perhaps I just don’t know how to search the racket docs correctly, but IIUC 
>> there’s no support for Streams in the current TR implementation? I just want 
>> to use stream-cons, empty-stream, stream-first, and stream-rest. I guess the 
>> easy workaround is just to use thunks to roll my own stream, but I’m 
>> wondering if I’m missing something obvious?
> 
> You can wrap `stream-cons`, etc. in contracts and keep the original stream 
> data type, but it's trickier than wrapping a normal function, and involves:
>  - an untyped file which imports the macros and exports "function-ized" 
> versions of the macros
>  - a typed file which imports those function-ized things with require/typed, 
> then exports new versions of the macros in terms of the functions
> 
> And looks something like like these two files:
> ; untyped-stream-function-ized.rkt
> #lang racket
> (provide stream-cons/fn)
> (require racket/stream)
> (define (stream-cons/fn a b)
>   (stream-cons (a) (b)))
> 
> ; typed-stream.rkt
> #lang typed/racket
> (provide stream-cons)
> (require/typed "untyped-stream-function-ized.rkt"
>   [stream-cons/fn (All (a) (-> (-> a) (-> (Sequenceof a)) (Sequenceof a)))])
> (define-simple-macro (stream-cons a b)
>   (stream-cons/fn (thunk a) (thunk b)))
> 
> This is the strategy I used for my `typed-racket-stream` repository:
> https://github.com/AlexKnauth/typed-racket-stream
> 
> I wanted to do this instead of "rolling my own" stream library because I 
> wanted to be able to share the same stream data-structure as existing untyped 
> racket files.
> 
> Alex Knauth
> 
> 
> -- 
> 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/50960124-B18A-445F-9511-5899E60D9A86%40knauth.org.



-- 
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/2102ff51-b1e3-49a8-8348-c023dc83d960%40mtasv.net.


Re: [racket-users] transparency in Pict

2019-09-10 Thread George Neuner


On 9/10/2019 11:23 AM, Jens Axel Søgaard wrote:
Den tir. 10. sep. 2019 kl. 17.04 skrev Hendrik Boom 
mailto:hend...@topoi.pooq.com>>:


On Tue, Sep 10, 2019 at 03:23:43PM +0200, Jens Axel Søgaard wrote:

> I have extended "clipped" to handle regions defined by more than
one path.
> Now (clipped c ... p) will make a region from the curves c ...
and use
> the region to clip the pict p. Most common uses:
>
>    (clipped c p)          the part of p inside c
>    (clipped c1 c2 p)   the part of p between c1 and c2 (if c2 is
inside c1)

Does that mean the part of p that is inside c1 and outside c2? (which
would be meaningful even if c1 and c2 intersect?  That might happen
because of numerical instability.)


Whether is point is inside or outside the region given by the
two curves is decided by the "winding rule". See the
discussion on fill (which also uses the winding rule):

https://docs.racket-lang.org/metapict/index.html?q=metapict#%28def._%28%28lib._metapict%2Fdraw..rkt%29._fill%29%29

For filling with the even-odd rule I have an eofill, but I haven't 
written an eoclipped yet.


/Jens Axel


Just a couple of points relevant to using regions in general:

 - any region can be selected as the clipping region for drawing.

 - a region can be created from any closed figure: a rectangle, an 
ellipse, a looping point path, etc.


 - a region can be created by combining other regions using union, 
subtraction, and intersection.


 - a single region can cover multiple disjoint areas.

And a hint:
If you are attempting to "shade" objects by painting them with a partly 
transparent brush, you may (and probably will) end up with Moire 
patterns where objects overlay / intersect each other.  The way to apply 
shade without worrying about Moire is to create a single region that 
simultaneously covers all the to-be-shaded areas, and then to fill/paint 
that region with your chosen shading brush.


YMMV,
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/d201f4a1-5de0-e540-c1ae-8ac02c4d981e%40comcast.net.


Re: [racket-users] transparency in Pict

2019-09-10 Thread Jens Axel Søgaard
Den tir. 10. sep. 2019 kl. 17.04 skrev Hendrik Boom :

> On Tue, Sep 10, 2019 at 03:23:43PM +0200, Jens Axel Søgaard wrote:
>


> > I have extended "clipped" to handle regions defined by more than one
> path.
> > Now (clipped c ... p) will make a region from the curves c ... and use
> > the region to clip the pict p. Most common uses:
> >
> >(clipped c p)  the part of p inside c
> >(clipped c1 c2 p)   the part of p between c1 and c2 (if c2 is inside
> c1)
>
> Does that mean the part of p that is inside c1 and outside c2? (which
> would be meaningful even if c1 and c2 intersect?  That might happen
> because of numerical instability.)
>

Whether is point is inside or outside the region given by the
two curves is decided by the "winding rule". See the
discussion on fill (which also uses the winding rule):

https://docs.racket-lang.org/metapict/index.html?q=metapict#%28def._%28%28lib._metapict%2Fdraw..rkt%29._fill%29%29

For filling with the even-odd rule I have an eofill, but I haven't written
an eoclipped yet.

/Jens Axel

-- 
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/CABefVgwxKrkbuqT_RbHtmX1Oda%2BEY_876naVT%2BQ5GJO2NWqxFQ%40mail.gmail.com.


Re: [racket-users] transparency in Pict

2019-09-10 Thread Hendrik Boom
On Tue, Sep 10, 2019 at 03:23:43PM +0200, Jens Axel Søgaard wrote:
> Den tir. 10. sep. 2019 kl. 14.54 skrev George Neuner :
> 
> >
> > Or create a region with a hole through it and use it to clip the drawing.
> >
> 
> Great suggestion. That's much better than using pict->bitmap.
> 
> I have extended "clipped" to handle regions defined by more than one path.
> Now (clipped c ... p) will make a region from the curves c ... and use
> the region to clip the pict p. Most common uses:
> 
>(clipped c p)  the part of p inside c
>(clipped c1 c2 p)   the part of p between c1 and c2 (if c2 is inside c1)

Does that mean the part of p that is inside c1 and outside c2? (which 
would be meaningful even if c1 and c2 intersect?  That might happen 
because of numerical instability.)

> 
> The example now becomes:
> 
> #lang racket
> (require metapict metapict/polygons)
> 
> (define (cutout p x y r)
>   (defv (w h) (pict-size p))
>   (with-window (window 0 w 0 h)
> (clipped (rectangle (pt 0 0) (pt w h))
>  (circle (pt x y) r)
>  p)))
> 
> (set-curve-pict-size 400 400)
> (def p (brushcolor "red" (fill (regular-polygon 5
> (cutout p 200 200 50)
> 
> Before only one curve was supported and the result of clipped was the
> interior,
> so the old clipped couldn't cut holes.
> 
> /Jens Axel

-- 
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/20190910150434.phffylfchq6ennlm%40topoi.pooq.com.


[racket-users] competition feedback

2019-09-10 Thread Stephen De Gabrielle
Hi Racketeers,

I included some optional questions in the voting for the community choice.
As the responses were anonymous, and generally very positive and/or
reasonable, I thought I’d share them with you.

I’d like to recruit a small team to run the next comp - ideally dividing up
the tasks so they are small and fun and not onerous.

Have a look at the responses and contact me directly if you are interested.

—-

*How could the competition be improved?*

· Minimise the clicks needed to see the contestants' pictures.

· More fish

· Suggest more libraries to inspire people to try.

· Have the pictures of each entry next to the choice boxes

· Require actual image output for all entries so it's easier to vote

· Include the output (picture) in the overview at the end of the
competition for those who don't want to bother with downloading and running
the code.

· Send fewer emails

· WITH MY ENTRY. IT WILL BE AWESOME. WOULD HAVE BEEN. WOULD WILLEN
BEENISH.

· I thought it was handled well.

· unclear if i need to use metapict for this or not



*Are there any other sorts of competition you would like to see?*

· Racket Gamejam competition - Racket low-level competition -
Racket retro competition

· Best Racket tutorial

· Live coding! (Though I probably would not participate myself, but
I'd be very eager to watch it!)

· Racket-based MUD

· Same thing, but using pict3d!

· "THOSE WITH MY ENTRIES THAT I HAVE  A CHANCE OF WINNING.

· I'm having a lot of fun with your form."

· I think the art competitions are great - perhaps animated stuff?



-- 


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAGHj7-%2BZS9ptnyQViyO9-_xLg%3D%3DKyMdhTWicFXacSWsAVcprAA%40mail.gmail.com.


Re: [racket-users] transparency in Pict

2019-09-10 Thread Jens Axel Søgaard
Den tir. 10. sep. 2019 kl. 14.54 skrev George Neuner :

>
> Or create a region with a hole through it and use it to clip the drawing.
>

Great suggestion. That's much better than using pict->bitmap.

I have extended "clipped" to handle regions defined by more than one path.
Now (clipped c ... p) will make a region from the curves c ... and use
the region to clip the pict p. Most common uses:

   (clipped c p)  the part of p inside c
   (clipped c1 c2 p)   the part of p between c1 and c2 (if c2 is inside c1)

The example now becomes:

#lang racket
(require metapict metapict/polygons)

(define (cutout p x y r)
  (defv (w h) (pict-size p))
  (with-window (window 0 w 0 h)
(clipped (rectangle (pt 0 0) (pt w h))
 (circle (pt x y) r)
 p)))

(set-curve-pict-size 400 400)
(def p (brushcolor "red" (fill (regular-polygon 5
(cutout p 200 200 50)

Before only one curve was supported and the result of clipped was the
interior,
so the old clipped couldn't cut holes.

/Jens Axel

-- 
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/CABefVgzoXLWXnjjrJhzwyzPVgHpzW7gif%2BwN5WyGVWzb-FiB1w%40mail.gmail.com.


Re: [racket-users] transparency in Pict

2019-09-10 Thread George Neuner


Or create a region with a hole through it and use it to clip the drawing.
George


On 9/10/2019 8:12 AM, Robby Findler wrote:
Another trick I use is to crop the picture that is nominally below the 
image and then just draw it again, but this time on top.


Robby

On Mon, Sep 9, 2019 at 2:15 PM Jens Axel Søgaard 
mailto:jensa...@soegaard.net>> wrote:


You can use a path with an even-odd-fill to cut out parts.

An example:

#lang racket
(require metapict metapict/polygons)

(define (cutout p x y r)
  (defv (w h) (pict-size p))
  (with-window (window 0 w 0 h)
    (brushstipple (pict->bitmap p)
                  (eofill (rectangle (pt 0 0) (pt w h))
                          (circle x y r)

(set-curve-pict-size 400 400)
(def p (brushcolor "red" (fill (regular-polygon 5
(cutout p 200 200 50)

/Jens Axel

The result (the yellowish color is the background color in my editor):

image.png


Den man. 9. sep. 2019 kl. 20.20 skrev Hendrik Boom
mailto:hend...@topoi.pooq.com>>:

I'm wondering how to cut a transparent hole in something.

Say I have a rectangle and I want to make part of it
transparent so
that I cn see what's behind it.
Drawing a transparent rectangle on top of it won't workm
because it'll
just reveal the original rectangle.
The only way I cn see it to draw the original rectangle in
pieces,
careful avoiding the area I want to make transparent. (that
may be
tricky if the transparent area is, say, a circle).

Is there some convenient operation in Pict that can accomplish
this
more directly?  Kind of the union and intersection and
complementation
on constructive solid geometry, but now 2D.

My guess is no.  I haven't found it.  So I ask.

Maybe I'll need some other drawing tool than Pict. Suggestions
welcome.

-- hendrik

-- 
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/20190909182018.74o322qfwehrmqaz%40topoi.pooq.com.



-- 
-- 
Jens Axel Søgaard


-- 
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/CABefVgy0cxZD1dJv6dA51_rTEFqk3wu-zBSpGdQV-eD1fmurag%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/CAL3TdOMM1rPLCGyicrcEv50USDaHmtOs-hPo4r%2BaKCACAgJw%3Dw%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/a8e5c22e-08d6-0839-1b22-cebe912aa409%40comcast.net.


Re: [racket-users] transparency in Pict

2019-09-10 Thread Robby Findler
Another trick I use is to crop the picture that is nominally below the
image and then just draw it again, but this time on top.

Robby

On Mon, Sep 9, 2019 at 2:15 PM Jens Axel Søgaard 
wrote:

> You can use a path with an even-odd-fill to cut out parts.
>
> An example:
>
> #lang racket
> (require metapict metapict/polygons)
>
> (define (cutout p x y r)
>   (defv (w h) (pict-size p))
>   (with-window (window 0 w 0 h)
> (brushstipple (pict->bitmap p)
>   (eofill (rectangle (pt 0 0) (pt w h))
>   (circle x y r)
>
> (set-curve-pict-size 400 400)
> (def p (brushcolor "red" (fill (regular-polygon 5
> (cutout p 200 200 50)
>
> /Jens Axel
>
> The result (the yellowish color is the background color in my editor):
>
> [image: image.png]
>
>
> Den man. 9. sep. 2019 kl. 20.20 skrev Hendrik Boom  >:
>
>> I'm wondering how to cut a transparent hole in something.
>>
>> Say I have a rectangle and I want to make part of it transparent so
>> that I cn see what's behind it.
>> Drawing a transparent rectangle on top of it won't workm because it'll
>> just reveal the original rectangle.
>> The only way I cn see it to draw the original rectangle in pieces,
>> careful avoiding the area I want to make transparent.  (that may be
>> tricky if the transparent area is, say, a circle).
>>
>> Is there some convenient operation in Pict that can accomplish this
>> more directly?  Kind of the union and intersection and complementation
>> on constructive solid geometry, but now 2D.
>>
>> My guess is no.  I haven't found it.  So I ask.
>>
>> Maybe I'll need some other drawing tool than Pict.  Suggestions welcome.
>>
>> -- hendrik
>>
>> --
>> 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/20190909182018.74o322qfwehrmqaz%40topoi.pooq.com
>> .
>>
>
>
> --
> --
> Jens Axel Søgaard
>
> --
> 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/CABefVgy0cxZD1dJv6dA51_rTEFqk3wu-zBSpGdQV-eD1fmurag%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/CAL3TdOMM1rPLCGyicrcEv50USDaHmtOs-hPo4r%2BaKCACAgJw%3Dw%40mail.gmail.com.


Re: [racket-users] Downloadable tutorials (e.g. on github)? Tutorial example source codes samples attached to DrRacket instalation?

2019-09-10 Thread Philip McGrath
On Tue, Sep 10, 2019 at 1:31 AM Prokop Hapala 
wrote:

> "File > Open Require Path …" ...  "/usr/share/racket/pkgs/games/"
>
> it is strange ... on one computer (at work) it works, on other (at home)
> it does not want to open that directory (the dialog is a bit too
> minimalistic so I don't know what it thinks :-) ). Maybe it may be because
> I was fiddling around with versions (from Ubuntu Repo, and Racket ppa)
>

I can think of two possibilities:

   - If you installed a "minimal Racket" distribution, you won't have the
   "games" package pre-installed. You can get it with "raco pkg install games"
   or the "File > Package Manager …" in DrRacket.
   - There are different ways of configuring your Racket installation that
   will end up putting your packages in different places on the filesystem,
   including user-specific vs. installation-wide places and self-contained vs.
   Unix-style installations. "Open Require Path" should find your packages
   wherever they are, but it takes a require path rather than a file system
   path, so it starts with `games` in this case.

You can try this program:
#lang racket
(require games)
If the package is installed, this should work and open the PLT Games
launcher window. In DrRacket (after it has had a moment to do background
expansion), you can also then right-click on `games` and choose the menu
item "Open main.rkt".

-Philip

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


Re: [racket-users] Simple macro issues

2019-09-10 Thread Philip McGrath
`On Tue, Sep 10, 2019 at 1:19 AM Simon Haines <
simon.hai...@con-amalgamate.net> wrote:

> This is a rather unpleasant pitfall of the REPL. If you try to evaluate
>> the expression `(if #f some-unbound-identifier 1)`, you will see that it
>> evaluates to `#f` in the REPL but raises an unbound identifier error in a
>> module. At the REPL, `some-unbound-identifier` refers to a top-level
>> variable, and it is allowed to support, for example, forward references to
>> identifiers that will be defined in a subsequent interaction, or
>> interactive re-definition of variables.
>>
>
> When entering '(hex a b c 1 2 3)' into the REPL, I don't think the symbols
> 'a', 'b' and 'c' are undefined or forward-references as they appear in the
> taken branch of the conditional. Maybe syntax objects are different coming
> from the REPL than a module, somehow resulting in the macro working as
> expected?
>

When you mention symbols being defined or undefined, which is terminology
that other Lisp and Scheme languages use, I think there can be some
confusion between a few different concepts. In Racket, we reserve the word
"symbol" for a type of value, like a number, string, or boolean. So, in the
expression `(λ (f) (f f))`, there are no symbols: we call `λ` and `f`
"identifiers," which are the parts of the syntax of a program that might
have bindings. Of course you know about `quote`, which can produce a symbol
from literal program text in expressions like `(quote a)` or, more often,
`'a`. Lisp programs that manipulate other programs, most particularly
macros, traditionally used symbols as the representation for identifiers,
but it turns out that a symbol isn't really as much information as you
want, so Racket uses "syntax objects," where a syntax object combines a
datum with lexical context (a set of scopes), source-location information,
and other properties. By analogy to `quote`, the expression `(syntax a)` or
`#'a` produces a syntax object, and in particular a syntax object
representing an identifier. (Sometimes we say "identifier" when we really
mean "a syntax object representing an identifier," which can be a bit
confusing, but then `identifier?` is probably a better function name than
`syntax-object-representating-identifier?`.)

If you consider the expanded form of `(hex a)`:

> (bytes
>   (let ([e (syntax-e #'a)])
> (if (number? e)
> a
> (string->number (symbol->string e) 16
>

The first sub-expression to be evaluated is `#'a`, which produces a syntax
object representing an identifier. This syntax object value is then passed
to the procedure `syntax-e`, which extracts the symbol value.

The key point here is that this doesn't involve a reference to the
identifier `a`: it could be written equivalently as `'a` (and should be, if
you want your macro to work this way), but we can also write it as
`(string->symbol "a")`, which makes it extra clear that the binding of `a`,
or rather the lack thereof, isn't consulted in evaluating this expression.
So we could re-write the expansion of `(hex a)` as:

> (bytes
>   (let ([e (string->symbol "a")])
> (if (number? e)
> a
> (string->number (symbol->string e) 16
>

This makes it clear that the only reference to the identifier `a` is in the
then branch of the conditional, which isn't taken. Probably, in your
original macro, you wanted to write `e` there instead of the template
variable `num`.

-Philip

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