Re: [racket-users] What’s everyone working on this week?

2019-12-10 Thread wanderley.guimar...@gmail.com
Started to read HtDP and I plan to training the design recipe while solving
AoC challenges.  So far, I am enjoying the systematic approach to right
software.  It is funny to realize that you started to solve a problem with
a partial understanding of it.

Playing a bit with rsound.  My goal is to have a Beginner Language like
that manipulates sounds instead of images.  With that in hand, I could play
(literally) in Racket with my musician friend that wants to learn how to
program (that is one more reason why I am reading HtDP).

I might work in a re-write project.  My "first" serious program was a
program to draw gates (those that go in front of houses).  I did it to my
father 16 years ago.  And I decided to re-write it in Racket and see what I
get.  This time the gift will go to my brothers who took over the family
business.

On Tue, Dec 10, 2019 at 3:54 PM Hadi Moshayedi  wrote:

> Started creating some slideshows on postgres internals using #lang
> slideshow: https://github.com/pykello/hadi-slides
>
> Not much content yet, as I've been struggling with getting things
> formatted as I like until now :) and this is my first time using slideshow,
> so I'm pretty slow.
>
> --
> 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%3D1%3DWqK3r9puu7JdM-aJ5HOE1FZSsrSwxaJvOa6eKELRTyu%3Dg%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/CAAmHZoeP99nP33ryzyJcGHeEhd1O9i3Wp-rSJjOCX0ac15sOVg%40mail.gmail.com.


Re: [racket-users] Playing with rsound

2019-12-07 Thread wanderley.guimar...@gmail.com
Thanks!  I will play with clip and assemble.

On Sat, Dec 7, 2019 at 4:39 PM John Clements 
wrote:

> The problem here is that the piano notes are not all the same duration.
> Specifically, your chord  (chord 60 64 67) is a bit longer:
>
> (rs-frames (chord 60 64 67)) -> 161634 frames
> (rs-frames (piano-tone 72)) -> 144000 frames
>
> There are a lot of ways of solving this, including clipping the two sounds
> to the same length and using the `assemble` function. but here’s one simple
> way:
>
>
> (require rsound)
> (require rsound/piano-tones)
> (define (chord . notes)
>   (rs-overlay* (map piano-tone notes)))
> (play (rs-append (rs-overlay (chord 60 64 67)
> (piano-tone 72))
>  (rs-overlay (chord 60 65 69)
> (piano-tone 72))
>  (rs-overlay (chord 62 67 71)
> (piano-tone 74))
>  (rs-overlay (chord 64 67 72)
> (piano-tone 84
>
>
> (that is, put the append on the outside, and the rs-overlays inside it.)
>
> (Also, yes, I made it a little I-IV-V-I instead of the same chord twice.)
>
> John
>
>
>
> > On Dec 7, 2019, at 14:39, wanderley.guimar...@gmail.com wrote:
> >
> > I started to playing around with rsound while reading its
> documentation.  I wrote the following code:
> >
> > #lang racket
> > (require rsound)
> > (require rsound/piano-tones)
> > (define (chord . notes)
> >   (rs-overlay* (map piano-tone notes)))
> > (play (rs-overlay (rs-append (chord 60 64 67)
> >  (chord 60 64 67))
> >   (rs-append (piano-tone 72)
> >  (piano-tone 72
> >
> > and I was expecting to hear `(piano-tone 72)` on the begin of the two
> chords.  The second `(piano-tone 72)` starts few milliseconds after the
> second chord starts.
> >
> > Can you help me understand why this is happening?
> >
> > Thanks,
> > wander
> >
> > --
> > 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/CAAmHZodfci0HM0_b%2BPaEuGBojyJsKwOhDKd-%2Bgi3jJHhaHi7Hg%40mail.gmail.com
> .
>
>
>
> --
Abraço,
Wanderley Guimarães

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


[racket-users] Playing with rsound

2019-12-07 Thread wanderley.guimar...@gmail.com
I started to playing around with rsound while reading its documentation.  I
wrote the following code:

#lang racket
(require rsound)
(require rsound/piano-tones)
(define (chord . notes)
  (rs-overlay* (map piano-tone notes)))
(play (rs-overlay (rs-append (chord 60 64 67)
 (chord 60 64 67))
  (rs-append (piano-tone 72)
 (piano-tone 72

and I was expecting to hear `(piano-tone 72)` on the begin of the two
chords.  The second `(piano-tone 72)` starts few milliseconds after the
second chord starts.

Can you help me understand why this is happening?

Thanks,
wander

-- 
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/CAAmHZodfci0HM0_b%2BPaEuGBojyJsKwOhDKd-%2Bgi3jJHhaHi7Hg%40mail.gmail.com.


Re: [racket-users] Day 7 Advent of Code - continuations?

2019-12-07 Thread wanderley.guimar...@gmail.com
I solved the problem without continuations but I will study them and
rewrite my solution to use them. It might be helpful in future problems.

On Fri, Dec 6, 2019 at 11:58 PM Daniel Prager 
wrote:

> Does anyone have a continuation-based solution to AoC day 7?
>
> https://adventofcode.com/2019/day/7
>
> I don't normally use continuations, and I solved today's puzzles without
> them, but part 2 looks to me like it might have yielded ;-) a more elegant
> solution.
>
> Dan
>
>
> --
> 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/CAFKxZVUHTL3ommwabYEBsYq3WgpDHkgF21HhqaigR-pFXL%2B2iw%40mail.gmail.com
> 
> .
>
-- 
Abraço,
Wanderley Guimarães

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


Re: [racket-users] Re: GUI (get-directory)

2019-12-05 Thread wanderley.guimar...@gmail.com
I think your point is totally valid, and I feel that I already saw such
discussion in the mail list.

You can simplify the process by searching a piece of the documentation in
github.  For example, I search for a piece of the docs from rackjure (1)
which is the second result in my search.


(1)
https://github.com/search?l==macro+automatically+adds+the+parentheses+language%3ARacket=Code


On Thu, Dec 5, 2019 at 12:27 PM David Storrs  wrote:

> For the record, my big concern with the documentation is that it's
> extremely hard to contribute to.  I would be delighted to contribute
> documentation if the process was easy, but it's just not.  For a language
> as amazing as Racket and a documentation set as high-quality as Racket's,
> the difficulty of helping with it is surprising.
>
> tl;dr :  Using literate programming techniques(*) for documentation is a
> bad idea.  So is having random tiny files scattered around instead of one
> single .scrbl file in a location that maps to the URL of the page.
>
> (*) (i.e., having random tiny files with documentation on one particular
> thing and then automating the process of assembling them)
>
>
> My understanding is that the sequence goes like this:
>
> 1) Notice a thing you would like to change (a typo fix, add an example,
> etc)
> 1a) Ask on the mailing list how to contribute changes since the Guide /
> Reference / package does not have clear directions built in
> 2) Go to Github
> 3) Find which racket-related repository is the one that matters for this
> documentation.  The Racket project itself has half a dozen repositories and
> it's not obvious (to me, at least) which one is which.  Things on the
> package server will have a direct link, which helps a lot.
> 4) git fork the appropriate repository, git clone it to your local machine
> 5) grep -r through the clone to find the document that you want to
> modify.  It will not be in a location apparent from the URL of the page you
> were looking at, nor will it be named what that page was named, nor will it
> contain all of the content from that page.  Also, it will be in Scribble,
> which is a DSL that requires non-trivial effort to learn and is non-trivial
> to read.  Still, it produces amazing output so that's probably worth it.
> It's intimidating when you're just getting started, though.
> 6a) make your change
> 6b) google for how to rebuild scribble documentation
> 6c) rebuild (by default this will rebuild all documentation), verify you
> made the change correctly
> 7) git commit, git push
> 8) go back to github and submit a pull request
> 9) (when (eq? (sync pr-msg-ch) 'Accepted) (exit))
> 10) make requested changes
> 11) git commit, git push, goto 9
>
> Compare that to what it looks like in, e.g., Perl
>
> 1) Notice a thing you would like to change (a typo fix, add an example,
> etc)
> 2) got to CPAN and search for the package / tutorial / etc.  clicking on
> the name of the package gets you a listing of all files in the package (cf
> https://metacpan.org/release/ETHER/Moose-2.2012)
> 3) click on the 'Package::Name::Contributing' file and do what it says.
> This will probably be similar to the Racket workflow except that:
>
> a) The complete details are spelled out.
> b) There is a link directly to the repository
> c) The location of the file you need to edit is obvious from the URL of
> the documentation page that you're changing
> d) The file contains the complete text of the page so it's easier to find
> and easier to verify that your edits were correct
> e) The file is in POD, which is so simple that you can generally learn
> what you need just from glancing at the file, and it's easier to read than
> Scribble.  It's simple enough that you generally don't need to rebuild it
> to HTML, but if you choose to then you can easily rebuild just that page.
>
> Example of a Contributing file:
> https://metacpan.org/pod/release/ETHER/Moose-2.2012/lib/Moose/Manual/Contributing.pod
>
>   (NB:  All major Perl packages have a Contributing file and the 'create a
> package' tool for generating Perl modules creates a stub version for you so
> it's hard to forget.  If the author somehow *does* forget and the package
> doesn't have its own Contributing file then CPAN will show you a default
> version that contains all critical information.  Also, it's easy to find
> the Contributing file:  Go to the package listing that's available directly
> on CPAN and Ctrl+F for "Contributing")
>
>
>
> On Tue, Dec 3, 2019 at 5:26 PM James Platt  wrote:
>
>>
>> On Nov 25, 2019, at 1:29 PM, Stephen De Gabrielle wrote:
>>
>> > Many packages contain an /examples folder, and adding examples is an
>> easy way to contribute.
>>
>> I did not know that.  So, I guess the strategy is to find the git
>> repository for the package and look there?  In any case, I haven't been
>> finding these examples with a general web search.
>>
>> >
>> > There is also https://github.com/racket/racket/wiki/Artifacts
>> >
>> >> This page captures useful code 

Re: [racket-users] type-checking error with immutable vectors in for loop

2019-11-25 Thread wanderley.guimar...@gmail.com
Is this a situation where the type-checker needs to be enhanced to
type-check this code, or there is not enough information to type-check the
code?  (I am just curious about that)

On Mon, Nov 25, 2019 at 6:12 AM Sam Tobin-Hochstadt 
wrote:

> This is a situation where the problem is needing more annotations --
> if you write:
>
> (for/list : (Listof M)
>   ([m : M s])
>   m)
>
> it type checks.
>
> Sam
>
> On Mon, Nov 25, 2019 at 3:27 AM bedeke  wrote:
> >
> > Hello,
> >
> > the following doesn't typecheck. Is it a bug? Should I avoid
> Immutable-Vectors?
> > #lang typed/racket/base
> > ;DrRacket, version 7.5.0.3 [3m].
> >
> > (require racket/sequence)
> >
> > (define-type M (Immutable-Vectorof Number))
> >
> > (define s
> >   (in-list (ann (list (vector-immutable 1 2 3)
> >   (vector-immutable 2 3 4)
> >   (vector-immutable 3 4 5))
> > (Listof M
> >
> > (for/list : (Listof M)
> >   ([m s])
> >   m)
> >
> > Kr,
> > Bert
> >
> > --
> > 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/1b1bc126-61d4-476f-bbfd-2bb7fce20aae%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%2Bbsycv4o77sxq_fRtUNqpfmjPicEFNw8VuxRQCkyxzpOA%40mail.gmail.com
> .
>
-- 
Abraço,
Wanderley Guimarães

-- 
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/CAAmHZoe-TABpckmR-bNf9q%3D%3DC2gghnTnG09CraUSMcK9bNJYVw%40mail.gmail.com.


Re: [racket-users] eq? of quoted expressions

2019-10-25 Thread wanderley.guimar...@gmail.com
On Fri, Oct 25, 2019 at 9:28 AM Alexis King  wrote:

> Unlike eq? on symbols, eq?’s behavior on quoted lists is unspecified, so I
> do not think there is a significantly deeper reason than “that isn’t what
> the current implementation chooses to do.” Whether the answer is #t or #f
> could change tomorrow, on a different VM, on a different architecture, or
> on Friday the 13th.
>
> Is there a reason you would like the answer to be #t?

Not strong one.  I was implementing a compiler (to a computer simulator
that I did) and I wanted to express some of my constants as list (because
it would make easier to read them in case expression).  I switched to use
match instead.

My intuition was that two quoted list of constant values would eq?.


>
> > On Oct 25, 2019, at 09:34, wanderley.guimar...@gmail.com wrote:
> >
> > Why (eq? (quote a) (quote a)) is #t but (eq? (quote (a)) (quote (a)))
> > is #f?  I would expect that if (quote (a)) was a mutable pair but it
> > is not since (quote (a)) returns #f.  It seems that guile returns #t
> > as I was expecting.
>
> --
Abraço,
Wanderley Guimarães

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


[racket-users] eq? of quoted expressions

2019-10-25 Thread wanderley.guimar...@gmail.com
Why (eq? (quote a) (quote a)) is #t but (eq? (quote (a)) (quote (a)))
is #f?  I would expect that if (quote (a)) was a mutable pair but it
is not since (quote (a)) returns #f.  It seems that guile returns #t
as I was expecting.

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


Re: [racket-users] How to efficiently simulate a video display

2019-10-22 Thread wanderley.guimar...@gmail.com
Thanks for the quick response.  Can you elaborate a bit more?  I've
never worked with OpenGL before, so I don't know exactly how to start
with that.

I found that I can use the mapped screen directly to generate a
monochrome bitbmap.

   (make-monochrome-bitmap 512 256
 (apply bytes (map (lambda (x) (modulo x 255)) (range (* 512 256)

With that I can get rid of the transformation bits->argb-bytes->pict->bitmap.

I saw gl-context but I didn't figure out how to use it the image that
I send to big-bang.

Thanks,
Wanderley

On Tue, Oct 22, 2019 at 8:58 AM Jay McCarthy  wrote:
>
> I would use a really simple OpenGL draw call that just draws a
> rectangle and update the texture contents with the screen bits.
>
> --
> Jay McCarthy
> Associate Professor @ CS @ UMass Lowell
> http://jeapostrophe.github.io
> Vincit qui se vincit.
>
> On Tue, Oct 22, 2019 at 6:54 PM wanderley.guimar...@gmail.com
>  wrote:
> >
> > Hi folks,
> >
> > I decided to write a computer simulator (16-bit machine as the one
> > built in nand2tetris course) in Racket.  The computer maps the screen
> > to a memory space where bits represent the pixel colors (black and
> > white).
> >
> > Right now, I am generating the screen image by converting the bits to
> > a vector of argb pixels and then converting it to bitmap using
> > argb-pixels->pict and then pict-bitmap.  The screen updates 10 frames
> > per second but this conversion bits->bitmap is a bottleneck even in
> > this low rate of update.
> >
> > How would be a better approach for this process?  I can imagine how an
> > incremental approach can be faster by only changing the necessary
> > parts of the image, but my idea of representing the screen as a
> > quadtree sounds too complex to be the right path.
> >
> > Thanks,
> > Wanderley Guimarães
> >
> > --
> > 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/CAAmHZocH9NaV2hwvQsi%2B_dXZy%3DT4nkPd-HmwhzTGKABh89kntg%40mail.gmail.com.



-- 
Abraço,
Wanderley Guimarães

-- 
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/CAAmHZoend3%2BS3CPKKnuXR%3D8F5vrG1XA%3Dc3LBFtb%2B2rd5EQbMYQ%40mail.gmail.com.


[racket-users] How to efficiently simulate a video display

2019-10-22 Thread wanderley.guimar...@gmail.com
Hi folks,

I decided to write a computer simulator (16-bit machine as the one
built in nand2tetris course) in Racket.  The computer maps the screen
to a memory space where bits represent the pixel colors (black and
white).

Right now, I am generating the screen image by converting the bits to
a vector of argb pixels and then converting it to bitmap using
argb-pixels->pict and then pict-bitmap.  The screen updates 10 frames
per second but this conversion bits->bitmap is a bottleneck even in
this low rate of update.

How would be a better approach for this process?  I can imagine how an
incremental approach can be faster by only changing the necessary
parts of the image, but my idea of representing the screen as a
quadtree sounds too complex to be the right path.

Thanks,
Wanderley Guimarães

-- 
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/CAAmHZocH9NaV2hwvQsi%2B_dXZy%3DT4nkPd-HmwhzTGKABh89kntg%40mail.gmail.com.


Re: [racket-users] Syntax pattern to match a sequence with x identical elements?

2019-10-11 Thread wanderley.guimar...@gmail.com
+1 for adding the explanation to the Guide.

On Fri, Oct 11, 2019 at 9:02 AM David Storrs  wrote:
>
> Alexis, is there any way that we can get this explanation and some of
> the ones you've given me added to the Guide?  I've tried to add things
> to the documentation before, or even just submit typo reports but, as
> I've mentioned before, the way the docs are organized (random little
> snippets scattered in unintuitive locations in a huge code base
> scattered across multiple repositories) presents too high a barrier to
> entry to be worth it for simple changes.  Presumably someone who knows
> the system better could copy/paste this into an appropriate file and
> submit a pull request.
>
> Your explanations of things are extremely helpful, and really REALLY
> need to be part of the docs somewhere.  I would add them myself if the
> method of doing so were straightforward and/or clearly documented.
> Sadly, it is not.
>
> Dave
>
> PS:  IMO, a vastly better system for the docs would be to have a set
> of complete pages that actually correspond to the pages / URLs that
> appear in the presentation.  I'm not sure why it isn't done that way,
> although I'm sure there's a reason.  I do think that it's a major
> problem that is denying a lot of the value of open-source
> documentation.
>
> On Thu, Oct 10, 2019 at 11:17 PM Alexis King  wrote:
> >
> > tl;dr: You need to use an ellipsis, so your pattern should be ((~between 
> > x:integer 3 3) ...). A (much) more detailed explanation of why follows.
> >
> > ~between is an ellipsis-head pattern. The most common ellipsis-head 
> > pattern, ~optional, also works as a plain head pattern, but ~between does 
> > not. What’s the difference?
> >
> > Let’s start by answering what a head pattern is. The simplest kind of 
> > syntax/parse pattern is a single-term pattern, which (as the name implies) 
> > only matches a single syntax object at a time. Head patterns are special in 
> > that they can match zero or more consecutive syntax objects in the head of 
> > a list. What is the head of a list? Well, if you have a list like '(1 2 3 
> > 4), its head is the sequence of elements “1 2 3 4” and its tail is simply 
> > the empty list, '(). It’s possible to write the list '(1 2 3 4 . ()) to 
> > make that more explicit.
> >
> > So when you have a head pattern like (~optional x:integer), it might parse 
> > an integer, but it also might parse nothing. In the latter case, the next 
> > head pattern in the sequence would get a chance to parse the same element 
> > that (~optional x:integer) did. Head patterns are able to do this because 
> > lists introduce a kind of linear sequencing (not just tree-like nesting), 
> > so “skipping” an element is an operation that makes sense.
> >
> > But what about ellipsis-head patterns? These are patterns that don’t just 
> > appear inside a list pattern, they appear inside a list pattern and under 
> > an ellipsis. For example, in the pattern (x y ... z), x and z are head 
> > patterns, but y is an ellipsis-head pattern. While head patterns introduce 
> > the ability to consume one or more elements at a time, ellipsis-head 
> > patterns extend that with the power to match elements in the list out of 
> > order. This is most useful when parsing keyword options, such as in the 
> > following pattern:
> >
> > ((~alt (~once (~seq #:foo foo:integer)) (~once (~seq #:bar 
> > bar:string))) ...)
> >
> > The above pattern will match (#:foo 1 #:bar "two") or (#:bar "two" #:foo 
> > 1), but not (#:foo 1) or (#:foo 1 #:foo 2 #:bar "three"). This is because 
> > ~alt introduces a set of alternatives that can be matched, but unlike a 
> > simple ~or* pattern, it also keeps track of how many times each case 
> > matched, and patterns like ~once, ~optional, and ~between introduce 
> > constraints on the number of times a given case must match for the overall 
> > parse to be successful.
> >
> > Interestingly, note that pattern variables bound under ~once and ~optional 
> > don’t have an ellipsis depth of 1, they have an ellipsis depth of 0. This 
> > is why, in the given example, you can refer to the foo and bar pattern 
> > variables in a template without any ellipses. ~between, however, still 
> > increments the ellipsis depth, since the pattern can actually match 
> > multiple times.
> >
> > In the pattern I suggested at the beginning of this email, ((~between 
> > x:integer 3 3) ...), you’re creating an ellipsis-head context with exactly 
> > one alternative: (~between x:integer 3 3). That is exactly what you want, 
> > so everything works out fine.
> >
> > The one remaining question, however, is why ~between is only allowed as an 
> > ellipsis-head pattern, but ~optional is also allowed as a head pattern. I 
> > can’t say for certain, since you can think of ((~optional x:integer)) as 
> > being sort of implicitly expanded to ((~optional x:integer) ...), and the 
> > same could be done for ~between. However, my guess is that it isn’t allowed 
> > 

Re: [racket-users] Chez Scheme history

2019-05-23 Thread wanderley.guimar...@gmail.com
Thanks for sharing this.

On Thu, May 23, 2019 at 10:09 AM Josh Rubin  wrote:

> I am just starting to learn Racket. Thank you, all Racket developers.
> I read about the concept of using the Chez Scheme runtime system to
> "host" Racket, so I looked into Chez, and found an interesting paper.
>
> The Development of Chez Scheme by R. Kent Dybvig
> https://www.cs.indiana.edu/%7Edyb/pubs/hocs.pdf
>
> I like its discussion of Scheme implementation issues. I also enjoyed
> reading about the author's evolution as a designer.
>
>
> --
> Josh Rubin
> jlru...@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/e2af79aa-d9a4-5960-4402-58f0c51f6757%40gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
Abraço,
Wanderley Guimarães

-- 
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/CAAmHZodEN6Hp%2BsUEg%2BiqD7Ko0mdpNVMZbDdHtfJNgxFYtmVFmA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: I wrote my first macro ever!

2019-04-29 Thread wanderley.guimar...@gmail.com
Hi Jérôme, `syntax-parse` was in my list to explore!  Thanks for the
example!  I did a new version following your example

(require
 (for-syntax
  racket/base
  racket/syntax
  syntax/parse))

(begin-for-syntax
  (define-syntax-class (element-exp)
(pattern (element:id value)
 #:with element? (format-id #'element "~a?" #'element)
 #:with var-decl #'(define element value)
 #:with pred-decl #'(define (element? v) (eq? element v)

(define-syntax (define-enum stx)
  (syntax-parse stx
[(_ name (~var e element-exp) ...)
 (with-syntax ([name? (format-id #'name "~a?" #'name)])
   #'(begin
   e.var-decl ...
   e.pred-decl ...
   (define (name? v) (or (e.element? v) ...]))

(module+ test
  (require rackunit)
  (define-enum animal (dog 1) (cat "2"))
  (check-true (dog? dog))
  (check-false (cat? dog))
  (check-true (animal? dog))
  (check-false (animal? 3)))

I removed the prefix and added a function to check if a value is a
valid enum value.  When trying to write the later, I stuck on the
expression

(define (name? v) (or e.element ...))

which I knew was not what I wanted.  Then I though  "You know, I
really liked to write (or (e.element v) ...).  You know what .. why
not give a try?".  I did and it worked as a charm!  I am amused by the
power of `...` in templates.

On Mon, Apr 29, 2019 at 12:37 AM Jérôme Martin
 wrote:
>
> Hello there!
>
> I'm really glad you're picking up Racket and enjoying it!
>
> I've been through the same paths and struggles before, so thank you very much 
> for posting that piece of
> experience here :)
>
> For your information, here is a syntax-parse version of your macro, which I 
> find simpler to write and understand:
> (it's basically syntactic sugar over syntax-case, but it's really useful!)
>
> #lang racket/base
>
> (provide
>   define-enum)
>
> (require
>   (for-syntax
> racket/base
> racket/syntax
> syntax/parse))
>
> (define-syntax (define-enum stx)
>   (syntax-parse stx
> [(_ name (element value) ...)
>  #:with (name-element? ...)
> (datum->syntax
>   #'(element ...)
>   (map (lambda (elem)
>  (format-id elem "~a-~a?" #'name elem))
>(syntax->list #'(element ...
>  #'(begin
>  (define element value) ...
>  (define (name-element? v)
>(eq? element v)) ...)]))
>
> (module+ test
>   (require rackunit)
>
>   (define-enum unit
> (dry #\d)
> (empty #\.)
> (rock #\#)
> (water #\~))
>
>   (check-true (unit-dry? #\d))
>   (check-false (unit-empty? #\#))
>   (check-false (unit-rock? #\~))
>   (check-true (unit-water? #\~)))
>
> To remove that ugly map, which requires transforming syntaxes to list then 
> back to syntaxes, you can use a syntax-class:
>
> (begin-for-syntax
>   (define-syntax-class (element-exp unit)
> (pattern (element value)
>   #:with pred-name (format-id #'element "~a-~a?" unit #'element)
>   #:with variable #'(define element value)
>   #:with predicate #'(define (pred-name v) (eq? element v)
>
> (define-syntax (define-enum stx)
>   (syntax-parse stx
> [(_ name (~var e (element-exp #'name)) ...)
>  #'(begin
>  e.variable ...
>  e.predicate ...)]))
>
> It's a bit more complicated at first, but it becomes really powerful once you 
> understand how syntax-parse and syntax-classes work.
>
> (the tricky part here is that I'm using a syntax-class that takes the unit 
> name as an argument, which is not so common)
>
> Have fun ;)
>
>
> --
> 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.



-- 
Abraço,
Wanderley Guimarães

-- 
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] I wrote my first macro ever!

2019-04-28 Thread wanderley.guimar...@gmail.com
I've been following the list since I started to play with Racket (~6
months), but I've never had the courage to write a macro.  It was like
a kind of magic that I wanted to manipulate, but I was afraid to do
that.


## Context. Story time!

I discovered Racket because a friend asked me to teach him to how to
program.  Inspired by the Lego kit for robotic that I saw years ago, I
created a little language (move forward and rotate) and started to ask
him to accomplish some tasks with the language.  The day after that, I
searched for "teach kids how to program" (my friend is not a kid
.. but what would be a better way to teach someone?) and I found
"Turtles" which led me to read an article from Papert.  The text was
mind blowing.  I am Brazilian, and I can't say for all of us, but I
was raised with a black/white (or right/wrong) mindset.  This mindset
shaped the way that I've been approaching life.  Basically, I always
had one chance to get things right.  Yeah!  I love programming and it
is a nightmare to try to get things right at first (it is so easy to
be stuck with this mindset).  So, even though I loved programming, I
also hated it.  But the ideas in Papert's article was liberating, I've
never thought that exploring without fear of failure would be so
natural.  I wanted more of it!  I kept searching and found "The Little
Lisper", which I consumed it vigor.  Then I found some of Matthias'
work in programming education and finally Racket.  As I said, I've
been following the list for a while. And man, that is a wonderful
community.  OK! My friend and I never really started those classes,
but I am grateful for his first interest on that.

I've learned that if I want to learn something I have to explore it
without fear!  Then, I decided to do the [Advents of Code
2018](https://adventofcode.com/2018) in
Racket.  My goal was use functional programming and immutability as
much as I can.  I started with Typed Racket, but I found hard to
freely explore while having to satisfy the compiler.  `#lang racket` was
the best option for me.

What about writing macros?  I've been postponing it until April 26th.
I was watching [Inside Racket Seminar 6. Sam Tobin-Hochstadt on
match](https://www.youtube.com/watch?v=IikGK8XP5_Q)
and thinking how these people can write such big programs in an
untyped laguange.  I remembered to see something about "bottom-up
programming" in [Racket
pages](https://docs.racket-lang.org/style/Units_of_Code.html) and I
started to search for it.  I found
the key idea: building the solution from bottom-up give you chance to
build a language for the problem.  It became clear when I saw [Daniel
Friedman & Jason Hemann - Implementing a
microKanren](https://www.youtube.com/watch?v=0FwIwewHC3o) in action
(by the
way, I am a big fan of Friedman) and [Bottom Up vs Top Down Design in
Clojure - Mark Bastian](https://www.youtube.com/watch?v=Tb823aqgX_0).

I went back to my problem and found that I have a code like

(define empty-unit #\.)
(define (empty-unit? v) (eq? #\. v))
(define rock-unit #\.)
(define (rock-unit? v) (eq? #\# v))

which I really wanted to express like

(define-enum unit (empty #\.) (rock #\#))

It is time for writing my first macro!


## Macro time!

My first try was something like this

(define-syntax (define-unit.wrong stx)
  (syntax-case stx ()
[(_ name value)
 (let ([name? (string->symbol (format "~a?" name))])
   #'(begin
   (define name value)
   (define (name? other-value) (eq? value other-value]))

which failed with

; /Users/wander/myprojects/aoc/2018/day17.rkt:118:48: name:
pattern variable cannot be used outside of a template
;   in: name
; [Due to errors, REPL is just module language, requires, and stub
definitions]

I didn't understand the error message, and had no idea of how to move
forward.  I searched the error message and found [Greg Hendershott's
Fear of Macros - Pattern
matching](https://www.greghendershott.com/fear-of-macros/pattern-matching.html)
(by the way, I am big fan of Greg).
After reading his write-up, became easier to read the Racket
documentation.

That was my first macro:

(require (for-syntax racket/syntax))
(define-syntax (define-unit stx)
  (syntax-case stx ()
[(_ name value)
 (with-syntax ([name? (format-id #'name "~a?" #'name)])
   #'(begin
   (define name value)
   (define (name? other-value) (eq? value other-value]))

(define-unit empty-unit #\.)
(define-unit rock-unit #\#)
(define-unit dry-unit #\d)
(define-unit water-unit #\~)

Dude!  I was so excited!  I did my first macro and it wasn't that
scare.  I barely could sleep because I did something cool and I also
wanted to improve my solution with a "more complex syntax". The next
night, I did my second macro:

(define-syntax (define-enum stx)
  (syntax-case stx ()
[(_ name (e v) ...)
 #`(begin
#,@(for/list ([x (syntax->list #'((e v) 

Re: [racket-users] How to refine types when filtering values

2018-12-24 Thread wanderley.guimar...@gmail.com
Thanks for the fast response.

"Instantiate the type of e with types t" in the documentation was crypt to
me.
The examples helped to clarify that if you have generic types A and B in a
type `(All (A B) A -> B)`, then the instantiate the type `(A -> B)` with
`(U Number False) Number)` means that `A` and `B` will be substituted by
`(U Number False)` and `Number` respectively.

That is cool!

Em seg, 24 de dez de 2018 às 13:46, Matthias Felleisen <
matth...@felleisen.org> escreveu:

>
> > #lang typed/racket
> >
> > (define-type MaybePB (U Positive-Byte False))
> >
> > (: f ( [Listof MaybePB] -> [Listof Positive-Byte]))
> > (define (f x)
> >   ((inst filter MaybePB Positive-Byte) number? x))
> >
> > (f '(1 #false))
>
>

-- 
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] How to refine types when filtering values

2018-12-24 Thread wanderley.guimar...@gmail.com
I am trying typed/racket for the first time and I can't figure out how to
refine a (Listof (U Positive-Byte False)) to (Listof Positive-Byte).

For example
> (filter identity '(1 2 3))
- : (Listof Positive-Byte)
'(1 2 3)
> (filter identity '(1 2 3 #f))
- : (Listof (U False Positive-Byte))
'(1 2 3)

It seems that typed/racket can't understand that `identiy` will filter
`False` values.

What is the proper way to filter this value and make sure that the types
won't include `False` branches?

Thanks,
Wanderley

-- 
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] typed racket backend/ir & gpu computing

2018-12-19 Thread wanderley.guimar...@gmail.com
Can you give an example of a simple eDSL language? Not that I am not lazy
but I don’t have an idea of what to search.
On Wed, Dec 19, 2018 at 1:19 PM Matthias Felleisen 
wrote:

>
> embedded as opposed to stand-alone
>
> > On Dec 19, 2018, at 3:08 PM, Greg Hendershott 
> wrote:
> >
> > What is the "e" in "eDSL"?
> >
> > --
> > 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.