let contains = mapOp1 containsKey
let keys = mapKV (fun (k, v) -> k)
let vals = mapKV (fun (k, v) -> v)
+
+ let atom nextValue = function
+ | [node] -> Atom((nextValue ()), ref node)
+ | _ -> raise <| Error.wrongArity ()
+
+ let deref = function
+ | [Atom(_, r)] -> !r
+ | [_] -> raise <| Error.argMismatch ()
+ | _ -> raise <| Error.wrongArity ()
+
+ let reset = function
+ | [Atom(_, r); node] ->
+ r := node
+ !r
+ | [_; _] -> raise <| Error.argMismatch ()
+ | _ -> raise <| Error.wrongArity ()
+
+ let swap = function
+ | Atom(_, r)
+ ::(BuiltInFunc(_, f) | Func(_, f, _, _, _))
+ ::rest ->
+ r := f (!r::rest)
+ !r
+ | [_; _] -> raise <| Error.argMismatch ()
+ | _ -> raise <| Error.wrongArity ()
| BuiltInFunc(tag, _) | Func(tag, _, _, _, _) ->
pr_func "func" tag
| Macro(tag, _, _, _, _) -> pr_func "macro" tag
+ | Atom(tag, r) -> pr_atom tag !r
and pr separator prefix node =
appendStr prefix
appendStr "\""
and pr_func ftype tag =
- sprintf "#<%s %d>" ftype tag |> appendStr
+ sprintf "#<%s %d>" ftype tag |> appendStr
+
+ and pr_atom tag node =
+ appendStr "(atom "
+ pr_node node
+ appendStr ")"
and pr_list nodes =
appendStr "("
| BuiltInFunc of int * (Node list -> Node)
| Func of int * (Node list -> Node) * Node * Node list * EnvChain
| Macro of int * (Node list -> Node) * Node * Node list * EnvChain
+ | Atom of int * Node Ref
static member private hashSeq (s : seq<Node>) =
let iter st node = (st * 397) ^^^ node.GetHashCode()
| BuiltInFunc(_, _)
| Func(_, _, _, _, _)
| Macro(_, _, _, _, _) -> 9
+ | Atom(_, _) -> 10
static member private equals x y =
match x, y with
| (BuiltInFunc(a, _) | Func(a, _, _, _, _) | Macro(a, _, _, _, _)),
(BuiltInFunc(b, _) | Func(b, _, _, _, _) | Macro(b, _, _, _, _)) ->
a = b
+ | Atom(a, _), Atom(b, _) -> a = b
| _, _ -> false
static member private compare x y =
| (BuiltInFunc(a, _) | Func(a, _, _, _, _) | Macro(a, _, _, _, _)),
(BuiltInFunc(b, _) | Func(b, _, _, _, _) | Macro(b, _, _, _, _)) ->
compare a b
+ | Atom(a, _), Atom(b, _) -> compare a b
| a, b -> compare (Node.rank a) (Node.rank b)
override x.Equals yobj =
| Bool(b) -> hash b
| BuiltInFunc(tag, _) | Func(tag, _, _, _, _) | Macro(tag, _, _, _, _) ->
hash tag
+ | Atom(tag, _) -> hash tag
interface System.IComparable with
member x.CompareTo yobj =