473,791 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

references/addrresses in imperative languages

in coding Python yesterday, i was quite stung by the fact that lists
appened to another list goes by as some so-called "reference" . e.g.

t=range(5)
n=range(3)
n[0]='m'
t.append(n)
n[0]='h'
t.append(n)
print t
in the following code, after some 1 hour, finally i found the solution
of h[:]. (and that's cheating thru a google search)

def parti(l,j):
'''parti(l,j) returns l partitioned with j elements per group. If j
is not a factor of length of l, then the reminder elements are dropped.
Example: parti([1,2,3,4,5,6],2) returns [[1,2],[3,4],[5,6]]
Example: parti([1,2,3,4,5,6,7],3) returns [[1,2,3],[4,5,6]]'''
n=len(l)/j
r=[] # result list
h=range(j) # temp holder for sublist
for n1 in range(n):
for j1 in range(j):
h[j1]=l[n1*j+j1]
r.append( h[:] )
return r

interesting that a dictionary has copy method, but not list. (the pain
is coupled with the uselessness of the Python doc)

------
Btw, behavior such as this one, common in imperative languages and info
tech industry, is a criminality arose out of hacks C, Unix, and from
there all associated imperative langs. (C++, csh, perl, Java... but
each generation improves slightly)

The gist of the matter is that these behaviors being the way they are
really is because they are the easiest, most brainless implementation,
as oppose to being a design decision.

In hindsight analysis, such language behavior forces the programer to
fuse mathematical or algorithmic ideas with implementation details. A
easy way to see this, is to ask yourself: how come in mathematics
there's no such thing as "addresses/pointers/references".

---------

PS is there any difference between
t=t+[li]
t.append(li)

---------
References:

for a analysis of the same situation in Java, see
http://xahlee.org/java-a-day/assign_array_to_list.html

How to write a tutorial
http://xahlee.org/Periodic_dosage_di...ami_cukta.html

Xah
xa*@xahlee.org
∑ http://xahlee.org/

Nov 14 '05 #1
9 1335
In article <11************ *********@g49g2 000cwa.googlegr oups.com>,
"Xah Lee" <xa*@xahlee.org > wrote:
A[n] easy way to see this, is to ask yourself: how come in mathematics
there's no such thing as "addresses/pointers/references".


Yes there are such things in mathematics, though not necessarily under
that name.

For instance, in graph theory, edges can be considered as "pointers".
After all, make a change to a node, and that change is visible via all
edges pointing to that node.
Nov 14 '05 #2
In article <11************ *********@g49g2 000cwa.googlegr oups.com>,
Xah Lee <xa*@xahlee.org > wrote:
In hindsight analysis, such language behavior forces the programer to
fuse mathematical or algorithmic ideas with implementation details. A
easy way to see this, is to ask yourself: how come in mathematics
there's no such thing as "addresses/pointers/references".


There is. Each variable in predicate calculas is a reference.
No matter how large the formulae, a change in a variable
is, in mathematics, immediately propagated to all occurances
of the variable (potentially changing the references of other
variables).

If the predicate calculas variables were not equivilent to references,
then the use of the variable in a formula would have to be a
non-propogating copy. and a change to the original value whence not
be reflected in all parts of the formula and would not change
what the other variables referenced.

Consider for example the proof of Goedel's Incompleteness
theorem, which involves constructing a formula with a free
variable, and constructing the numeric encoding of that
formula, and then substituting the numeric encoding in as
the value of the free variable, thus ending up with
a number that is "talking about" iteelf. The process of
the proof is *definitely* one of "reference" to a value
in the earlier stages, with the formula being "evaluated"
at a later point -- very much like compiling a program
and then feeding the compiled program as input to itelf. You
cannot do it without a reference, because you need to
have the entire number available as data at the time
you start evaluating the mathematical formula.
--
Ceci, ce n'est pas une idée.
Nov 14 '05 #3
# easy way to see this, is to ask yourself: how come in mathematics
# there's no such thing as "addresses/pointers/references".

The whole point of Goedelisation was to add to name/value references into
number theory. Thus Goedel was able to add back pointers contrary to the
set hierarchy of the theory of types and reintroduce Russel's paradox.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
The little stoner's got a point.
Nov 14 '05 #4
Walter Roberson wrote:
In article <11************ *********@g49g2 000cwa.googlegr oups.com>,
Xah Lee <xa*@xahlee.org > wrote:
In hindsight analysis, such language behavior forces the programer to
fuse mathematical or algorithmic ideas with implementation details. A
easy way to see this, is to ask yourself: how come in mathematics
there's no such thing as "addresses/pointers/references".
There is. Each variable in predicate calculas is a reference.
No matter how large the formulae, a change in a variable
is, in mathematics, immediately propagated to all occurances
of the variable (potentially changing the references of other
variables).


Variables don't change in mathematics, at least the run-of-the-mill
everyday mathematics. :)
If the predicate calculas variables were not equivilent to references,
then the use of the variable in a formula would have to be a
non-propogating copy. and a change to the original value whence not
be reflected in all parts of the formula and would not change
what the other variables referenced.

Consider for example the proof of Goedel's Incompleteness
theorem, which involves constructing a formula with a free
variable, and constructing the numeric encoding of that
formula, and then substituting the numeric encoding in as
the value of the free variable, thus ending up with
a number that is "talking about" iteelf.
All these substitutions ``work'' in a way that is analogous to
functional programming. For example, substituting a variable into a
formula generates a new formula with occurences of that variable
replaced by the given value. You haven't destroyed the old formula.
The process of
the proof is *definitely* one of "reference" to a value
in the earlier stages, with the formula being "evaluated"
at a later point -- very much like compiling a program
and then feeding the compiled program as input to itelf.
Actually no. The process specifically avoids the pointer problem by
using an arithmetic coding for the formula, the Goedel numbering. The
formula talks about an encoded version of itself. That's how the
self-reference is smuggled in, via the Goedel numbering.
You
cannot do it without a reference, because you need to
have the entire number available as data at the time
you start evaluating the mathematical formula.


The final result just /is/ self-referential. It's not constructed bit
by bit like a data structure inside a digital computer that starts out
being non-self-referential and is then backpatched to point to itself.

A mathematical derivation may give you the idea that something is
changing in place, because you always hold the most recent version of
the formula at the forefront of your mind, and can visualize the whole
process as a kind of in-place animation in your head. But really, at
each step you are making something completely new which stands on its
own.

Nov 14 '05 #5
SM Ryan wrote:
# easy way to see this, is to ask yourself: how come in mathematics
# there's no such thing as "addresses/pointers/references".

The whole point of Goedelisation was to add to name/value references into
number theory.
Is that so? That implies that there is some table where you can
associate names (or whatever type of locators: call them pointers,
whatever) with arbitrary values. But in fact that's not the case.
Thus Goedel was able to add back pointers contrary to the
set hierarchy of the theory of types and reintroduce Russel's paradox.


Nope. Goedel didn't add anything, he just revealed what was already
there: that you can have statements of number theory, well-formed
formulas constructed out of existing operators without any backpointer
tricks, which have true interpretations , but are not theorems.

Everything in a Goedel's string can be recursively expanded to yield an
ordinary formula! There is no infinite regress, no unchased embedded
pointer-like things left behind.

Self-reference is achieved using two tricks: Goedel numbering, and
indirect reference. Godel numbering allows a formula to talk about
formulas, by way of embedding their Godel numbers, and translating
formula-manipulations into arithmetic manipulations (of interest are
finite ones that will nicely unfold into finite formulas). In essence
that which used to be ``code'' can be now treated as ``data''', and
operations on code (logical derivations) become arithmetic operations
on data.

Indirect reference is needed because a formula G's Goedel number cannot
be inserted into itself directly. If you start with a formula G which
has some free variable V, and then produce some new formula by
substituting G's Goedel number into it directly for occurences of V,
you no longer have G but that other formula. You want whatever comes
out to be G, and so the input formula, the one with the free variable,
cannot be G, but perhaps a close relative which either talks about G,
or whose constituent formulas cleverly end up talking about G after the
substitution takes place.

Instead of a direct (Goedel number) reference, you can insert into a
formula some /procedure/ for making that formula's Goedel number out of
another formula's Goedel number and talk about it that way. As an
example, instead of saying ``here is a number'' by inserting its
literal digits, you can say ``the number that results by applying this
formula to this other number''. For instance, instead of writing the
number 4 we can write successor(3). or 2 + 2. We explicitly
mention some other number, and say how 4 is constructed out of it.

Douglas Hofstadter exposition of all this is very good. To allow the
formula G to mention its own Goedel number, Douglas Hofstadter uses
another formula which he calls U, the ``uncle''. The trick is that: the
procedure for making G's Goedel number out of U's number is the
arithmetic equivalent of the same procedure that's used to substitute
the Goedel number of U for the free variable in U itself. So as U (the
formula) is treated by substituting its own Godel number for its one
and only free variable, it produces G, and, at the same time, the
arithmetic version of that substitution, fully contained inside the U
formula itself, turns the now substituted copy of U into G also. U
contains the fully expanded ``source code'' for the arithmetic version
of the free-variable substitution procedure, and it contains a free
variable representing the arithmetic version of the formula on which
that algorithm is to be done. As that free variable within U is
replaced by the Goedel number U, the overall formula becomes G, and the
embedded free-variable-replacement procedure is instantiated concretely
over U's Goedel number, so it becomes a constant, unparameterized
calculation that produces G's Goedel number.

Voila, G contains a procedure that computes the arithmetic object
(Goedel number) that represents G's ``source code'' (the symbolic
formula), out of the embedded number representing U's source code.
Using that giant formula, G can assert things about itself, like ``I am
not a theorem'' (i.e. ``there exists no integer representing the Goedel
numbers of a list of true statements that represent a derivation
deducing myself as the conclusion'').

There are no name references or pointers or anything. All the functions
are primitive recursive, and so can be expanded into finite-length
formulas which contain only numbers and operators and variables---dummy
ones that are bound to existential quantifiers, not to concrete values
some external name/value table.

Nov 14 '05 #6
Lawrence D’Oliveiro wrote:
In article <11************ *********@g49g2 000cwa.googlegr oups.com>,
"Xah Lee" <xa*@xahlee.org > wrote:
A[n] easy way to see this, is to ask yourself: how come in mathematics
there's no such thing as "addresses/pointers/references".


Yes there are such things in mathematics, though not necessarily under
that name.

For instance, in graph theory, edges can be considered as "pointers".
After all, make a change to a node, and that change is visible via all
edges pointing to that node.


Oh yeah, by the way, note how such destructive changes to a variable
become whole-environment derivations in the discipline of proving the
correctness of imperative programs.

E.g. say you have this assignment:

x <- x + 1

and you want to deduce what preconditions must exist in order for the
desired outcome x = 42 to be true after the execution of the
statement. What do you do? You pretend that the program is not
modifying a variable in place, but rather manufacturing a new
environment out of an old one. In the new environment, the variable X
has a value that is one greater than the corresponding variable in the
old environment. To distinguish the two variables, you call the one in
the old environment X' .

You can then transform the assignment by substituting X' for X in the
right hand side and it becomes

x <= x' + 1

and from that, the precondition x' = 41 is readily deduced from the
x = 42 postcondition.

Just to be able to sanely reason about the imperative program and its
destructive variable assignment, you had to nicely separate past and
future, rename the variables, and banish the in-place modification from
the model.

Nov 14 '05 #7
"Kaz Kylheku" <kk******@gmail .com> wrote:
# SM Ryan wrote:
# > # easy way to see this, is to ask yourself: how come in mathematics
# > # there's no such thing as "addresses/pointers/references".
# >
# > The whole point of Goedelisation was to add to name/value references into
# > number theory.
#
# Is that so? That implies that there is some table where you can
# associate names (or whatever type of locators: call them pointers,
# whatever) with arbitrary values. But in fact that's not the case.

Do you really believe the Goedel number of a statement is the statement
itself? Is everything named Kaz the same as you?

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?
Nov 14 '05 #8


SM Ryan wrote:
"Kaz Kylheku" <kk******@gmail .com> wrote:
# SM Ryan wrote:
# > # easy way to see this, is to ask yourself: how come in mathematics
# > # there's no such thing as "addresses/pointers/references".
# >
# > The whole point of Goedelisation was to add to name/value references into
# > number theory.
#
# Is that so? That implies that there is some table where you can
# associate names (or whatever type of locators: call them pointers,
# whatever) with arbitrary values. But in fact that's not the case.

Do you really believe the Goedel number of a statement is the statement
itself? Is everything named Kaz the same as you?


The Goedel number is a representation of the statement in a way that
the name Kaz isn't a representation of me. You cannot identify parts of
the name Kaz with parts of me; there is no isomorphism there at all. I
am not the translated image of the name Kaz, nor vice versa.

A Goedel number isn't anything like a name or pointer. It's an encoding
of the actual typographic ``source code'' of the expression. There is
nothing external to refer to other than the encoding scheme, which
isn't particular to any given Goedel number. The encoding scheme is
shallow, like a record player; it doesn't contribute a significant
amount of context. If I decode a Goedel number, I won't have the
impression that the formula was hidden in the numbering scheme, and the
Goedel number simply triggered it out like a pointer. No, it will be
clear that each piece of the resulting formula is the direct image of
some feature of the Goedel number.

Nov 14 '05 #9


SM Ryan wrote:
"Kaz Kylheku" <kk******@gmail .com> wrote:
# SM Ryan wrote:
# > # easy way to see this, is to ask yourself: how come in mathematics
# > # there's no such thing as "addresses/pointers/references".
# >
# > The whole point of Goedelisation was to add to name/value references into
# > number theory.
#
# Is that so? That implies that there is some table where you can
# associate names (or whatever type of locators: call them pointers,
# whatever) with arbitrary values. But in fact that's not the case.

Do you really believe the Goedel number of a statement is the statement
itself? Is everything named Kaz the same as you?


The Goedel number is a representation of the statement in a way that
the name Kaz isn't a representation of me. You cannot identify parts of
the name Kaz with parts of me; there is no isomorphism there at all. I
am not the translated image of the name Kaz, nor vice versa.

A Goedel number isn't anything like a name or pointer. It's an encoding
of the actual typographic ``source code'' of the expression. There is
nothing external to refer to other than the encoding scheme, which
isn't particular to any given Goedel number. The encoding scheme is
shallow, like a record player; it doesn't contribute a significant
amount of context. If I decode a Goedel number, I won't have the
impression that the formula was hidden in the numbering scheme, and the
Goedel number simply triggered it out like a pointer. No, it will be
clear that each piece of the resulting formula is the direct image of
some feature of the Goedel number.

Nov 14 '05 #10

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

Similar topics

17
3082
by: Tom | last post by:
The motivation for references seems clear: stop people from using nasty pointers when all they really want is a reference to an object. But C++ references are so inadequate that I'm still using pointers for my references to objects. There are 3 reasons why I find them inadequate: 1 - Can't be null. 2 - Can't be reseated. Now I'm sure there are good reasons for these first 2, but it's #3 that I
15
14040
by: Web Developer | last post by:
Hi, Can someone provide a short and concise statement(s) on the difference between pointers and references. A graphical representation (via links?) of both would be much appreciated as well. WD
2
1913
by: george r smith | last post by:
I understand that when you compare (using ==) objects you are seeing if they both refer to the same object. My question why or when would you ever use multiple references to the same object. What would be a production code type example why you would set objOne = objTwo. Thanks grs
3
1406
by: Joachim Folz | last post by:
Hello, I didn't find newsgroups for Python, Lisp, Eiffel, PHP, Cobol etc. on news.microsoft.com. So I want to ask the C#-newsgroup about the usage of other languages then C# and VB.NET. How popular are languages like Python, PHP, Perl, Lisp, Smalltalk, Prolog, Eiffel, Haskell, Mercury, APL, Cobol, Fortran, PL/1, RPG etc. amongst ..NET-developers?
2
2309
by: Brad | last post by:
I have one of those seemingly simple questions that evades/confuses me. I've created an assembly with bass classes (classes meant to be inherited in other assemblys). In a secondary assembly (my business layer) I created a class which inherits from a base class in the first assembly....so far so good. If I create a third assembly (my UI layer) and add reference in it to the business layer and I access a public variable in the business...
6
1759
by: cj | last post by:
I'm tryin to set up a sqlcommand in VB.NET that would issue the command: insert into server1.database.owner.table select * from server2.database.owner.table Since this sqlcommand has it's connection property set to a connection string for server1 I'm assuming it isn't seeing server2 -- I get invalid object name server2. How can I get one sql statement to reference multiple servers?
4
1630
by: Sebastian Fey | last post by:
Hi, i have to design a program written in an imperative language. I ve done the anaylysis part in UML, but how do i proceed? Core of the program is a data structure that looks like this: ----------- --------
9
2474
by: igor.kulkin | last post by:
References is a relatively basic feature of C++ language. It might be a good thing to think of references as aliases to the variables. However it's good to think of references this way when you deal with references which are local variables. But references can also be function arguments (in fact they are more useful this way) in which case it has to have the in-memory representation.
76
4720
by: valentin tihomirov | last post by:
As explained in "Using pointers vs. references" http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca , the pointers are allowed to be null, while references must refer an existing variable of required type. The null is normally used for making optional parameters. But there is no way to pass null reference in C#. Something is missing.
0
9997
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
9030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
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();...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
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.