Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dedbox/racket-template
A Racket Meta-Program Generator
https://github.com/dedbox/racket-template
macros meta-programming program-generator racket template-metaprogramming
Last synced: 10 days ago
JSON representation
A Racket Meta-Program Generator
- Host: GitHub
- URL: https://github.com/dedbox/racket-template
- Owner: dedbox
- License: apache-2.0
- Created: 2019-12-07T23:57:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-26T17:32:18.000Z (almost 5 years ago)
- Last Synced: 2024-12-03T08:08:32.872Z (2 months ago)
- Topics: macros, meta-programming, program-generator, racket, template-metaprogramming
- Language: Racket
- Homepage: https://pkgs.racket-lang.org/package/template
- Size: 164 KB
- Stars: 17
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Template Macros
[![Racket Package](https://img.shields.io/badge/raco%20pkg-template-red.svg)](https://pkgd.racket-lang.org/pkgn/package/template)
[![Documentation](https://img.shields.io/badge/read-docs-blue.svg)](http://docs.racket-lang.org/template/)
[![Build Status](https://travis-ci.org/dedbox/racket-template.svg?branch=master)](https://travis-ci.org/dedbox/racket-template)
[![Coverage Status](https://coveralls.io/repos/github/dedbox/racket-template/badge.svg?branch=master)](https://coveralls.io/github/dedbox/racket-template?branch=master)## Dead Simple Code Generation for Racket
Template macros combine the flexibility of [template
meta-programming](https://en.wikipedia.org/wiki/Template_metaprogramming) with
the safety of Racket's hygienic macro sub-system.Template variables are resolved *before* expansion by selectively rewriting
the input text. The extra flexibility makes escaping to the expanding
environment less necessary *and* more convenient.``` racket
#lang racket/base(require racket/match template (for-syntax racket/base))
(define-for-syntax the-fibs
(make-immutable-hash
(for/fold ([fibs '([1 . 1] [0 . 0])])
([k (in-range 2 10)])
`([,k . ,(+ (cdar fibs) (cdadr fibs))] ,@fibs))))(begin-template '#,(map cdr (sort (hash->list the-fibs) < #:key car)))
; '(0 1 1 2 3 5 8 13 21 34)(begin-template
(define fib (match-lambda (for/template ([K (in-range 10)])
[K #,(hash-ref the-fibs K)]))))(fib 8)
; 21(fib 10)
; match-lambda: no matching clause for 10
```## Installation and Use
Template macros are distributed in the
[template](https://pkgs.racket-lang.org/package/template) package on the
official Racket package repository. It can be installed from DrRacket's
package manager, or with `raco pkg` from the comand line.``` shell
raco pkg install template
```To start using template macros, import the `template` collection.
``` racket
(require template)
```See the [official documentation](https://docs.racket-lang.org/template/) for a
detailed overview of template macros, along with a catalog of template
constructors, combiners, and definers.## Contributing
Pull requests of any size are welcome. For help creating one, or to propose
major changes, please open an
[issue](https://github.com/dedbox/racket-template/issues/new) first to discuss
what you would like to change.