我正在教自己Common Lisp.我一直在看康威生命游戏的一个例子,有一段我不懂的语法.
完整的代码可在此处获得.特别是我遇到麻烦的部分如下:
(defstruct (world (:constructor %make-world))
current
next)
(defun make-world (width height)
(flet ((make-plane (width height)
(make-array (list width height)
:element-type 'bit
:initial-element 0)))
(%make-world
:current (make-plane width height)
:next (make-plane width height))))
Run Code Online (Sandbox Code Playgroud)
我想知道,首先,%make-world中百分号的意义是什么?其次,为什么构造函数指定了两个不同的名称?(make-world和%make-world)我之前看过这个语法,但名字总是一样的.似乎有一些更深层次的功能,但它正在逃避我.
lisp syntax functional-programming common-lisp data-structures
我想根据 URL 参数中的数据使用 PDO 运行查询(是的,我知道这很容易受到攻击,但它是实用程序的内部代码)。
$user = 'USER';
$pass = 'PASSWORD';
$dsn = 'mysql:dbname=PRODUCTS;host=HOST';
try {
$productDB = new PDO($dsn, $user, $pass);
$productDB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
$msg = 'PDO ERROR' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage();
die($msg);
}
if(isset($_GET['cat']))
{
$cat = $_GET['cat'];
print "cat = $cat <br>";
$products = $productDB->prepare('SELECT * FROM products WHERE cat_id LIKE ?');
$products->execute(array($cat));
$rows = $products->rowCount();
print "$rows rows returned";
?>
<table border="1">
<tr>
<td>product_id</td> …Run Code Online (Sandbox Code Playgroud)