如何在Common Lisp中进行模式匹配 [英] How to do Pattern Matching in Common Lisp

查看:221
本文介绍了如何在Common Lisp中进行模式匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道Common Lisp是否存在模式匹配功能,但是我必须自己做一个功能.我对Lisp一无所知.有人可以单调学习Lisp吗?最重要的是,如何在Lisp中进行模式匹配.我将不得不传递一个模式和一个事实,然后说出它们是否匹配. 一个例子是

I have no idea if there exists a pattern matching function for Common Lisp, nevertheless I have to make my own function. I have no idea about Lisp. Can somebody give heads-up on learning Lisp and most importantly, how to go about doing pattern matching in Lisp. I will have to pass a pattern and a fact and say if they match. An example would be

(heroes (hitpoints=hp) (mana=m)) 

应该匹配

(Morphling (hitpoints 435) (mana 260))

它还应该能够对数字是大还是小进行数字比较.就像其他英雄的法力值不如变身那样.

it should also be able to also do numeric comparisons of if a number is greater or lesser. Like if another heroes mana is less that Morphling.

推荐答案

各种Lisp书籍中都介绍了简单的模式匹配功能.

Simple pattern matching functionality is explained in various Lisp books.

人工智能编程范例,Common Lisp案例研究,Peter Norvig

和其他人.

以上书籍很好地解释了如何在Lisp中实现模式匹配.

Above books explain implementing pattern matching in Lisp very well.

存在图书馆,例如 trivia

Libraries exist, for example trivia, cl-match, and various others.

这篇关于如何在Common Lisp中进行模式匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆