(.module: [lux (#- Scope) [abstract ["." monad (#+ do)]] [data ["." product] [text ["%" format (#+ format)]] [collection ["." list ("#@." functor)]]] [target ["_" ruby (#+ Expression)]]] ["." // #_ [runtime (#+ Operation Phase)] ["#." case] ["#/" // ["#/" // [// [synthesis (#+ Scope Synthesis)]]]]]) (def: #export (scope generate [start initsS+ bodyS]) (-> Phase (Scope Synthesis) (Operation (Expression Any))) (do ////.monad [@loop (:: @ map (|>> %.nat (format "loop") _.local) ///.next) initsO+ (monad.map @ generate initsS+) bodyO (///.with-anchor @loop (generate bodyS))] (wrap (|> (_.return bodyO) (_.lambda (#.Some @loop) (|> initsS+ list.enumerate (list@map (|>> product.left (n/+ start) //case.register)))) (_.apply/* initsO+))))) (def: #export (recur generate argsS+) (-> Phase (List Synthesis) (Operation (Expression Any))) (do ////.monad [@scope ///.anchor argsO+ (monad.map @ generate argsS+)] (wrap (_.apply/* argsO+ @scope))))