什么是计算机语言的表达? [英] What is Expresiveness in a Computer Language?

查看:119
本文介绍了什么是计算机语言的表达?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是计算机语言的表达


20050207,Xah Lee。


在人类或计算机语言中,有一个概念表达性。


英语例如,在表现形式上非常富有表现力,见证所有

诗歌和含义以及典故和内涵以及

dictions。有很多方法可以说一件事,模糊和温暖,以及所有的b $ b。但是,当我们看看它可以说什么,它的意义,或它的效率或精确度的表达能力,我们

发现自然语言无能为力。 />

这些可以通过几种方式看出来。一种可靠的方法是通过逻辑,

语言学,或者所谓的语言哲学。还可以通过

学习人工语言lojban直接收集自然语言的无能力和不足,其中一个人意识到,不仅仅是b $ b自然语言精确度不高,缺乏效率,

但是很多东西几乎不可能通过

来表达。


计算行业中常常被误解的一个问题是

表达性的概念。如果一种语言有一个词汇(微笑,笑,笑,

傻笑,轻笑,笑声,咯咯笑),那么这种语言将不会像

表达,只有语言(严重,轻微,笑,哭)。

前者是富有表现力的在细微差别方面,后者是

表达意义。


同样,在计算机语言中,表现力很重要

尊重语义,而不是语法变异。


通过Perl与Python

语言可以很容易地看出这两个截然不同的想法,并作为一个具体的例子他们的文本模式匹配

功能。


Perl是一种语法杂色的语言。 Python在另一方面

手,甚至不允许更改代码的缩进,但它的表达效率和表达能力相对于语义,

展示了Perl在规范中的贫困。

http://xahlee.org/perl-python/what_i...esiveness.html


??版权所有2005年Xah Lee。


Xah
xa*@xahlee.org

a ?? http://xahlee.org/

What is Expresiveness in a Computer Language

20050207, Xah Lee.

In languages human or computer, there''s a notion of expressiveness.

English for example, is very expressive in manifestation, witness all
the poetry and implications and allusions and connotations and
dictions. There are a myriad ways to say one thing, fuzzy and warm and
all. But when we look at what things it can say, its power of
expression with respect to meaning, or its efficiency or precision, we
find natural languages incapable.

These can be seen thru several means. A sure way is thru logic,
linguistics, and or what''s called Philosophy of Languages. One can also
glean directly the incapacity and inadequacy of natural languages by
studying the artificial language lojban, where one realizes, not only
are natural languages incapable in precision and lacking in efficiency,
but simply a huge number of things are near impossible to express thru
them.

One thing commonly misunderstood in computing industry is the notion of
expressiveness. If a language has a vocabulary of (smile, laugh, grin,
giggle, chuckle, guffaw, cackle), then that language will not be as
expressive, as a language with just (severe, slight, laugh, cry). The
former is "expressive" in terms of nuance, where the latter is
expressive with respect to meaning.

Similarly, in computer languages, expressiveness is significant with
respect to semantics, not syntactical variation.

These two contrasting ideas can be easily seen thru Perl versus Python
languages, and as one specific example of their text pattern matching
capabilities.

Perl is a language of syntactical variegations. Python on the other
hand, does not even allow changes in code''s indentation, but its
efficiency and power in expression, with respect to semantics,
showcases Perl''s poverty in specification.

http://xahlee.org/perl-python/what_i...esiveness.html

?? Copyright 2005 by Xah Lee.

Xah
xa*@xahlee.org
a?? http://xahlee.org/

推荐答案

你好,

我有一个新手问题,我写了以下距离函数:


def distance (self,element1,element2):

dist = 0

范围内的n(len(element1)):

dist = dist + pow((element1 [n] - element2 [n]),2)

打印''dist''+ dist

返回sqrt(dist)

并且为了能够使用len()和index element1 []函数

需要知道参数element1和element2都是listst或

不是吗?


我收到以下错误消息:


Traceback(最近一次调用最后一次):

文件" Memory.py",第105行,在?

start.inputVector(inP2)

文件" Memory.py",第97行,在inputVector中

allDimensions [0] .newAttribute(vector)

文件" Memory.py",第56行,in newAttribute

dist = self.distance(n.getCenter,newElement)

文件" Memory.py" ;,第75行,距离

范围内的n(len(element1)):

TypeError:未确定对象的len()


如果我拿出len,我会得到:


Traceback(最近一次调用最后一次):

文件Memory.py,行105,in?

start.inputVector(inP2)

文件" Memory.py",第97行,在inputVector中

allDimensions [0 ] .newAttribute(vector)

文件" Memory.py",第56行,in newAttribute

dist = self.distance(n.getCenter,newElement)

文件" Memory.py",第76行,距离

dist = dist + pow((element1 [n] - element2 [n]),2)

TypeError:unsubscriptable对象


非常感谢你的帮助。


Phil
Hello,
I got a newbie question, I have written the following distance function:

def distance(self,element1, element2):
dist = 0

for n in range(len(element1)):
dist = dist + pow((element1[n] - element2[n]),2)
print ''dist'' + dist
return sqrt(dist)
and in order to be able to use len() and index element1[] the function
needs to know that the arguments element1 and element2 are both listst or
doesn''t it ?

I get the following error msg:

Traceback (most recent call last):
File "Memory.py", line 105, in ?
start.inputVector(inP2)
File "Memory.py", line 97, in inputVector
allDimensions[0].newAttribute(vector)
File "Memory.py", line 56, in newAttribute
dist = self.distance(n.getCenter,newElement)
File "Memory.py", line 75, in distance
for n in range(len(element1)):
TypeError: len() of unsized object

AND if I take len out I get:

Traceback (most recent call last):
File "Memory.py", line 105, in ?
start.inputVector(inP2)
File "Memory.py", line 97, in inputVector
allDimensions[0].newAttribute(vector)
File "Memory.py", line 56, in newAttribute
dist = self.distance(n.getCenter,newElement)
File "Memory.py", line 76, in distance
dist = dist + pow((element1[n] - element2[n]),2)
TypeError: unsubscriptable object

Thank you very much for your help.

Phil


(你发布了你的问题作为后续跟进Xah Lee的沉思。

这不是最好的想法,因为有线程新闻阅读器的人

往往不会看到它。请稍后发布(创建一个新主题)。)


On Sun,2005年7月10日11:19:31 +0100(BST),Philipp H. Mohr< ph ** @ kent.ac.uk>写道:
(You posted your question as a followup to oen of Xah Lee''s musings.
That is not the best of ideas, since people with threaded newsreaders
tend not to see it. Just post (creating a new thread) next time.)

On Sun, 10 Jul 2005 11:19:31 +0100 (BST), Philipp H. Mohr <ph**@kent.ac.uk> wrote:
你好,
我有一个新手问题,我写了以下距离函数:

def distance(self,element1,element2):
dist = 0
对于范围内的n(len(element1)):
dist = dist + pow((element1 [n] - element2 [n]),2)
print''dist''+ dist
返回sqrt(dist)

并且为了能够使用len()和index element1 []这个函数需要
要知道参数element1和element2都是listst或
不是吗?


是的,还是支持len(x)和x [n]的其他东西。

我收到以下错误消息:
... .TypeError:未限定对象的len()
....如果我拿出len我得到:
.... TypeError:unsubscriptable object
Hello,
I got a newbie question, I have written the following distance function:

def distance(self,element1, element2):
dist = 0

for n in range(len(element1)):
dist = dist + pow((element1[n] - element2[n]),2)
print ''dist'' + dist
return sqrt(dist)

and in order to be able to use len() and index element1[] the function
needs to know that the arguments element1 and element2 are both listst or
doesn''t it ?
Yeah, or something else supporting len(x) and x[n].
I get the following error msg: .... TypeError: len() of unsized object .... AND if I take len out I get: .... TypeError: unsubscriptable object




嗯,这取决于参数的类型

你传递给方法,不是吗?打电话给


距离([1,1],[0,0])


对我来说很好。这是一个稍微简单的实现

,它避免了len(从而接受更广泛的参数类型)

和pow:


def distance(element1,element2):

dist = 0

为a,b为zip(element1,element2):

n = float (ab)

dist + = n * n

返回math.sqrt(dist)


(如果那是'不知道'' n维距离的正确公式。

我在过去的十年中忘记了太多的数学运算。)


/ Jorgen


-

// Jorgen Grahn< jgrahn @ Ph''nglui mglw''nafh Cthulhu

\ X / algonet.se> ; R''lyeh wgah''nagl fhtagn!



Well, that depends on the types of the arguments
you''re passing to the method, doesn''t it? A call like

distance([1,1], [0,0])

works fine for me. And here is a slightly simpler implementation
which avoids len (thus accepting a wider range of argument types)
and pow:

def distance(element1, element2):
dist=0
for a, b in zip(element1, element2):
n = float(a-b)
dist += n*n
return math.sqrt(dist)

(Dunno if that''s the correct formula for n-dimensional distance.
I have forgotten way too much math in the past ten years.)

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph''nglui mglw''nafh Cthulhu
\X/ algonet.se> R''lyeh wgah''nagl fhtagn!


" Philipp H. Mohr" < pH值** @ kent.ac.uk>写道:
"Philipp H. Mohr" <ph**@kent.ac.uk> wrote:
你好,
我有一个新手问题,我写了以下距离函数:

def distance(self,element1,element2 ):
dist = 0
对于范围内的n(len(element1)):
dist = dist + pow((element1 [n] - element2 [n]), 2)
打印''dist''+ dist
返回sqrt(dist)

并且为了能够使用len()和index element1 []函数
需要知道参数element1和element2都是listst或
不是吗?


不,它不是;它在运行时发现。另外,他们不必是
列表;任何定义__len__的对象都会这样做。

我收到以下错误消息:

Traceback(最近一次调用最后一次):
文件Memory.py ,第105行,在?
start.inputVector(inP2)
文件" Memory.py",第97行,在inputVector中
allDimensions [0] .newAttribute(vector)
文件Memory.py,第56行,in newAttribute
dist = self.distance(n.getCenter,newElement)
文件Memory.py,第75行,距离
对于范围内的n(len(element1)):
TypeError:未确定对象的len()


显然n.getCenter不是列表。

如果我拿出len,我会得到:

Traceback(最近一次调用最后一次):
文件Memory.py,第105行,在?
开始.inputVector(inP2)
文件" Memory.py",第97行,在inputVector中
allDimensions [0] .newAttribute(vector)
文件Memory.py,第56行,在newAttribute中
dist = self .distance(n.getCenter,newElement)
文件Memory.py,第76行,距离
dist = dist + pow((element1 [n] - element2 [n]),2)
TypeError:unsubscriptable对象


同样的问题; n.getCenter和/或newElement不是列表(或其他

可订阅对象)。只需在打电话之前打印它们

就可以说服自己。


顺便说一下,你不要在任何地方使用''self'',所以也许距离应该是一个函数,而不是方法。另外,写它的pythonic方式(因为

2.4)是:


来自math import sqrt

来自itertools import izip


def距离(sequence1,sequence2):

返回sqrt(和(xy)** 2表示x,y表示izip(sequence1,sequence2) ))

非常感谢你的帮助。

Phil
Hello,
I got a newbie question, I have written the following distance function:

def distance(self,element1, element2):
dist = 0

for n in range(len(element1)):
dist = dist + pow((element1[n] - element2[n]),2)
print ''dist'' + dist
return sqrt(dist)
and in order to be able to use len() and index element1[] the function
needs to know that the arguments element1 and element2 are both listst or
doesn''t it ?
No it doesn''t; it finds out at runtime. Also they don''t have to be
list; any object that defines __len__ will do.
I get the following error msg:

Traceback (most recent call last):
File "Memory.py", line 105, in ?
start.inputVector(inP2)
File "Memory.py", line 97, in inputVector
allDimensions[0].newAttribute(vector)
File "Memory.py", line 56, in newAttribute
dist = self.distance(n.getCenter,newElement)
File "Memory.py", line 75, in distance
for n in range(len(element1)):
TypeError: len() of unsized object
So obviously n.getCenter is not a list.
AND if I take len out I get:

Traceback (most recent call last):
File "Memory.py", line 105, in ?
start.inputVector(inP2)
File "Memory.py", line 97, in inputVector
allDimensions[0].newAttribute(vector)
File "Memory.py", line 56, in newAttribute
dist = self.distance(n.getCenter,newElement)
File "Memory.py", line 76, in distance
dist = dist + pow((element1[n] - element2[n]),2)
TypeError: unsubscriptable object
Same problem; n.getCenter and/or newElement are not lists (or other
subscriptable objects for that matter). Just print them before you call
distance to convince yourself.

By the way, you don''t use ''self'' anywhere, so perhaps distance should
be a function, not method. Also, the pythonic way of writing it (since
2.4) is:

from math import sqrt
from itertools import izip

def distance(sequence1, sequence2):
return sqrt(sum((x-y)**2 for x,y in izip(sequence1, sequence2)))
Thank you very much for your help.

Phil




问候,

乔治



Regards,
George


这篇关于什么是计算机语言的表达?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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