 PRIVATE>
 
 : which ( command -- file/f )
-    current-path (which) ;
+    "PATH" os-env (which) ;


<PRIVATE

: default-path ( -- path )
    os {
        { windows [ ".;C:\\bin" ] }
        { macosx [ ":" ] }
        { linux [ ":/bin:/usr/bin" ] }
    } case ;

: current-path ( -- path )
    "PATH" os-env [ default-path ] unless* ;

: split-path ( path -- seq )
    os windows? ";" ":" ? split harvest ;

: executable? ( path -- ? )
    {
        [ exists? ]
        [ file-executable? ]
        [ file-info directory? not ]
    } 1&& ;

: path-extensions ( command -- commands )
    "PATHEXT" os-env [

    [ prepend-path ] { } assoc>map
    [ executable? ] find nip ;

: (which) ( command path -- file/f )
    split-path os windows? [
        [ path-extensions ] [ "." prefix ] bi*
    ] [ [ 1array ] dip ] if ((which)) ;
