fn val_of_prim(p: Symbol) -> Option<Val> {
        PRIMS.get(&p).cloned().or_else(||
            // starts with digit -> Int
            if p.as_str().chars().next().unwrap().is_digit(10) {
                let i: i32 = p.as_str().parse().ok()?;
                Some(Int(i).into())
            }
            // starts with `[` -> List (must be all ints)
            else if p.as_str().starts_with('[') {
                let intvec: Vec<i32> = serde_json::from_str(p.as_str()).ok()?;
                let valvec: Vec<Val> = intvec.into_iter().map(|v|Dom(Int(v))).collect();
                Some(List(valvec).into())
            } else {
                None
            }
        )
    }
// val_of_prim takes a symbol like "+" or "0" and returns the corresponding Val.
// Note that it can largely just be a call to the global hashmap PRIMS that define_semantics generated
// however you're also free to do any sort of generic parsing you want, allowing for domains with
// infinite sets of values or dynamically generated values. For example here we support all integers
// and all integer lists.
val_of_prim takes a symbol like "+" or "0" and returns the corresponding Val.
Note that it can largely just be a call to the global hashmap PRIMS that define_semantics generated
however you're also free to do any sort of generic parsing you want, allowing for domains with
infinite sets of values or dynamically generated values. For example here we support all integers
and all integer lists.
val_of_prim takes a symbol like " + " or " 0 " and returns the corresponding Val . Note that it can largely just be a call to the global hashmap PRIMS that define_semantics generated however you ' re also free to do any sort of generic parsing you want allowing for domains with infinite sets of values or dynamically generated values . For example here we support all integers and all integer lists .
fn val_of_prim(p: Symbol) -> Option<Val> {
        PRIMS.get(&p).cloned().or_else(||
            // starts with digit -> Int
            if p.as_str().chars().next().unwrap().is_digit(10) {
                let i: i32 = p.as_str().parse().ok()?;
                Some(Int(i).into())
            }
            // starts with `[` -> List (must be all ints)
            else if p.as_str().starts_with('[') {
                let intvec: Vec<i32> = serde_json::from_str(p.as_str()).ok()?;
                let valvec: Vec<Val> = intvec.into_iter().map(|v|Dom(Int(v))).collect();
                Some(List(valvec).into())
            } else {
                None
            }
        )
    }
fn val_of_prim ( p : Symbol ) -> Option < Val > { PRIMS . get ( & p ) . cloned ( ) . or_else ( | | // starts with digit -> Int if p . as_str ( ) . chars ( ) . next ( ) . unwrap ( ) . is_digit ( 10 ) { let i : i32 = p . as_str ( ) . parse ( ) . ok ( ) ? ; Some ( Int ( i ) . into ( ) ) } // starts with `[` -> List (must be all ints) else if p . as_str ( ) . starts_with ( '[' ) { let intvec : Vec < i32 > = serde_json :: from_str ( p . as_str ( ) ) . ok ( ) ? ; let valvec : Vec < Val > = intvec . into_iter ( ) . map ( | v | Dom ( Int ( v ) ) ) . collect ( ) ; Some ( List ( valvec ) . into ( ) ) } else { None } ) }
val_of_prim takes a symbol like "+" or "0" and returns the corresponding Val.
val_of_prim takes a symbol like " + " or " 0 " and returns the corresponding Val .
p
Symbol
p
Symbol