TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Pattern matching in Python

38 点作者 mariusae大约 16 年前

4 条评论

silentbicycle大约 16 年前
While pattern matching is one of my favorite things about OCaml, I'm not sure this fits well in Python. A <i>big</i> part of Python is trying to keep the language from being all things to all people and accumulating esoteric cruft, especially in the syntax. If I ran the zoo, I would have probably chosen a slightly different subset of features for Python, but I have a lot of respect for Guido's intent.<p>Also, doing anything by overloading arithmetic operators for a semantically unrelated purpose tends to be pretty disharmonious with the rest of the language. The only exception I can think of is Lua's LPEG (<a href="http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html" rel="nofollow">http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html</a>), but that's a specific sub-language that tends to be clearly isolated to grammars; in practice, it's usually as distinct as using * within regular expression strings.
paulgb大约 16 年前
Cool.<p>I wrote some pattern matching code myself for python a few months back just for fun. It was extremely unpythonic, but a fun exercise. For comparison, here's my code:<p><a href="http://github.com/paulgb/python-pattern-matching/tree/master" rel="nofollow">http://github.com/paulgb/python-pattern-matching/tree/master</a>
ulf大约 16 年前
This adds a neat Prolog-angle to the whole language. Cant wait to see if someone actually makes a complete prolog-module out of this.
评论 #605498 未加载
评论 #605959 未加载
erlanger大约 16 年前
That is terribly un-Pythonic, and a poor imitation to boot. Neat proof of concept though.