added make, dir;
authorwenzelm
Tue, 09 Mar 1999 12:09:51 +0100
changeset 6319 80173cb8691c
parent 6318 4a423e8a0b54
child 6320 4df282137880
added make, dir;
src/Pure/General/path.ML
--- a/src/Pure/General/path.ML	Tue Mar 09 12:09:22 1999 +0100
+++ b/src/Pure/General/path.ML	Tue Mar 09 12:09:51 1999 +0100
@@ -19,10 +19,12 @@
   val is_basic: T -> bool
   val append: T -> T -> T
   val appends: T list -> T
+  val make: string list -> T
   val pack: T -> string
   val unpack: string -> T
   val base: T -> T
   val ext: string -> T -> T
+  val dir: T -> T
   val expand: T -> T
 end;
 
@@ -36,7 +38,8 @@
 
 fun err_elem msg chs = error (msg ^ " path element specification: " ^ quote (implode chs));
 
-fun check_elem (chs as ["~"]) = err_elem "Illegal" chs
+fun check_elem (chs as []) = err_elem "Illegal" chs
+  | check_elem (chs as ["~"]) = err_elem "Illegal" chs
   | check_elem (chs as ["~", "~"]) = err_elem "Illegal" chs
   | check_elem chs =
       (case ["/", "\\", "$", ":"] inter_string chs of
@@ -82,6 +85,7 @@
 
 fun append (Path xs) (Path ys) = Path (rev_app (rev xs) ys);
 fun appends paths = foldl (uncurry append) (current, paths);
+val make = appends o map basic;
 fun norm path = rev_app [] path;
 
 
@@ -131,6 +135,11 @@
     Some (prfx, Basic s) => if e = "" then path else Path (prfx @ [Basic (s ^ "." ^ e)])
   | _ => err_no_base path);
 
+fun dir (path as Path xs) =
+  (case try split_last xs of
+    Some (prfx, _) => Path prfx
+  | _ => error ("Cannot split path " ^ quote (pack path)));
+
 
 (* evaluate variables *)