Skip to content

Instantly share code, notes, and snippets.

@crcx
Created December 13, 2009 14:45
Show Gist options
  • Select an option

  • Save crcx/255441 to your computer and use it in GitHub Desktop.

Select an option

Save crcx/255441 to your computer and use it in GitHub Desktop.
Refactoring of contrib_comnmentary.retro
Original by docl:
{{
variable tmp
: nf whitespace dup @ tmp ! off ;
: rf tmp @ whitespace ! ;
---reveal---
: ::: nf 10 accept rf ;
}}
I believe the filtering ("nf", "rf") could be done better.
Given:
variable tmp
: nf whitepsace dup tmp ! off ;
: rf tmp @ whitespace ! ;
Since the stack won't be touched outside of ":::", we can eliminate "tmp" variable:
: nf whitespace dup @ swap off ;
: rf whitespace ! ;
Taking it one step further, both definitions can be merged with "later":
: filter ( - ) whitespace dup @ swap off later whitespace ! ;
And then, adapting ":::" to use it:
: ::: ( "- ) filter 10 accept ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment