Macro exercises?

Hi – I’m learning Racket and enjoying it, but what really drew me to the language was its emphasis on making DSLs and new languages; I’ve also heard that its macro system is really nice. So I’m keen to learn about Racket macros.

It would be nice to have some exercises with macros. Any ideas?

The Racket track features practice exercises, which typically can be solved several ways. You could try using macros in your solutions to those exercises.

Outside of Exercism, Beautiful Racket is a well-written book that teaches how to create DSL’s using macros. It is definitely worth a read.

1 Like

I’m reading Beautiful Racket! It’s great! His pedalogical approach is excellent: he starts with the super simple stacker language, and the pacing of the successive iterations and new things is perfect.

My only complaint is that he has his own br language, so you’re not using the 100% standard Racket macro stuff. But he does have a page on how to go from his framework to the base one.

Sure, I can try using macros – but I’m still so new to them that I don’t have a good sense for when to use them.

For example: I’m very good at writing code…and thinking “ahh, I need to write a function for this”. But I don’t have any sense for the macro version of that. When I’m writing Racket code, when should I say “ah, I need a new macro here.” I don’t have any sense of judgement. Maybe working on a few exercises that scaffold me up from the super basic “assert” macro (which seems like the Hello World of macros) to more complex pattern matching and such.

Exercism has two types of exercises, “practice” and “concept”. The practice exercises are generic. They are implemented in every language for which we have a willing implementor. This gives you the chance to see how a given problem plays out in various languages with differing capabilities.

It also means that these problems are generally computational tasks that can be solved in any language. Many languages are designed with their own distinctive goals. Vimscript is for adding editing functions to vim, Lua emphasizes embedding, Elm provides a model for Web development, and so on. By their nature, the practice exercises don’t bring that out. It is all calculating prime numbers and the like.

By contrast, the concept exercises are language-specific. They typically have more detailed instructions intended to guide the solver towards exploring some noteworthy aspect of the language.

Currently, all of the Racket exercises are of the practice variety. A set of concept exercises exploring Racket’s “superpower” of letting you create new languages using its macro facilities would be awesome.

However…

  • All Exercism exercises are created by volunteers, so you have to find someone willing and able to do the work (Hint: it could be you!)
  • Creating exercises that are illuminating, fun, and checkable is not trivial. People who have implemented syllabuses of concept exercises for other languages invariably report that it was hard work.
  • For macros in particular, my feeling is that a satisfying exercise is probably larger in scope than is usual for the problems here. That is not to say that we couldn’t carve up a bigger project into a number of bite-sized pieces, but it would take some careful thought.

So I agree with you in principle and would actually be pretty excited to work towards having such exercises, but realistically it won’t happen anytime soon. You may notice that Racket has about 80 exercises while some other languages are over 150. I have been intending to add more but somehow never get to it. The same goes for @BNAndras though in his defense, he does about a million other things for Exercism.

1 Like

I suspected “it could be you” would eventually get said… :slight_smile:

Fortunately, there are lots of examples scattered around the web, and I could ask some of the authors if Exercism could use them.

I’m a college teacher (math and CS) so I’m well aware of this!

I agree. The nature of macros and good usage thereof does make it quite tricky to have exercises for them. But, I hope we can at least get a start. One or two very simple, basic exercises seems better than none.
or macros in particular, my feeling is that a satisfyor macros in particular, my feeling is that a satisfying exercise ior macros in particular, my feeling is that a satisfying exercise is probably larger in scope than is usual for the problems here. s probably larger in scope than is usual for the problems here. ing exercise is probably larger in scope than is usual for the problems here.

A question for folks who know the landscape of Scheme and Lisp dialects:

The Beautiful Racket book makes it sound like Racket’s macro system is particularly well-refined, sophisticated, and easy to use. Is that generally true? TBH since I’ve started to try learning macros in Racket I haven’t looked at, say, macros in CLOS or emacs lisp.

This statement about “all calculating prime numbers” is not likely a substantial majority for most tracks, and I would say it is inaccurate in description.

We are often eschewing “overly mathy” exercises to avoid that myth that you have to be good at math to be good at programming. Not to say that we have none, but most of the exercises are “light math may be required”.

The first step would be to upgrade the Racket test runner to v2 of the Exercism test runner interface. That lets us present results from individual tests including the test code, which is needed because we don’t show students the concept exercise tests directly.

The major reason Racket and my other maintained tracks are largely still on v1 test runners is that I simply haven’t figured out the v1 → v2 migration. If I get it working for one track, I can try the same approach with the others.

Once Racket is on v2, a track syllabus is possible. The beginner concepts can be adapted from existing track syllabi like Common Lisp’s without a lot of grief, but eventually we’ll run out of adaptable exercises as we get to more Racket-specific concepts. That’s where it’ll get bogged down a bit since we’d need to write brand-new concepts with brand-new exercises and test suites.

However, even just having a limited syllabus with a few simpler concepts would still be helpful and draw attention to the track. There’s at least a minor correlation I believe in a track having a learning mode and students enrolling in the track.

2 Likes