Skip to content

Instantly share code, notes, and snippets.

@crcx
Forked from lsparrish/gist:264138
Created December 27, 2009 03:21
Show Gist options
  • Save crcx/264139 to your computer and use it in GitHub Desktop.
Save crcx/264139 to your computer and use it in GitHub Desktop.

A Macro for Appending Code Before Evaluation

With this macro loaded, you can append code to a string and evaluate the results easily.

( A macro for appending code blocks. )
{{
  ifNotExists prepend { : prepend ( $$-$ ) here -rot 2 for dup here swap getLength dup allot copy next 0 , ; }
  : $space ( $-$ ) s"  " prepend ;
---reveal---
   : append-block 32 accept tib @ char: { =if
     char: } accept tib tempString keepString literal,
     ` $space ` swap ` prepend then ; compile-only
   : code ( "- ) ` append-block ` dup ` getLength ` eval ; compile-only
}}

Example

: access ( n"- ) 32 accept tib code { + @ . } ;
create mylist 1 , 2 ,
0 access mylist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment