Hacker News new | past | comments | ask | show | jobs | submit login

> And here is an another pattern matching implementation for Python [1].

Oh, I like the prettier syntax:

    calc_rules = alt(
      Int(id),
      rule(BinOp("+", Int(X), Int(Y)), to(lambda v: Int(v.X + v.Y))),
      rule(BinOp("-", Int(X), Int(Y)), to(lambda v: Int(v.X - v.Y))),
      rule(BinOp("*", Int(X), Int(Y)), to(lambda v: Int(v.X * v.Y))),
      rule(BinOp("/", Int(X), Int(Y)), to(lambda v: Int(v.X // v.Y)))
    )
(https://github.com/true-grue/raddsl/blob/master/examples/cal...)

This way of sharing variable names between the pattern and the associated action is pretty neat. It's much nicer than Pampy's use of '_' for all variables.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: