import { isArray } from "@thi.ng/checks/is-array" ; import { isFunction } from "@thi.ng/checks/is-function" ; import type { StackContext , StackProc } from "./api.js" ; import { unwrap } from "./word.js" ; param prog param ctx export const run = ( prog , ctx = [ [ ] , [ ] , { } ] ) : StackContext => { if ( isFunction ( prog ) ) { return prog ( ctx ) ; } for ( let p = isArray ( prog ) ? prog : [ prog ] , n = p . length , i = 0 , w ; i < n ; i ++ ) { if ( isFunction ( ( w = p [ i ] ) ) ) { ctx = w ( ctx ) ; } else { ctx [ 0 ] . push ( w ) ; } } return ctx ; } ; /**
 * Like  run , but returns unwrapped result. Syntax sugar for:
 * `unwrap(run(...),n)`
 *
 *  param prog param ctx param n export const runU = ( prog , ctx ? , n = 1 ) => unwrap ( run ( prog , ctx ) , n ) ; /**
 * Like  run , but returns result environment. Syntax sugar for:
 * `run(...)[2]`
 *
 *  param prog param ctx param n export const runE = ( prog , ctx ? ) => run ( prog , ctx ) [ 2 ] ;