473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 1305
In article <11*********************@g49g2000cwa.googlegroups. 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*********************@g49g2000cwa.googlegroups. 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*********************@g49g2000cwa.googlegroups. 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*********************@g49g2000cwa.googlegroups. 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
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...
15
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. ...
2
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...
3
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...
2
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...
6
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...
4
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
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...
76
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.