Walnut/Advanced Topics/Build your Own Guards

Build Your Own Guards
First, here is a simple guard that matches integer strings and converts them to integers:

def asInt { to coerce(specimen, optEjector) :int { try { return __makeInt(specimen :String) } catch ex { throw.eject(optEjector, ex) }  } }

You can use it like this:

def str := "5 + 7 = 12" def `@{a:asInt} + @{b:asInt} = @{c:asInt}` := str require(a + b == c)

Now for a more complicated example...

Here is the emaker that makes a pair of VOC claim check guards, a proveAuth (i.e., a claimCheck), and a checkAuth (i.e., a checkedClaim):

Now here is an example of the pair of VOC guards in use:

? def [ProveAuth, CheckAuth] := ("voc") # value: [, ] ? def f1 :=  # value:  ? def f2 :=  # value:  ? def foo(f :CheckAuth[f1,f2]) :void { >    println(f.getPath) > }    # value: ? foo(f1) # stdout: c:/Documents and Settings/millerm1/.bashrc #    ? def f3 :=  # value:  ? foo(f3) # problem: Unmatched voc authorization ? foo(f1 :ProveAuth) # stdout: c:/Documents and Settings/millerm1/.bashrc #    ? foo(f3 :ProveAuth) # problem: Unmatched voc authorization ? def bar(f) :void { >    println(f.getPath) > }    # value: ? bar(f1) # stdout: c:/Documents and Settings/millerm1/.bashrc #    ? bar(f1 :ProveAuth) # problem: .getPath/0>