Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created September 23, 2015 11:48
Show Gist options
  • Select an option

  • Save Vaguery/c1131a6ca3630deeb8e4 to your computer and use it in GitHub Desktop.

Select an option

Save Vaguery/c1131a6ca3630deeb8e4 to your computer and use it in GitHub Desktop.
Stepping through a Push solution
;; I've used «» to indicate the results of applying an instruction to arguments
;; initial state
EXEC: (exec_dup (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length)
;; program gets "unwrapped"
EXEC: exec_dup (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length
;; duplicate next item on exec
EXEC: (\space \newline in1 string_replacechar) (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length
;; code literal gets unwrapped
EXEC: \space \newline in1 string_replacechar (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length
;; char to :char stack
CHAR: \space
EXEC: \newline in1 string_replacechar (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length
;; char to :char stack
CHAR: \newline \space
EXEC: in1 string_replacechar (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length
;; input is a string
CHAR: \newline \space
EXEC: string_replacechar (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length
STRING: in1
;; string_replacechar produces a string
CHAR:
EXEC: (\space \newline in1 string_replacechar) print_string \newline string_removechar string_length
STRING: «string_replacechar in1 \newline \space»
;; code literal on :exec gets unwrapped
CHAR:
EXEC: \space \newline in1 string_replacechar print_string \newline string_removechar string_length
STRING: «string_replacechar in1 \newline \space»
;; char
CHAR: \space
EXEC: \newline in1 string_replacechar print_string \newline string_removechar string_length
STRING: «string_replacechar in1 \newline \space»
;; char
CHAR: \newline \space
EXEC: in1 string_replacechar print_string \newline string_removechar string_length
STRING: «string_replacechar in1 \newline \space»
;; input again
CHAR: \newline \space
EXEC: string_replacechar print_string \newline string_removechar string_length
STRING: in1 «string_replacechar in1 \newline \space»
;; another of those results
CHAR:
EXEC: print_string \newline string_removechar string_length
STRING: «string_replacechar in1 \newline \space» «string_replacechar in1 \newline \space»
;; print one
PRINT: «string_replacechar in1 \newline \space»
CHAR:
EXEC: \newline string_removechar string_length
STRING: «string_replacechar in1 \newline \space»
;; char
PRINT: «string_replacechar in1 \newline \space»
CHAR: \newline
EXEC: string_removechar string_length
STRING: «string_replacechar in1 \newline \space»
;; delete newlines in this string
PRINT: «string_replacechar in1 \newline \space»
CHAR:
EXEC: string_length
STRING: «string_removechar «string_replacechar in1 \newline \space» \newline»
;; how long is that now?
INT: «string_length «string_removechar «string_replacechar in1 \newline \space» \newline»»
PRINT: «string_replacechar in1 \newline \space»
CHAR:
EXEC:
STRING:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment