473,695 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is Expresiveness in a Computer Language?

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
http://xahlee.org/

Jul 21 '05 #1
24 2596
Hello,
I got a newbie question, I have written the following distance function:

def distance(self,e lement1, element2):
dist = 0

for n in range(len(eleme nt1)):
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.inputVect or(inP2)
File "Memory.py" , line 97, in inputVector
allDimensions[0].newAttribute(v ector)
File "Memory.py" , line 56, in newAttribute
dist = self.distance(n .getCenter,newE lement)
File "Memory.py" , line 75, in distance
for n in range(len(eleme nt1)):
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.inputVect or(inP2)
File "Memory.py" , line 97, in inputVector
allDimensions[0].newAttribute(v ector)
File "Memory.py" , line 56, in newAttribute
dist = self.distance(n .getCenter,newE lement)
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
Jul 21 '05 #2
(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.u k> wrote:
Hello,
I got a newbie question, I have written the following distance function:

def distance(self,e lement1, element2):
dist = 0

for n in range(len(eleme nt1)):
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


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(elemen t1, 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!
Jul 21 '05 #3
"Philipp H. Mohr" <ph**@kent.ac.u k> wrote:
Hello,
I got a newbie question, I have written the following distance function:

def distance(self,e lement1, element2):
dist = 0

for n in range(len(eleme nt1)):
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.inputVect or(inP2)
File "Memory.py" , line 97, in inputVector
allDimensions[0].newAttribute(v ector)
File "Memory.py" , line 56, in newAttribute
dist = self.distance(n .getCenter,newE lement)
File "Memory.py" , line 75, in distance
for n in range(len(eleme nt1)):
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.inputVect or(inP2)
File "Memory.py" , line 97, in inputVector
allDimensions[0].newAttribute(v ector)
File "Memory.py" , line 56, in newAttribute
dist = self.distance(n .getCenter,newE lement)
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(sequen ce1, sequence2):
return sqrt(sum((x-y)**2 for x,y in izip(sequence1, sequence2)))
Thank you very much for your help.

Phil


Regards,
George

Jul 21 '05 #4
I think u are wrong.. I think perl is much more exrpressive in
semantics than Python..

Jul 21 '05 #5
On Sun, 10 Jul 2005 07:20:34 -0700, raptor wrote:
I think u are wrong.. I think perl is much more exrpressive in
semantics than Python..


Well, with such great command of natural language as you are displaying,
how could anyone argue with your conclusion?

--
Steven.

Jul 21 '05 #6
On Sun, 10 Jul 2005 11:19:31 +0100, Philipp H. Mohr wrote:
Hello,
I got a newbie question, I have written the following distance function:
Great. Now, how about you tell us what you expect it to do? I assume
it calculates the Euclidean distance between two points. (If you
don't know what Euclidean distance is, don't worry about it -- it is
basically just the "normal" distance.)

Should it calculate the distance between points on a line? 2-D points on
a plane? 3-D points in space? Higher dimensions?

I'm going to assume you want your function to operate on any number of
dimensions.
def distance(self,e lement1, element2):
You don't need "self" unless it is a method of a class.
dist = 0
for n in range(len(eleme nt1)):
dist = dist + pow((element1[n] - element2[n]),2)
print 'dist' + dist
Why are you printing the SQUARE of the distance?
return sqrt(dist)
Okay, here is a simpler method, complete with comments:

def distance(point1 , point2):
"""Return the distance between two points in N-dimensional space.

Example: if the points are (a,b) and (c,d) respectively, returns the
Euclidean distance d = sqrt( (c-a)**2 + (d-b)**2 )

Both points should have the same number of coordinates, each of which
is a float or int. Points can be given as lists or tuples.
"""
sum_sq = 0 # sum of squares of the differences
if len(point1) != len(point2):
# check for errors here because they might not be picked
# up later if we don't
raise ValueError("Poi nts have different number of dimensions")
for i in range(len(point 1)):
x, y = point1[i], point2[i] # extract the next two ordinates
sum_sq = sum_sq + (y-x)**2 # and add the square of the difference
return sum_sq**0.5

If you really care about accuracy, you should use the sqrt function from
the math module rather than **0.5.

Here is another version, using zip.

def distance(point1 , point2):
if len(point1) != len(point2):
raise ValueError("Poi nts have different number of dimensions")
L = zip(point1, point2)
sum_sq = 0
for x,y in L:
sum_sq = sum_sq + (y-x)**2
return sum_sq**0.5

And finally, a one-liner using list comprehensions and no error-checking.

def distance(point1 , point2):
return sum([(y-x)**2 for x,y in zip(point1, point2)])**0.5
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. Lots of things can be passed to len() and indexed.
I get the following error msg:

Traceback (most recent call last):
File "Memory.py" , line 105, in ?
start.inputVect or(inP2)
File "Memory.py" , line 97, in inputVector
allDimensions[0].newAttribute(v ector)
File "Memory.py" , line 56, in newAttribute
dist = self.distance(n .getCenter,newE lement)
File "Memory.py" , line 75, in distance
for n in range(len(eleme nt1)):
TypeError: len() of unsized object
And what is element1 when you get that error message? That's the first
thing I would look at.
AND if I take len out I get:
Traceback (most recent call last):
File "Memory.py" , line 105, in ?
start.inputVect or(inP2)
File "Memory.py" , line 97, in inputVector
allDimensions[0].newAttribute(v ector)
File "Memory.py" , line 56, in newAttribute
dist = self.distance(n .getCenter,newE lement)
File "Memory.py" , line 76, in distance
dist = dist + pow((element1[n] - element2[n]),2)
TypeError: unsubscriptable object


Firstly, you seem to have a lot of modules there. What happens when you
call distance directly? Can you get it to work then?

Secondly, what are the values for element1 and element2?
--
Steven.

Jul 21 '05 #7
Is getCenter a function? If so, you need to invoke distance using:
dist = self.distance( n.getCenter(), newElement )

Of course, that is assuming that newElement is a local variable of type
list/tuple/etc.

-- Paul

Jul 21 '05 #8
Hello,

thank you very much for all your help. I have solved the problem - you
guys where right, the problem was some where else.

I have another class which got an accessor:

def getCenter(self) :
global center
return center
and I called it by saying n.getCenter, but this returns:

<bound method ARBgps.getCente r of <__main__.ARBgp s instance at
0xb7c368ec>>

I changed it to n.getCenter() and now it works. Despite some small
problems I am really getting to like python.

Thank you,
Phil
On Sun, 10 Jul 2005, Paul McGuire wrote:
Is getCenter a function? If so, you need to invoke distance using:
dist = self.distance( n.getCenter(), newElement )

Of course, that is assuming that newElement is a local variable of type
list/tuple/etc.

-- Paul

Jul 21 '05 #9
On 10 Jul 2005 02:57:04 -0700, "Xah Lee" <xa*@xahlee.org > wrote:
Similarly, in computer languages, expressiveness is significant with
respect to semantics, not syntactical variation.

It may just be me, but I tend to think of a computer language as a
tool for directing computers to perform specific actions. Do we talk
about the expressiveness of a spade?

There's a similar concept in the 'possible uses' of a tool (a spade is
an excellent tool for digging the garden, but you wouldn't use it to
clean your teeth; you *could* use a toothbrush to dig the garden, but
you wouldn't if a spade was available). Similarly with computer
languages - some are better for certain tasks than others, but I don't
think 'expressiveness ' is the way to describe that.

Pete Barrett
Jul 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
19032
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
699
33919
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
226
12577
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d1 = {'a':1} >>> d2 = {'b':2} >>> d3 = {'c':3}
5
2366
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code (intermediate language and so on). Is there any page on internet, which makes me clear? Thanx
121
10072
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
15
1317
by: Xah Lee | last post by:
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
41
3423
by: Mountain Bikn' Guy | last post by:
What is the current preferred way to save user preferences in dotnet? Is the registry the right place to do this? Can anyone recommend a good article (or book) for this topic? Thanks.
23
3626
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a so-called pre-fix notation or algebraic notation. Algebraic notations have the concept of operators, meaning, symbols placed around arguments. In algebraic in-fix notation, different
669
25912
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
0
8623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9113
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8977
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5837
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2997
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.