brainfuck: collapse spaces to compress better, 2+2=5 test.

db4
John Benediktsson 2014-06-17 09:32:09 -07:00
parent 2f53a7c5de
commit 125f64a72f
2 changed files with 16 additions and 4 deletions

View File

@ -60,4 +60,16 @@ IN: brainfuck.tests
[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]"""
get-brainfuck ] unit-test
! fun with numbers: 2 + 2 = 5
{ "5" } [
"""
+++++ +++++
+ +
+ + + +++++
+++++ +++ +++++
+ + + +++++
+ +
+++++ +++++.
""" get-brainfuck
] unit-test

View File

@ -1,8 +1,8 @@
! Copyright (C) 2009 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: accessors assocs io io.streams.string kernel macros
math peg.ebnf prettyprint sequences strings ;
USING: accessors ascii assocs fry io io.streams.string kernel
macros math peg.ebnf prettyprint sequences strings ;
IN: brainfuck
@ -70,8 +70,8 @@ code = (loop|ops|unknown)* => [[ compose-all ]]
PRIVATE>
MACRO: run-brainfuck ( code -- )
[ <brainfuck> ] swap parse-brainfuck [ drop flush ] 3append ;
[ blank? not ] filter parse-brainfuck
'[ <brainfuck> @ drop flush ] ;
: get-brainfuck ( code -- result )
[ run-brainfuck ] with-string-writer ; inline