All Projects → dedbox → racket-template

dedbox / racket-template

Licence: Apache-2.0 license
A Racket Meta-Program Generator

Programming Languages

racket
414 projects

Projects that are alternatives of or similar to racket-template

so stupid search
It's my honor to drive you fucking fire faster, to have more time with your Family and Sunshine.This tool is for those who often want to search for a string Deeply into a directory in Recursive mode, but not with the great tools: grep, ack, ripgrep .........every thing should be Small, Thin, Fast, Lazy....without Think and Remember too much ...一…
Stars: ✭ 135 (+694.12%)
Mutual labels:  meta-programming
Cometary
Roslyn extensions, with a touch of meta-programming.
Stars: ✭ 31 (+82.35%)
Mutual labels:  meta-programming
Unchained
A fully type safe, compile time only units library.
Stars: ✭ 70 (+311.76%)
Mutual labels:  meta-programming
Truth
A Domain Representation Language
Stars: ✭ 23 (+35.29%)
Mutual labels:  meta-programming
exper
experimental rule-based programming formalism (under construction)
Stars: ✭ 14 (-17.65%)
Mutual labels:  meta-programming
pmatch
Pattern matching DSL for R
Stars: ✭ 21 (+23.53%)
Mutual labels:  meta-programming
Scientific-Programming-in-Julia
Repository for B0M36SPJ
Stars: ✭ 32 (+88.24%)
Mutual labels:  meta-programming
sai
Staged Abstract Interpreters
Stars: ✭ 58 (+241.18%)
Mutual labels:  meta-programming

Template Macros

Racket Package Documentation Build Status Coverage Status

Dead Simple Code Generation for Racket

Template macros combine the flexibility of template meta-programming 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.

#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 package on the official Racket package repository. It can be installed from DrRacket's package manager, or with raco pkg from the comand line.

raco pkg install template

To start using template macros, import the template collection.

(require template)

See the official documentation 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 first to discuss what you would like to change.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].