Re: Passing by reference

2007-12-23 Thread Marc 'BlackJack' Rintsch
On Sun, 23 Dec 2007 03:10:48 -0800, MartinRinehart wrote: > Bruno, right now I've got this: > > def __init__ ( self, t ): > """ Constructor, called with array of strings. """ > > self.text = t > ... > > Some other program will say: > tok = Toker( text_array ) > tokens = tok.tokenize

Re: Passing by reference

2007-12-23 Thread MartinRinehart
Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a �crit : > > > > Bruno Desthuilliers wrote: > > > >>... that's definitively not > >>something I'd store in global. > > > > > > So where would you put it? > > You don't have to "put" functions arguments anywhere - they're already > local vars. Brun

Re: Passing by reference

2007-12-23 Thread MartinRinehart
Dennis Lee Bieber wrote: > Great if one is using a teletype as editor The original Dartmouth computer room was a basement that featured 8 teletypes. The original BASIC, Dennis, was implemented on a time-shared "mainframe" with a gigantic 8k words (20-bit words, if I remember) of core memory. D

Re: Passing by reference

2007-12-22 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > > Bruno Desthuilliers wrote: > >>... that's definitively not >>something I'd store in global. > > > So where would you put it? You don't have to "put" functions arguments anywhere - they're already local vars. def tokenize(text): do some work returns or (

Re: Passing by reference

2007-12-22 Thread MartinRinehart
Steven D'Aprano wrote: > Context is all gone, so I'm not sure that I remember what "it" is. I > think it is the text that you're parsing. Yes. I'm tokenizing today. Parsing comes after Christmas. > TEXT = "placeholder" > > def parse(): > while True: > token = get_next_token() # look

Re: Passing by reference

2007-12-22 Thread Steven D'Aprano
On Sat, 22 Dec 2007 04:13:31 -0800, MartinRinehart wrote: > Bruno Desthuilliers wrote: >> ... that's definitively not >> something I'd store in global. > > So where would you put it? Context is all gone, so I'm not sure that I remember what "it" is. I think it is the text that you're parsing.

Re: Passing by reference

2007-12-22 Thread MartinRinehart
Bruno Desthuilliers wrote: > ... that's definitively not > something I'd store in global. So where would you put it? -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing by reference

2007-12-22 Thread MartinRinehart
Hendrik van Rooyen wrote: > I wonder if you have some COBOL data divisions under your belt? Hendrik, I go way back but somehow I missed COBOL. Martin -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing by reference

2007-12-22 Thread Hendrik van Rooyen
MartinRinehart Wrote: > More seriously, I can and do use lots of globals. In the tokenizer I'm > writing, for example, all the token types(COMMENT_EOL = 0, > CONSTANT_INTEGER = 1, ...) are global constants. The text to be > tokenized is a global variable. (Actually, the text is unchanging once >

Re: Passing by reference

2007-12-21 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hi, Bruno. Merry Christmas! > By "constant" I meant that it did not change during the lifetime of > the Toker. That's still a variable to me. It's even the essence of the variable, since it's the main input of your program. And that's definitively not something I

Re: Passing by reference

2007-12-21 Thread MartinRinehart
Hi, Bruno. Merry Christmas! By "constant" I meant that it did not change during the lifetime of the Toker. -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing by reference

2007-12-21 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > > Sion Arrowsmith wrote: >> Michael Sparks <[EMAIL PROTECTED]> wrote: >>> def bar(): >>>global x >>>x[0] += " another" >>>print id(x[0]) >> ... and for bonus marks, explain why the "global x" in this function >> is not required. > > Because x does not ap

Re: Passing by reference

2007-12-21 Thread MartinRinehart
Sion Arrowsmith wrote: > Michael Sparks <[EMAIL PROTECTED]> wrote: > >def bar(): > >global x > >x[0] += " another" > >print id(x[0]) > > ... and for bonus marks, explain why the "global x" in this function > is not required. Because x does not appear as an LHS in bar(), just about t

Re: Passing by reference

2007-12-21 Thread Sion Arrowsmith
Michael Sparks <[EMAIL PROTECTED]> wrote: >def bar(): >global x >x[0] += " another" >print id(x[0]) ... and for bonus marks, explain why the "global x" in this function is not required. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ "Frankly I have no feelings towar

Re: Passing by reference

2007-12-20 Thread Aahz
In article <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]> wrote: > >Is the following correct? Sort-of, but I would say that it's misleadingly correct. Try this: http://starship.python.net/crew/mwh/hacks/objectthink.html -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "T

Re: Passing by reference

2007-12-20 Thread Terry Reedy
7;reference', as you seem to have. Others get confused by that viewpoint. It depend on exactly what one means by 'reference'. | foo(x) | | Reference is passed to function. The first parameter name of foo gets bound to the object referred to by 'x'. Calling that 'pa

Re: Passing by reference

2007-12-20 Thread Michael Sparks
[EMAIL PROTECTED] wrote: > ... the first element of the list to which x refers is a reference to > the new string and back outside foo, the first element of the list to > which x refers will be a reference to the new string. I'd rephrase that as: * Both the global context and the inside of foo

Re: Passing by reference

2007-12-20 Thread MartinRinehart
... the first element of the list to which x refers is a reference to the new string and back outside foo, the first element of the list to which x refers will be a reference to the new string. Right? -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing by reference

2007-12-20 Thread John Machin
On Dec 21, 5:57 am, [EMAIL PROTECTED] wrote: > Is the following correct? > > x = "some string" > > x is a reference to "some string" > > foo(x) > > Reference is passed to function. > > In foo: > x += " change" > > Strings are immutable, so x in foo() now points to a different string > than x ou

Re: Passing by reference

2007-12-20 Thread Ben Finney
[EMAIL PROTECTED] writes: > Is the following correct? > > [lots of references to "references"] All good so far. > x[0] += " other" > > Another string is created, the first element of x is modified to point > to the new string and back outside foo(), x[0] will point to the new > string. Change

Passing by reference

2007-12-20 Thread MartinRinehart
Is the following correct? x = "some string" x is a reference to "some string" foo(x) Reference is passed to function. In foo: x += " change" Strings are immutable, so x in foo() now points to a different string than x outside foo(). Right? Back outside foo. x = ["some string"] x is a r

Re: Embedding Python - Passing by Reference

2007-11-29 Thread andy
Thanks for the replies - I see that I completely misunderstood "passing by reference" when discussing Python. It looks like wrapping the object up in a list will be the path I go down as it remains closer to the C API I am wrapping. Thanks again! Andy -- http://mail.python.org/mailma

Re: Embedding Python - Passing by Reference

2007-11-29 Thread Neil Cerutti
On 2007-11-29, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I understand the parameters to Python functions are passed by > reference: > > def foo(a): > a = a + 1 > > Will change the value of a in the calling function. How do I > implement the equivalent in C when extending Python? You've got

Re: Embedding Python - Passing by Reference

2007-11-29 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |I understand the parameters to Python functions are passed by reference: Nope. Python's name-object model is so far different from the named memory block model of Fortran/C/etc that terms invented for the latter are misleading when

Re: Embedding Python - Passing by Reference

2007-11-29 Thread Jean-Paul Calderone
On Thu, 29 Nov 2007 14:39:52 -0800 (PST), [EMAIL PROTECTED] wrote: >I understand the parameters to Python functions are passed by >reference: > >def foo(a): > a = a + 1 > >Will change the value of a in the calling function. How do I implement >the equivalent in C when extending Python? You misund

Embedding Python - Passing by Reference

2007-11-29 Thread andy
I understand the parameters to Python functions are passed by reference: def foo(a): a = a + 1 Will change the value of a in the calling function. How do I implement the equivalent in C when extending Python? I know how to write a function that can be called from Python and I know how to use P

Re: C API: passing by reference

2007-06-23 Thread [EMAIL PROTECTED]
Thanks for that clarification Martin. When I googled it before, the first page I read said "Python passes all arguments using 'pass by reference'." However, after seeing your reply and further searching I see that this is not true. I have a python function insertEdge which takes to 2-tuples of (fa

Re: C API: passing by reference

2007-06-23 Thread Carsten Haese
On Sat, 2007-06-23 at 18:25 +, [EMAIL PROTECTED] wrote: > I'm writing my own python extension module with the C API. In python > all functions pass arguments by reference, "Pass by reference", while correct from a certain standpoint, is to be taken with a large grain of salt. It is correct in

Re: C API: passing by reference

2007-06-23 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb: > I'm writing my own python extension module with the C API. In python > all functions pass arguments by reference Can you please show an example what you mean by that? There is no "pass-by-reference" in Python: a function can not normally modify the variable in the call

C API: passing by reference

2007-06-23 Thread [EMAIL PROTECTED]
I'm writing my own python extension module with the C API. In python all functions pass arguments by reference, but how can I make use of this in C? Right now, I am using: PyArg_ParseTuple(args, "(ii)(ii)", &faceId1, &vertId1, &faceId2, &vertId2) I want the to change the faceId's in my function.