Re: [racket-users] Simple macro issues

2019-09-09 Thread Simon Haines
Thanks again Philip for taking the time to reply.

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?

Anyway, I take your point the top level has issues. I will be far more wary 
of it in future.

-- 
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/729c89d9-a301-47ff-8974-93618ef59390%40googlegroups.com.


Re: [racket-users] Simple macro issues

2019-09-09 Thread Philip McGrath
On Mon, Sep 9, 2019 at 8:17 PM Simon Haines 
wrote:

> What wasted a lot of time for me is that, despite the macroexpander's
> results, the macro works as expected in the REPL. If you paste my original
> macro into DrRacket, run it, then type '(hex a)' into the REPL you get the
> expected result. In this case, '(expand (hex a))' doesn't help. This is
> possibly due to something like a combination of phases, environments and
> top-level bindings, but I couldn't figure it out.
>

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.

However, I have to admit that I hadn't realized before that references to
undefined variables are allowed even without a lambda delaying evaluation,
as long as they are in an untaken branch of a conditional. I have to say I
don't like it. This certainly falls under the category of "the top level is
hopeless" [1], but maybe we can do better in Racket2.

[1] See for example https://gist.github.com/samth/3083053, though that list
isn't even up-to-date.

-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/CAH3z3gZGHqow2wS6QOfEa3zT%2BM-y2_HOERuDC_H5KHcYmY7RsQ%40mail.gmail.com.


Re: [racket-users] Simple macro issues

2019-09-09 Thread Simon Haines
Thanks Phillip for providing a very thorough example. There is much to 
digest in there, and some novel ideas I didn't know about (attaching values 
as attributes to syntax).

What wasted a lot of time for me is that, despite the macroexpander's 
results, the macro works as expected in the REPL. If you paste my original 
macro into DrRacket, run it, then type '(hex a)' into the REPL you get the 
expected result. In this case, '(expand (hex a))' doesn't help. This is 
possibly due to something like a combination of phases, environments and 
top-level bindings, but I couldn't figure it out.

In any case, thanks again. I will learn from your example ideas that I hope 
will help future me.

-- 
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/291a7036-3f19-4e72-b093-26eed20aa82e%40googlegroups.com.


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

2019-09-09 Thread Alex Harsanyi


On Monday, September 9, 2019 at 10:09:02 PM UTC+8, Prokop Hapala wrote:
>
> Hi, 
>
> I recently found Racket when I was searching some tutorials about Lisp and 
> Metaprogramming. I really like that the community around DrRacket seems to 
> be very much interested in education, making talks and tutorials even for 
> childerens. The doc pages https://docs.racket-lang.org/ seems to be best 
> what I found up to now in Lisp-world.
>
> What I'm missing however is some example codes which I can just simply 
> download, load in DrRacket, run, and see what it does (without copying it 
> step by step from doc-pages). This is my favourite way of learning - 
> reverse-engineering finished cool demos. I don't like reading tutorials 
> step-by-step. I like just browsing over code examples and see what is 
> interesting.   
>
> I was searching for some time to find some links e.g. to 
> github-repositories with example codes for Racket, but I did not found 
> almost anything usefull (easily accessible, easy to make i run).
>
> Maybe you know processing (https://processing.org/), it is in some 
> aspects similar to DrRacket
>
>- It tries to bring programming to non-programmers (e.g. arts, 
>humanities)
>- It has own minimalistic IDE to make it easier for people
>
> but unlike DrRacket it has huge amount of example codes packed within the 
> standard instalation, (see attached picture). I think it would be great 
> addition to DrRacket, exactly in direction of what you try to achieve.
>
> [image: Screenshot_2019-09-09_15-55-18.png]
>
>
>
>
>
>
>
>
>
>
>
>
> Other great thing which help me learn to program are 
> https://www.shadertoy.com/
> https://www.openprocessing.org/
>
> ... it would be greate if something similar would be there for Racket, 
> Lisp, Haskell or any of these kind of languages
>

Most of the tutorials I wrote on GUI various topics have a link to a Github 
Gist which has the full code which you can download and run in DrRacket 
directly.  The link is usually provided at the end of each blog post -- 
some posts also require additional data files, and links to those files are 
provided too.

Here is a link to those blog posts, but not all of them are tutorials, 
though: https://alex-hhh.github.io/tags/racket.html
 
Alex.

>
> ( I come from graphics/physics background (imperative languages 
> C/C++,GLSL,OpenCL ...  , high-performace), I have no previous experience 
> with any Lisp-family language nor other functional language  )
>
>

-- 
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/eaa60f9e-5cdb-4588-b143-bda156f37725%40googlegroups.com.


Re: [racket-users] transparency in Pict

2019-09-09 Thread Jens Axel Søgaard
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.


[racket-users] transparency in Pict

2019-09-09 Thread 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.


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

2019-09-09 Thread Philip McGrath
For pedagogical examples, you may like the games that go along with the
"Realm of Racket" book, which are also in the main Racket distribution. For
example, try "Open Require Path …" for `realm/chapter2/source`, or here is
the whole collection on GitHub: https://github.com/racket/realm

On Mon, Sep 9, 2019 at 12:35 PM Prokop Hapala 
wrote:

> how can user know that this directory was installed with racket?  DrRacket
> could have some link to this directory somewhere (e.g. under File > Open,
> or Package Manager ...)
>

"File > Open Require Path …" will let you open files with the same style of
path you would use for `require`, regardless of where they live on the file
system.

It is not very straightforward to run these examples. When I just hit "run"
> it does nothing. And it is not obvious what is the "entry point" ...
> something like "main" function in C/C++ ?
>

The `games/main` module (i.e. "/usr/share/racket/pkgs/games/main.rkt")
implements the "PLT Games" executable that is part of the Racket
distribution. Running it in DrRacket is a little non-obvious because of
this bit at the end of the file:

> ;; For test mode, check that we can at least start,
> ;; but exit right away:
> (module+ test
>   (queue-callback (lambda () (exit )) #f))
>

DrRacket runs `test` submodules by default (see the guide section
),
so running this file will quickly call `exit`. You can adjust this in the
"Language > Choose Language …" dialog by clicking "Show Details" and
customizing the "Submodules to Run," but you could also just run one of
these at the command line:

   - racket --lib games
   - racket /usr/share/racket/pkgs/games/main.rkt
   - plt-games

 -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/CAH3z3gbBq%2BEmabZ6zaJqjDELd4t77FuNgFnqdXuun9kMiDQ4-w%40mail.gmail.com.


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

2019-09-09 Thread Prokop Hapala
Aha,
/usr/share/racket/pkgs/games/(on Ubuntu 18.04)
Great, that is exactly what I was searching for. Thanks !

Only two things:

   - how can user know that this directory was installed with racket?
   DrRacket could have some link to this directory somewhere (e.g. under File
   > Open, or Package Manager ... )
   - It is not very straightforward to run these examples. When I just hit
   "run" it does nothing. And it is not obvious what is the "entry point" ...
   something like "main" function in C/C++ ?



On Mon, Sep 9, 2019 at 5:48 PM Neil Van Dyke  wrote:

> You can find various Scheme code around the Internet, and various
> textbooks that use Scheme (sometimes with the code available for download).
>
> The Racket code for much of core Racket itself is also available, and
> some of it will probably be installed already, though it's mostly not
> written as beginner tutorials.  (It represents particular styles, and
> can also get pretty obtuse, so grepping for how to do, say, GUI tabs,
> might not be very helpful.)  The first bundled code that comes to mind
> as possibly helpful might be on your system under
> "share/racket/pkgs/games/" (or something like that).
>
> There are some good tutorials that people have written as blog posts and
> Racket manuals.
>
> I agree that a set of code written specifically as "load these in
> Racket" tutorials would be useful for people who like to get started
> that way.  (Perhaps as "notebooks".)  I don't recall much of that
> specifically for Racket, but I've seen it for some other languages and
> frameworks/libraries.
>
> A long time ago, there was a "Scheme Cookbook", IIRC, started by Noel
> Welsh, et al.(?), which emphasized what's now called Racket, but which
> seems to have disappeared.  It wasn't strictly tutorial of the language,
> but was perhaps inspired by a cookbook for Perl, and showed ways to
> accomplish tasks thought to be commonplace, which often meant runnable
> code samples, and one could learn some things just by reading those.
>
>
> Aside, before I encourage people to work on all the above... We already
> have so many piles and piles and manuals and other trappings of big,
> popular platforms, wildly disproportionate to how much actual people and
> real-world uses we have.  I keep thinking of additional ways to promote
> Racket, but I don't want to inadvertently be "playing house".  I
> currently think that one of the most important things we're missing, at
> least for the goal of practical use promotion, is more actual deployed
> real-world success stories, probably from startups.  There's already
> more than enough ways to learn Scheme and Racket sufficiently, to deploy
> real-world systems. If someone is up to doing such a startup: find a
> startup CEO who can get funding, start coding with the copious
> information and community support available for Racket... and then feed
> back your success story, as well as feed back useful generic open source
> modules you'll probably have to write to get to launch.  (And if you can
> get enough funding for that startup, I could help with everything except
> the funding schmoozing.)
>
> Of course, if one wants to make, say, tutorials, that's great, and they
> should.  But if they're starting with the goal of wanting to do big
> things in Racket, or wanting to have other people do big things in
> Racket for some reason, then making tutorials might not be the most
> effective way to achieve that.
>
> (A humanities professor friend says that one of the biggest things she
> has to teach enthusiastic, woke new undergraduates is that they can't
> simply write to "raise awareness".  IIUC, she has them start with issues
> they care about, research and understand the issues objectively, learn
> about the structures in which changes they want can happen, and only
> then effectively communicate, to make actual progress, based on all that
> understanding.  I can't claim to know how for certain how to do this for
> some of the more popular goals of Racket people, including my own goals
> for Racket, but I'll try to keep that wisdom from outside STEM in mind.)
>
> --
> 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/ca06c7bb-f9f7-d59d-0d53-87c6e72619d8%40neilvandyke.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/CAO24GjV3bLme6KH7gPWqh1yvX_%2BBifVCv-9BsNHKfpqO1H%2BAkA%40mail.gmail.com.


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

2019-09-09 Thread Neil Van Dyke
You can find various Scheme code around the Internet, and various 
textbooks that use Scheme (sometimes with the code available for download).


The Racket code for much of core Racket itself is also available, and 
some of it will probably be installed already, though it's mostly not 
written as beginner tutorials.  (It represents particular styles, and 
can also get pretty obtuse, so grepping for how to do, say, GUI tabs, 
might not be very helpful.)  The first bundled code that comes to mind 
as possibly helpful might be on your system under 
"share/racket/pkgs/games/" (or something like that).


There are some good tutorials that people have written as blog posts and 
Racket manuals.


I agree that a set of code written specifically as "load these in 
Racket" tutorials would be useful for people who like to get started 
that way.  (Perhaps as "notebooks".)  I don't recall much of that 
specifically for Racket, but I've seen it for some other languages and 
frameworks/libraries.


A long time ago, there was a "Scheme Cookbook", IIRC, started by Noel 
Welsh, et al.(?), which emphasized what's now called Racket, but which 
seems to have disappeared.  It wasn't strictly tutorial of the language, 
but was perhaps inspired by a cookbook for Perl, and showed ways to 
accomplish tasks thought to be commonplace, which often meant runnable 
code samples, and one could learn some things just by reading those.



Aside, before I encourage people to work on all the above... We already 
have so many piles and piles and manuals and other trappings of big, 
popular platforms, wildly disproportionate to how much actual people and 
real-world uses we have.  I keep thinking of additional ways to promote 
Racket, but I don't want to inadvertently be "playing house".  I 
currently think that one of the most important things we're missing, at 
least for the goal of practical use promotion, is more actual deployed 
real-world success stories, probably from startups.  There's already 
more than enough ways to learn Scheme and Racket sufficiently, to deploy 
real-world systems. If someone is up to doing such a startup: find a 
startup CEO who can get funding, start coding with the copious 
information and community support available for Racket... and then feed 
back your success story, as well as feed back useful generic open source 
modules you'll probably have to write to get to launch.  (And if you can 
get enough funding for that startup, I could help with everything except 
the funding schmoozing.)


Of course, if one wants to make, say, tutorials, that's great, and they 
should.  But if they're starting with the goal of wanting to do big 
things in Racket, or wanting to have other people do big things in 
Racket for some reason, then making tutorials might not be the most 
effective way to achieve that.


(A humanities professor friend says that one of the biggest things she 
has to teach enthusiastic, woke new undergraduates is that they can't 
simply write to "raise awareness".  IIUC, she has them start with issues 
they care about, research and understand the issues objectively, learn 
about the structures in which changes they want can happen, and only 
then effectively communicate, to make actual progress, based on all that 
understanding.  I can't claim to know how for certain how to do this for 
some of the more popular goals of Racket people, including my own goals 
for Racket, but I'll try to keep that wisdom from outside STEM in mind.)


--
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/ca06c7bb-f9f7-d59d-0d53-87c6e72619d8%40neilvandyke.org.


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

2019-09-09 Thread Jens Axel Søgaard
FWIW there a lot of (small) examples at

https://rosettacode.org/wiki/Category:Racket

/Jens Axel

Den man. 9. sep. 2019 kl. 16.09 skrev Prokop Hapala :

> Hi,
>
> I recently found Racket when I was searching some tutorials about Lisp and
> Metaprogramming. I really like that the community around DrRacket seems to
> be very much interested in education, making talks and tutorials even for
> childerens. The doc pages https://docs.racket-lang.org/ seems to be best
> what I found up to now in Lisp-world.
>
> What I'm missing however is some example codes which I can just simply
> download, load in DrRacket, run, and see what it does (without copying it
> step by step from doc-pages). This is my favourite way of learning -
> reverse-engineering finished cool demos. I don't like reading tutorials
> step-by-step. I like just browsing over code examples and see what is
> interesting.
>
> I was searching for some time to find some links e.g. to
> github-repositories with example codes for Racket, but I did not found
> almost anything usefull (easily accessible, easy to make i run).
>
> Maybe you know processing (https://processing.org/), it is in some
> aspects similar to DrRacket
>
>- It tries to bring programming to non-programmers (e.g. arts,
>humanities)
>- It has own minimalistic IDE to make it easier for people
>
> but unlike DrRacket it has huge amount of example codes packed within the
> standard instalation, (see attached picture). I think it would be great
> addition to DrRacket, exactly in direction of what you try to achieve.
>
> [image: Screenshot_2019-09-09_15-55-18.png]
>
>
>
>
>
>
>
>
>
>
>
>
> Other great thing which help me learn to program are
> https://www.shadertoy.com/
> https://www.openprocessing.org/
>
> ... it would be greate if something similar would be there for Racket,
> Lisp, Haskell or any of these kind of languages
>
> ( I come from graphics/physics background (imperative languages
> C/C++,GLSL,OpenCL ...  , high-performace), I have no previous experience
> with any Lisp-family language nor other functional language  )
>
> --
> 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/254a1ad3-637c-46d1-9466-3a10599af180%40googlegroups.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/CABefVgy0r1Bbchy8FirQ46LN%3DyRNocXtaEsc3iVeV%2BxrR%2BNFfw%40mail.gmail.com.


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

2019-09-09 Thread Prokop Hapala
Hi, 

I recently found Racket when I was searching some tutorials about Lisp and 
Metaprogramming. I really like that the community around DrRacket seems to 
be very much interested in education, making talks and tutorials even for 
childerens. The doc pages https://docs.racket-lang.org/ seems to be best 
what I found up to now in Lisp-world.

What I'm missing however is some example codes which I can just simply 
download, load in DrRacket, run, and see what it does (without copying it 
step by step from doc-pages). This is my favourite way of learning - 
reverse-engineering finished cool demos. I don't like reading tutorials 
step-by-step. I like just browsing over code examples and see what is 
interesting.   

I was searching for some time to find some links e.g. to 
github-repositories with example codes for Racket, but I did not found 
almost anything usefull (easily accessible, easy to make i run).

Maybe you know processing (https://processing.org/), it is in some aspects 
similar to DrRacket

   - It tries to bring programming to non-programmers (e.g. arts, 
   humanities)
   - It has own minimalistic IDE to make it easier for people

but unlike DrRacket it has huge amount of example codes packed within the 
standard instalation, (see attached picture). I think it would be great 
addition to DrRacket, exactly in direction of what you try to achieve.

[image: Screenshot_2019-09-09_15-55-18.png] 












Other great thing which help me learn to program are 
https://www.shadertoy.com/
https://www.openprocessing.org/

... it would be greate if something similar would be there for Racket, 
Lisp, Haskell or any of these kind of languages

( I come from graphics/physics background (imperative languages 
C/C++,GLSL,OpenCL ...  , high-performace), I have no previous experience 
with any Lisp-family language nor other functional language  )

-- 
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/254a1ad3-637c-46d1-9466-3a10599af180%40googlegroups.com.


[racket-users] community choice winners

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

The community choice results are in;

1st: tessellation by Zachary Romero https://github.com/zkry/tessellation
2nd: lightsaber by Justin Zamora https://github.com/standard-fish/lightsaber
Best Entry with Butter and Local Maine Maple Syrup:
waffle-racket by Connie https://github.com/conniepocky/waffle-racket

Thank you to all of you for participating.

Kind regards

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/CAGHj7-%2By%3DmGMs05E2G9RpgE17SzZzMh56izoe%2B_nBN-MkesQmw%40mail.gmail.com.


Re: [racket-users] Simple macro issues

2019-09-09 Thread Philip McGrath
On Mon, Sep 9, 2019 at 2:42 AM Simon Haines 
wrote:

> I'm still trying to figure out why my original, terrible macro behaved the
> way it did, but I suspect I'll never know. I would have wasted a lot of
> time on that awful construct. I appreciate your help, many thanks.
>

A great way to understand how your macros are (mis)behaving is to use the
macro stepper in DrRacket to walk through an expansion.

Here's your original macro again, with a slightly smaller example that
produces the same error ("a: unbound identifier in: a"):

> #lang racket
> (define-syntax hex
>   (syntax-rules ()
> [(_ num ...)
>  (bytes
>   (let ([e (syntax-e #'num)])
> (if (number? e) num
> (string->number (symbol->string e) 16))) ...)]))
> (hex a)
>

The macro stepper shows that `(hex a)` expands into this:

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

Hopefully that makes some of the issues clear, starting with the use of `a`
in the "then" branch of your `if` expression, which is indeed an unbound
identifier.

In case you don't already know, you can write literal numbers in hex
notation in Racket, so `(bytes #xa #xb #xc #x1 #x2 #x3 #x41 #x42 #x43)`
evaluates to `#"\n\v\f\1\2\3ABC"`.

I strongly endorse using `syntax-parse` for writing macros, which gives you
good error checking and many other benefits. Here is a version of your
macro that expands to a literal byte-string, rather than an expression that
will create a byte-string at run-time:

> #lang racket
>
> (require (for-syntax syntax/parse))
>
> (define-for-syntax (int->hex n)
>   ;; treats n as though it had been written in hex
>   (let loop ([n n]
>  [place 0]
>  [acc 0])
> (cond
>   [(= 0 n)
>acc]
>   [else
>(define-values [q r]
>  (quotient/remainder n 10))
>(loop q (add1 place) (+ acc (* r (expt 16 place])))
>
>
> (define-syntax (hex stx)
>   (define-syntax-class hex-byte
> #:description "hexadecimal byte"
> #:attributes [n]
> (pattern :exact-nonnegative-integer
>  #:attr n (int->hex (syntax-e this-syntax))
>  #:fail-when (and (not (byte? (attribute n))) this-syntax)
>  "not a byte? when interpreted as hexadecimal")
> (pattern :id
>  #:attr n (string->number (symbol->string
>(syntax-e this-syntax))
>   16)
>  #:fail-when (and (not (attribute n)) this-syntax)
>  "not a hexadecimal number"
>  #:fail-when (and (not (byte? (attribute n))) this-syntax)
>  "hexadecimal number is not a byte?"))
>   (syntax-parse stx
> [(_ :hex-byte ...)
>  #`(quote #,(apply bytes (attribute n)))]))
>
> (hex a b c 1 2 3 41 42 43) ; #"\n\v\f\1\2\3ABC"
>

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


Re: [racket-users] Simple macro issues

2019-09-09 Thread Daniel Prager
Hi Simon

I only use macros sparingly, and sympathise with your struggles to develop
macro-fu.

Some simple macros can be written quite simply using define-syntax-rule/s
and aren't that much more complex than writing functions.

To milk a bit more from this example, here's a similarly themed function:

#lang racket

(define (hex/f hs)
  (apply bytes
 (for/list ([h hs])
   (string->number (~a h) 16

(hex/f '(a b c 1 2 3 41 42 43)) ; #"\n\v\f\1\2\3ABC"


The (marginal) advantage of the macro, of course, is that we can omit the
quote from the function call.

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/CAFKxZVX2gx4PWpdUezs1nq3WJEsrujC3yStRDa-6kBvfrHa%3Dwg%40mail.gmail.com.


Re: [racket-users] Simple macro issues

2019-09-09 Thread Simon Haines
Thanks Dan, I am learning a fair bit today: a quoted number evaluates to 
its unquoted value, and the racket/format templates are available outside 
format (I had forgotten that).

I'm still trying to figure out why my original, terrible macro behaved the 
way it did, but I suspect I'll never know. I would have wasted a lot of 
time on that awful construct. I appreciate your help, many 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/87dcfe25-f3c6-42e1-a82f-24d66fa59f72%40googlegroups.com.


Re: [racket-users] Simple macro issues

2019-09-09 Thread Daniel Prager
Hi Simon

I think you'll find that the if statement is misguided, since it treats
numbers as decimal rather than hex valued.

Happily, this simplifies the solution.

#lang racket

(define-syntax-rule (hex h ...)
  (bytes (string->number (~a (quote h)) 16) ...))

(hex a b c 1 2 3 41 42 43) ; #"\n\v\f\1\2\3ABC"

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/CAFKxZVXHwP5mLFDOKxXim-GmAmtBtCFLM-2zUSoFD4WBALk_bg%40mail.gmail.com.