code-arrays: don't ask, don't tell

db4
Doug Coleman 2011-11-27 22:03:55 -08:00
parent 1eaea88912
commit 4dc12f1660
3 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -0,0 +1,13 @@
! Copyright (C) 2011 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: code-arrays locals math tools.test ;
IN: code-arrays.tests
[ { 1 2 9 } ] [ {{ 1 2 3 sq }} ] unit-test
[ { 1 2 { 9 } } ] [ {{ 1 2 {{ 3 sq }} }} ] unit-test
[ H{ { 9 3 } { 4 1 } } ] [ H{{ {{ 3 sq 3 }} {{ 2 sq 1 }} }} ] unit-test
:: local-code-arrays ( -- seq ) {{ 1 2 3 + }} ;
[ { 1 5 } ] [ local-code-arrays ] unit-test

View File

@ -0,0 +1,25 @@
! Copyright (C) 2011 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: combinators.smart hashtables kernel parser quotations
sequences vectors ;
IN: code-arrays
: parse-code-array ( delimiter quot stack -- seq )
[ parse-until >quotation ] dip curry append! ;
DEFER: }}
DEFER: ]]
SYNTAX: {{ \ }} [ output>array ] parse-code-array ;
SYNTAX: [[ \ ]] [ [ ] output>sequence ] parse-code-array ;
SYNTAX: H{{ \ }} [ output>array >hashtable ] parse-code-array ;
SYNTAX: V{{ \ }} [ V{ } output>sequence ] parse-code-array ;
: vector ( seq -- vector ) >vector ;
: hashtable ( seq -- hashtable ) >hashtable ;
: quotation ( seq -- vector ) >quotation ;