⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unix-env.sml

📁 这是我们参加06年全国开源软件的竞赛作品
💻 SML
字号:
(* unix-env.sml * * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.  See COPYRIGHT file for details. * * A UNIX environment is a list of strings of the form "name=value", where * the "=" character does not appear in name. * NOTE: binding the user's environment as an ML value and then exporting the * ML image can result in incorrect behavior, since the environment bound in the * heap image may differ from the user's environment when the exported image * is used. *)structure UnixEnv : UNIX_ENV =  struct    local      fun isEqual #"=" = true | isEqual _ = false    in    fun splitBinding s = (case (String.fields isEqual s)	   of [a, b] => (a, b)	    | _ => (s, "")	  (* end case *))    end  (* return the value, if any, bound to the name. *)    fun getFromEnv (name, env) = let	  fun look [] = NONE	    | look (s::r) = let		val (n, v) = splitBinding s		in		  if (n = name) then (SOME v) else look r		end	  in	    look env	  end  (* return the value bound to the name, or a default value *)    fun getValue {name, default, env} = (case getFromEnv(name, env)	   of (SOME s) => s	    | NONE => default	  (* end case *))  (* remove a binding from an environment *)    fun removeFromEnv (name, env) = let	  fun look [] = []	    | look (s::r) = let		val (n, v) = splitBinding s		in		  if (n = name) then r else (s :: look r)		end	  in	    look env	  end  (* add a binding to an environment, replacing an existing binding   * if necessary.   *)    fun addToEnv (nameValue, env) = let	  val (name, _) = splitBinding nameValue	  fun look [] = [nameValue]	    | look (s::r) = let		val (n, v) = splitBinding s		in		  if (n = name) then r else (s :: look r)		end	  in	    look env	  end  (* return the user's environment *)    val environ = Posix.ProcEnv.environ  (* return the binding of an environment variable in the   * user's environment.   *)    fun getEnv name = getFromEnv(name, environ())  end; (* UnixEnv *)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -