Skip to content

Instantly share code, notes, and snippets.

@dramforever
Last active November 22, 2023 19:10
Show Gist options
  • Save dramforever/2a667e8718e2e240f6b3bcbd339dc0a9 to your computer and use it in GitHub Desktop.
Save dramforever/2a667e8718e2e240f6b3bcbd339dc0a9 to your computer and use it in GitHub Desktop.
\ https://www.cs.utexas.edu/users/EWD/transcriptions/EWD00xx/EWD28.html
: indvar create 0 , ['] @ ,
does> dup cell+ @ execute ;
: :=
>body
dup -rot ! \ Store value
cell+ ['] @ swap ! ; \ Make literal indvar
: indrun
@ >r \ Get start of xts
begin
r@ @ r> cell- >r \ Get xt and go back one
dup while
\ If non-zero, push if is not ' execute and execute otherwise
dup ['] execute = if drop execute then
repeat drop \ If zero done
rdrop ;
: :-
>r \ Word to assign to
\ Save xts to data space backwards
0 , begin dup , while repeat
here 2 cells - r> >body ( saved word)
dup -rot ! \ Store address of xts
cell+ ['] indrun swap ! ; \ Make string indvar
: zero 0 ;
indvar five
indvar three
\ 5 five := E
5 ' five ' := execute
\ 3 three := E
3 ' three ' := execute
indvar prog
indvar plinus
\ S E five P E three P E plinus P E prog :- E
' zero execute
' five ' execute
' three ' execute
' plinus ' execute
' prog ' :- execute
\ S E + P E plinus :- E
' zero execute
' + ' execute
' plinus ' :- execute
\ prog E
' prog execute . \ 8
\ S E - P E plinus :- E
' zero execute
' - ' execute
' plinus ' :- execute
\ prog E
' prog execute . \ 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment