 : define-math-inverse ( word quot1 quot2 -- )
     pick 1quotation 3array "math-inverse" set-word-prop ;
 
-: define-pop-inverse ( word n quot -- )
-    [ dupd "pop-length" set-word-prop ] dip
-    "pop-inverse" set-word-prop ;
+:: define-pop-inverse ( word n quot -- )
+    word n "pop-length" set-word-prop
+    word quot "pop-inverse" set-word-prop ;
 
 ERROR: bad-math-inverse ;
 

SYMBOL: visited

: flattenable? ( object -- ? )
    { [ word? ] [ primitive? not ] [
        { "inverse" "math-inverse" "pop-inverse" }
        [ word-prop ] with any? not
    ] } 1&& ;

: flatten ( quot -- expanded )
    [
        visited [ over suffix ] change
        [
            dup flattenable? [
                def>>

                bi
            ] [ 1quotation ] if
        ] map concat
    ] with-variable ;

ERROR: undefined-inverse ;

