Arrays 通过分解数组来简化boa压缩?

Arrays 通过分解数组来简化boa压缩?,arrays,tuples,factor-lang,Arrays,Tuples,Factor Lang,我经常发现自己处于这样的境地: IN: scratchpad: TUPLE: box length width height ; IN: scratchpad { { 1 2 3 } { 4 5 6 } { 6 7 8 } } --- Data stack: { ~array~ ~array~ ~array~ } IN: scratchpad [ V{ } clone-like ] dup [ map ] dip call --- Data stac

我经常发现自己处于这样的境地:

IN: scratchpad: TUPLE: box
                    length width height ;

IN: scratchpad { { 1 2 3 } { 4 5 6 } { 6 7 8 } }

--- Data stack:
{ ~array~ ~array~ ~array~ }
IN: scratchpad [ V{ } clone-like ] dup [ map ] dip call

--- Data stack:
V{ ~vector~ ~vector~ ~vector~ }
IN: scratchpad [ dup pop swap dup pop swap dup pop swap drop box boa ] map  

--- Data stack:
V{ ~box~ ~box~ ~box~ }
IN: scratchpad dup .
V{
    T{ box { length 3 } { width 2 } { height 1 } }
    T{ box { length 6 } { width 5 } { height 4 } }
    T{ box { length 8 } { width 7 } { height 6 } }
}
这达到了我想要的结果,但这:

dup pop swap
必须复制/粘贴与我要销毁的数组中的项相同的次数,并且数组必须首先是
clone-like
d到
V{}
向量,并且。。。这是非常糟糕、混乱的代码。(请注意,由于堆栈效应,
3[dup pop swap]次
将不起作用。)


必须有更好的方法从数组的项构造
元组的实例。它是什么?

注意,您可以一次从
序列中的
first2
first3
first4
以及
序列中的
x firstn
中解压许多元素。概括

我认为最“factorsh”的方法是定义一个以序列为参数的构造函数:

: seq>box ( s -- box ) first3 box boa ;
然后,您可以在其上映射

{ { 1 2 3 } { 4 5 6 } } [ seq>box ] map
另一方面,更接近你正在做的事情:

{ { 1 2 3 } { 4 5 6 } } [ box prefix >tuple ] map
>元组
采用以下形式的序列

{ name-of-tuple-class 1st-slot-value 2nd-slot-value ... last-slot-value }

因此,你必须给每一个序列加上前缀。

你,我的朋友,是个天才。