Explorer

core.eval-pattern

description
Matches value against pattern. some(env with the bound variables) if it matches, none otherwise
type
Fn(pattern: @core.pattern, value: @core.value, env: @core.env) -> Union{#none, #some(@core.env)}
expression
fn(pattern$0, value$1, env$2) =>
  match $0 {
    #any(_) =>
      #some($2),
    #bind(bind$10) =>
      #some(@core.env-extend(env: $2, var_id: $10.variable_id, val: $1)),
    #variant(pattern_variant$11) =>
      match $1 {
        #variant(value_variant$12) =>
          match @core.equal(left: $12.tag, right: $11.tag) {
            true =>
              @core.eval-pattern(pattern: $11.payload, value: $12.payload, env: $2),
            false =>
              #none
          },
        _ =>
          #none
      },
    #string(literal$13) =>
      match $1 {
        #string(s$14) =>
          match @core.equal(left: $14, right: $13) {
            true =>
              #some($2),
            false =>
              #none
          },
        _ =>
          #none
      },
    #number(literal$15) =>
      match $1 {
        #number(n$16) =>
          match @core.equal(left: $16, right: $15) {
            true =>
              #some($2),
            false =>
              #none
          },
        _ =>
          #none
      },
    #boolean(literal$17) =>
      match $1 {
        #boolean(b$18) =>
          match @core.equal(left: $18, right: $17) {
            true =>
              #some($2),
            false =>
              #none
          },
        _ =>
          #none
      }
  }
visibility
public
core.eval-pattern (project definy, branch main, snapshot CfIAXM725tR74SWd4aoTUz4-JJQfqnllblZbQ2Sv204)
id: w4Xd_3wM2OLuD4Kytt33nb_rkxrvitFaqVrNUQkA-ik
content hash: orYdd0IkOLyUi4dUoDzsEry6VkHJtdaNd-BlYI4KSw8