Skip to content

Instantly share code, notes, and snippets.

@crcx
Forked from lsparrish/On the use of ` (back tick) in macros
Created December 2, 2009 00:19
Show Gist options
  • Save crcx/246775 to your computer and use it in GitHub Desktop.
Save crcx/246775 to your computer and use it in GitHub Desktop.
Commentary on the use of ` in compiler macros

Compiler macros are often used to lay down code in the calling word. You'll see something like:

: foo ['] + compile ['] . compile ; immediate

This is fine, but sometimes you need to deal with other macros:

: bar 1 literal, 2 literal, ['] foo execute ; immediate

This approach has one problem: keeping track of what words need to be compiled and which need to be called. Plus, with Retro's use of word classes, you may have other words that are handled in other ways.

The word ` was written to address this. It is class-aware, so lays down the proper code and the proper class handler for it. With ` the above examples can be rewritten:

: foo ` + ` . ; immediate
: bar ` 1 ` 2 ` foo ; immediate
How about:
: foo `` + . `` ; immediate
: bar `` 1 2 foo `` ; immediate
Slight variation:
{{
: (`)
dup 0 !if literal, which @ d->class @ compile ;then
drop tib >number literal, ['] .data compile ;
---reveal---
: '' ; immediate
: `` repeat ' dup ['] '' =if drop ;then (`) again ; immediate
}}
: foo `` + . '' ; immediate
: bar `` 1 2 foo '' ; immediate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment