1. Rationale
    1. API
      1. with-prefix
      2. gensym*
      3. prefixes
    2. Examples
  2. Requirements
  3. Last update
  4. Author
  5. License
  6. Version history

Rationale

This module implements only one macro, with-prefix, and ony procedure, a variant of gensym with memory.

The former does the renaming in explicit-renaming-macros automatically. You need only prefix each symbol you want to be renamed of the macro-code and wrap the whole shebang with that macro. The necessary let defining the prefixed symbols as renamed ones than replaces with-prefix.

An example will make this more clear:

 (with-prefix (% gensym)
   `(1 ,%a (,%b ,%a) ,%c d)) 

rewrites to

 (let ((%a (gensym 'a)) (%b (gensym 'b)) (%c (gensym 'c)))
   `(1 ,%a (,%b ,%a) ,%c d))

To be able to test this replacement, you need gensym* instead of gensym.

API

with-prefix

[syntax] (with-prefix (prefix mapper) symtree)

extracts those symbols from symtree, which are prefixed with prefix, and prepends symtree with bindings of the prefixed syms to prefix stripped versions mapped with mapper, e.g. gensym, rename, inject.

gensym*

[procedure] (gensym* sym)

a variant of gensym with memory, i.e. it will always produce the same gensym for its only argument.

prefixes

[procedure] (prefixes)
[procedure] (prefixes sym)

with sym: documentation of exported symbol without sym: list of exported symbols

Examples


(import prefixes)

(gensym* 'a)
;-> (gensym* (quote a))

(with-prefix (% gensym*) `(1 ,%a (,%b ,%a) ,%c d))
;-> (let ((%a (gensym* (quote a))) (%b (gensym* (quote b))) (%c (gensym* (quote c)))) (quasiquote (1 (unquote %a) ((unquote %b) (unquote %a)) (unquote %c) d)))

(equal?
  (with-prefix (% gensym*) `(1 ,%a (,%b ,%a) ,%c d))
  (let ((%a (gensym* 'a)) (%b (gensym* 'b)) (%c (gensym* 'c)))
    `(1 ,%a (,%b a) ,%c d)))
;-> #f

(equal?
  (with-prefix (% gensym*) `(1 ,%a (,%b a) ,%c d))
  (let ((%a (gensym* 'a)) (%b (gensym* 'b)) (%c (gensym* 'c)))
    `(1 ,%a (,%b ,%a) ,%c d)))
;-> #f

Requirements

None

Last update

Mar 24, 2024

Author

Juergen Lorenz

License

Copyright (c) 2022-2023 , Juergen Lorenz, ju (at) jugilo (dot) de All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Version history

1.0
initial check in