如何在 LISP 的函数中创建一个大小为参数的数组? [英] How to make an array with size received as arguments in a function in LISP?

查看:26
本文介绍了如何在 LISP 的函数中创建一个大小为参数的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个函数,该函数接收许多行和列并从中生成一个数组.这就是我所做的

I'm trying to create a function that receives a number of lines and columns and makes an array out of it. This is what I did

(defun create-table (lines columns)
     (make-array '(lines columns)))

我认为这就是制作多维数组的方式.但是当我调用函数 create-table 例如 (create-table 2 2) 这个错误被给出

I thought this is how you make a multidimensional array. But as I call the function create-table for example (create-table 2 2) this error is given

MAKE-ARRAY:维度 LINES 的类型不是 `(INTEGER 0(,ARRAY-DIMENSION-LIMIT))

MAKE-ARRAY: dimension LINES is not of type `(INTEGER 0 (,ARRAY-DIMENSION-LIMIT))

我不明白,怎么可能不是整数?我应该做演员吗?

I don't understand, how could it not be an integer? Should I make a cast?

推荐答案

您认为 '(lines columns) 的计算结果是什么?

What do you think '(lines columns) evaluates to?

提示:您可以使用 LIST 函数创建列表.

Hint: you can create lists with the function LIST.

这篇关于如何在 LISP 的函数中创建一个大小为参数的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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