(defun run-bf (string) (let ((mem (make-vector 30000 0)) (p 0) (i 0) (l (length string)) (return 0)) (while (< i l) (let ((c (aref string i))) (cond ((= c ?+) (incf (aref mem p))) ((= c ?-) (decf (aref mem p))) ((= c ?>) (incf p)) ((= c ?<) (decf p)) ((= c ?.) (insert (aref mem p))) ((= c ?,) (progn (char-after (point)) (forward-char 1))) ((= c ?\[) (if (equal (aref mem p) 0) (setq i (string-match "\\]" string i)) (setq return i))) ((= c ?\]) (setq i (1- return)))) (incf i))))) ;; And here a test-case to demonstrate that it actually works: (run-bf "++++++++++++++++++++++++++++++++[>+>+<<-]>>+++++++++++++++++++++++++<<++++++++++[>>.-<.<-]") ;; Which should output 9 8 7 6 5 4 3 2 1 0 in the current buffer. ;; Bugs: The matching bracket rules is not implemented, so nested ;; loops will fail.