LISP - 破坏性和非破坏性构造 [英] LISP - destructive and non-destructive constructs

查看:156
本文介绍了LISP - 破坏性和非破坏性构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LISP(或通常)中的破坏性非破坏性结构的正确定义是什么。我试图寻找真正的含义,但是我没有真正解释它们,而是发现了很多这些术语的用法。



据我了解,通过破坏性函数是指一个函数,它改变了构造体(或变量)的含义 - 所以当我将一个列表作为参数传递给一个函数时,它会改变它,它被称为破坏性操作,因为它会更改初始列表并返回一个全新的列表。这是正确的还是有一些例外?



例如设置一个破坏性函数(因为它改变了x的值)?

 (set'x 1)

对不起,可能是一个非常基本的问题....感谢您的任何答案!

我不会对破坏性这个词进行太多解释。



在列表处理中,破坏性操作是其中一个可能会将一个或多个输入列表更改为可见副作用。

现在您可以扩展对数组,结构,CLOS对象等的操作的含义。你也可以调用变量赋值'破坏性'等。



在Common Lisp中,讲述序列的破坏性操作是有意义的(它是列表,字符串和向量一般而言)和多维数组。

What is the correct definition of destructive and non-destructive constructs in LISP (or in general). I have tried to search for the actual meaning but I have only found a lot of usage of these terms without actually explaining them.

It came to my understanding, that by destructive function is meant a function, that changes the meaning of the construct (or variable) - so when I pass a list as a parameter to a function, which changes it, it is called a destructive operation, because it changes the initial list and return a brand new one. Is this right or are there some exceptions?

So is for example set a destructive function (because it changes the value of x)? I think not but I do not how, how would I justify this.

(set 'x 1)

Sorry for probably a very basic question.... Thanks for any answers!

解决方案

I would not interpret too much into the word 'destructive'.

In list processing a destructive operation is one which potentially changes one or more of the input lists as a visible side effect.

Now you can widen the meaning to operations over arrays, structures, CLOS objects, etc. You can also call variable assignment 'destructive' and so on.

In Common Lisp it make sense to talk about destructive operations over sequences (which are lists, strings, and vectors in general) and multi-dimensional arrays.

这篇关于LISP - 破坏性和非破坏性构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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