On Wed, 26 Mar 2008 19:45:34 +0100, Heiko Wundram wrote:

> Am Mittwoch, 26. März 2008 19:04:44 schrieb David Anderson:
>> HOw can we use express pointers as in C or python?
> 
> There's no such thing as a pointer in Python, so you can't "express"
> them either. Was this what you were trying to ask?

But if you really need then, you can fake them:


memory = [None]*10
# get a "pointer" to a memory location
ptr = 5
# and assign a function there
memory[ptr] = lambda s: '$' + s + '$'
assert memory[ptr]('hello') == '$hello$'
# store a pointer to a pointer
memory[3] = ptr
assert memory[memory[3]]('bye') == '$bye$'



In Python this is a silly trick, not worth doing because there are better 
ways to solve problems that other languages use pointers for. But in 
older languages like Fortran, before they gained pointers, this was a 
standard method for getting pointers into a language without pointers. 
Thank goodness those days are long-gone!



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to