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
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Is the following correct? | | x = "some string" | | x is a reference to "some string" x is a name bound to a string object with value 'some string'. Some people find is useful to call that a 'reference', as you seem to have. Others ge

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