Recently Written · git

LispBrain

The best Brainfuck debugger available, if you know how the Common Lisp debugger works. Uses Common Lisp's ease of debugging to make debugging Brainfuck code easy. Almost entirely useless.

git clone https://github.com/equwal/LispBrain

Log | Files | Refs


commit 4881de8e4513e6f867d24b46a9c95c89ef6c64f0
Spenser Truex <struex0@gmail.com>
2016-02-14 10:46:44 -0800

Added the alias 'fuck' and the string return

 README.md        | 19 +++++++++++++------
 interpreter.lisp | 25 ++++++++++++++++---------
 packages.lisp    |  3 ++-
 3 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index e8b3b66..2175fc5 100644
--- a/README.md
+++ b/README.md
@@ -15,9 +15,11 @@ Brainfuck is an esoteric programming language that works on a theoretical byte t
 Any other character is considered a "comment" meaning it does nothing.
 ```
 
-These can be combined into a string such as the following "Hello, world!" program:
+These can be combined into a string such as the following "Hello World!#\Newline" program:
 ```
-(interpret "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")
+> (interpret "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.")
+"Hello World!
+"
 ```
 #How to use:
 Run SBCL or another Common Lisp implementation and load the packages file:
@@ -40,15 +42,20 @@ Run a string of brainfuck code with:
 ```
 > (interpret "[code]")
 ```
-Another example:
+For example:
 ```
 > (interpret ".+[.+] Print out all the ascii characters")
 
-�	
+"�	
 


-


 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„
†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
+


 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„
†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
+```
+Take note that the `interpret` command returns a string, which allows the brainfuck to be used within other lisp code.
 
-NIL ;note that NIL will always be returned by (interpret). The above text is written to *standard-output*
+Finally, there is a slightly more profane alias for the `interpret` function:
+```
+> (fuck "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.F+++++++++++++++.U------------------.C++++++++.K")
+"FUCK"
 ```
 #TODO:
  - ASDF would be a better packaging system choice than the current arrangement.
diff --git a/interpreter.lisp b/interpreter.lisp
index ee9fe84..6efa4f3 100644
--- a/interpreter.lisp
+++ b/interpreter.lisp
@@ -17,8 +17,9 @@
 (defparameter *tape-size-default* 30000
   "The size of the tape, in bytes, used to store each byte")
 
-(defparameter *maximum-brainfuck-string-chars* 1000000
-  "The maximum characters allowed in the brainfuck code string")
+(defvar *output* ""
+  "Defaults to an empty string because it is setf'd by other functions")
+
 
 (defun make-tape-array ()
   "Creates a new tape array"
@@ -28,9 +29,7 @@
 (defvar *tape* (make-tape-array)
   "The tape array used to store each byte")
 
-(defun brainfuck-string ()
-  (make-string *maximum-brainfuck-string-chars*))
-(defvar *brainfuck* (brainfuck-string)
+(defvar *brainfuck* ""
   "Place to store brainfuck code input string globally")
 
 ;; Conditions for looping 
@@ -45,8 +44,9 @@
 
 (defun reset-globals ()
   (setf *tape* (make-tape-array))
-  (setf *brainfuck* (brainfuck-string))
-  (setf *pointer* (pointer-default)))
+  (setf *brainfuck* "")
+  (setf *pointer* (pointer-default))
+  (setf *output* ""))
 
 (defmacro byte-value ()
   `(elt *tape* *pointer*))
@@ -63,6 +63,7 @@
   `(if (= (byte-value) ,bound)
       (setf (byte-value) ,bound-next)
       (,operation (byte-value))))
+
 (defun incf-byte ()
   "Increment a byte, and wrap to 0 if 255 is incremented"
   (crement-if incf 255 0))
@@ -109,7 +110,9 @@
   (setf *pointer* (1- *pointer*)))
 
 (defun print-this-byte ()
-  (format t "~a" (integer-to-ascii (byte-value))))
+  (setf *output* (concatenate 'string
+			      *output*
+			      (vector (integer-to-ascii (byte-value))))))
 
 (defun read-this-byte ()
   (setf (byte-value)
@@ -156,4 +159,8 @@
   (reset-globals)
   (setf *brainfuck* brainfuck-string)
   (interpret-fuck-aux 0)
-  nil)
+  *output*)
+
+(defun fuck (brainfuck-string)
+  "An alias for the interpret function"
+  (interpret brainfuck-string))
diff --git a/packages.lisp b/packages.lisp
index 357ffde..a35dc24 100644
--- a/packages.lisp
+++ b/packages.lisp
@@ -7,6 +7,7 @@
 ;;;; THE BRAINFUCK SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THIS BRAINFUCK SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS BRAINFUCK SOFTWARE.
 (defpackage :cl-brainfuck
   (:use :cl)
-  (:export :interpret))
+  (:export :interpret
+	   :fuck))