From 0d55aeac8295b655b120babccd590f5c4f65355a Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 18 Oct 2016 17:08:47 -0700 Subject: [PATCH] updates --- beautiful-racket-lib/br/define.rkt | 7 +++++- beautiful-racket-lib/br/main.rkt | 4 +-- beautiful-racket-lib/br/scribblings/br.scrbl | 26 +++++++++++++++++++- beautiful-racket/br/demo/bf/atsign.rkt | 4 +-- beautiful-racket/br/demo/bf/main.rkt | 2 +- 5 files changed, 36 insertions(+), 7 deletions(-) diff --git a/beautiful-racket-lib/br/define.rkt b/beautiful-racket-lib/br/define.rkt index efde574..190e8fe 100644 --- a/beautiful-racket-lib/br/define.rkt +++ b/beautiful-racket-lib/br/define.rkt @@ -264,4 +264,9 @@ (define-macro-cases no-else-macro [(_ ARG) #''got-arg]) - (check-exn exn:fail:syntax? (λ _ (expand-once #'(no-else-macro 'arg1 'arg2))))) \ No newline at end of file + (check-exn exn:fail:syntax? (λ _ (expand-once #'(no-else-macro 'arg1 'arg2))))) + +(define-macro (define-unhygienic-macro (ID PAT ...) BODY ... STX-OBJECT) + #'(define-macro (ID PAT ...) + BODY ... + (datum->syntax caller-stx (syntax->datum STX-OBJECT)))) \ No newline at end of file diff --git a/beautiful-racket-lib/br/main.rkt b/beautiful-racket-lib/br/main.rkt index 4a100c8..0196117 100644 --- a/beautiful-racket-lib/br/main.rkt +++ b/beautiful-racket-lib/br/main.rkt @@ -1,11 +1,11 @@ #lang racket/base (require racket/provide racket/list racket/string racket/format racket/match racket/port br/define br/syntax br/datum br/debug br/cond racket/class racket/vector - (for-syntax racket/base racket/syntax br/syntax br/debug br/define)) + (for-syntax racket/base racket/syntax br/syntax br/debug br/define br/datum)) (provide (all-from-out racket/base) (all-from-out racket/list racket/string racket/format racket/match racket/port br/syntax br/datum br/debug br/cond racket/class racket/vector br/define) - (for-syntax (all-from-out racket/base racket/syntax br/syntax br/debug)) + (for-syntax (all-from-out racket/base racket/syntax br/syntax br/debug br/datum)) (for-syntax caller-stx with-shared-id)) ; from br/define ;; todo: activate at-exp reader by default diff --git a/beautiful-racket-lib/br/scribblings/br.scrbl b/beautiful-racket-lib/br/scribblings/br.scrbl index a13a4e3..7a73bc4 100644 --- a/beautiful-racket-lib/br/scribblings/br.scrbl +++ b/beautiful-racket-lib/br/scribblings/br.scrbl @@ -4,7 +4,7 @@ @(require scribble/eval) @(define my-eval (make-base-eval)) -@(my-eval `(require br racket/stxparam)) +@(my-eval `(require br racket/stxparam (for-syntax br))) @title[#:style 'toc]{Beautiful Racket} @@ -426,3 +426,27 @@ Bind pattern variables within each @racket[stx-pattern] by matching the pattern (m ((1 2) (3 4) (5 6))) ] } + +@defform[(prefix-id prefix id)]{ +Create a new identifier within the lexical context of @racket[id] with the same name, but prefixed with @racket[prefix]. + +@examples[#:eval my-eval +(define-macro ($-define ID VAL) + (with-pattern ([PREFIXED-ID (prefix-id '$ #'ID)]) + #'(define PREFIXED-ID VAL))) +($-define foo 42) +$foo +] +} + +@defform[(suffix-id id suffix)]{ +Create a new identifier within the lexical context of @racket[id] with the same name, but suffixed with @racket[suffix]. + +@examples[#:eval my-eval +(define-macro (define-% ID VAL) + (with-pattern ([ID-SUFFIXED (suffix-id #'ID '%)]) + #'(define ID-SUFFIXED VAL))) +(define-% foo 42) +foo% +] +} \ No newline at end of file diff --git a/beautiful-racket/br/demo/bf/atsign.rkt b/beautiful-racket/br/demo/bf/atsign.rkt index a5d2b0b..0b8fa42 100644 --- a/beautiful-racket/br/demo/bf/atsign.rkt +++ b/beautiful-racket/br/demo/bf/atsign.rkt @@ -1,3 +1,3 @@ -#lang reader "bf-reader.rkt" +#lang reader "reader.rkt" Greatest language ever! -++++-+++-++-++[>++++-+++-++-++<-]>.[ \ No newline at end of file +++++-+++-++-++[>++++-+++-++-++<-]>. \ No newline at end of file diff --git a/beautiful-racket/br/demo/bf/main.rkt b/beautiful-racket/br/demo/bf/main.rkt index 2c59887..aa1b8c6 100644 --- a/beautiful-racket/br/demo/bf/main.rkt +++ b/beautiful-racket/br/demo/bf/main.rkt @@ -1,5 +1,5 @@ #lang br (module reader br - (require "bf-reader.rkt") + (require "reader.rkt") (provide read-syntax))