Metaprogramming in Racket: A Guide to Macros and Language Design
Format:
Paperback
En stock
0.57 kg
Sí
Nuevo
Amazon
USA
- Have you ever looked at your own code and felt like a human compiler? You find yourself writing the same patterns over and over again. You copy-paste a block of error-handling logic, changing only one variable. You manually validate JSON configurations because the language has no way to check them for you. You write "boilerplate" code that serves the machine, not the logic.You are trapped in Phase 0—the runtime. You are stuck obeying the rules of the language. But there is another world. It exists in the split second before your program runs. This is Phase 1: The Expansion Time. In this space, the code is still fluid. It is soft clay, waiting to be sculpted.This book is your invitation to step behind the curtain. We will look at the Macro Expander, the engine that drives Racket. We will explore the concept of Homoiconicity, where code and data are the same thing. You will learn that what looks like a function call might actually be a program that writes other programs.We will climb the Tower of Phases, a concept that baffles many developers, and demystify the difference between "compile time" and "runtime." You will learn to break the rules of Hygiene—the safety mechanism that keeps variables distinct—so you can intentionally inject variables into your user's scope. By the end, you won't just be writing Racket. You will be building your own languages to replace it.What's insideThis book is a comprehensive curriculum designed to take you from a complete novice in metaprogramming to a professional language designer.The Philosophy of Rewriting: Understand why Racket treats code as Syntax Objects carrying source location and lexical scope, rather than just raw text.Pattern-Based Macros: Master syntax-rules to create clean, hygienic syntactic sugar like while loops and list comprehensions without writing complex logic.Breaking Hygiene: Step down to syntax-case to manually manipulate syntax, break scoping rules intentionally, and create "anaphoric" macros that introduce variables like it or self automatically.The Modern Standard: Learn syntax-parse, Racket’s professional macro system. Define reusable Syntax Classes to validate input grammar and produce helpful, precise error messages that guide your users.The Phase Tower: Finally understand the separation between Compile Time and Runtime. Learn how to use begin-for-syntax and cross-phase persistence to manage state during compilation.Language Creation: The ultimate goal. Learn to write a Reader and Expander to create a #lang. We walk through a case study of building a safe, JSON-like configuration language that compiles to strict Racket structs.Who it's meant forThis book is for:Racket Developers who want to move beyond basic functional programming and unlock the full power of the ecosystem.Language Enthusiasts who are curious about how compilers, parsers, and macro expanders work under the hood.Senior Engineers tired of writing repetitive boilerplate code who want to build smarter tools for their teams.Polyglots coming from Rust, Julia, or Elixir who want to understand the theoretical roots of the macro systems in those languages.You do not need to be a compiler expert to read this book, but you should be comfortable with the basics of Racket or a similar Lisp-family language. Stop acting as a translator between your ideas and the computer. Stop waiting for language designers to give you the features you need. Open the hood, take control of the compiler, and build the language you have always wanted to use.Read "Metaprogramming in Racket" today and start rewriting the rules.
IMPORT EASILY
By purchasing this product you can deduct VAT with your RUT number