Strong/weak typing

2008-08-01 Thread MartinRinehart
I'm writing Python as if it were strongly typed, never recycling a name to hold a type other than the original type. Is this good software engineering practice, or am I missing something Pythonic? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python conventions

2008-04-10 Thread MartinRinehart
Daniel Fetchinson wrote: > I'm sorry to disappoint you but this project has already been completed: > > http://www.python.org/dev/peps/pep-0008/ Daniel, PEP 8 is anything but complete. How much of the following simple question can you answer from there: Given that you can name things with Upper

Python conventions

2008-04-10 Thread MartinRinehart
I assembled a good conventions set for Java. View it at http://www.martinrinehart.com/articles/code-conventions.html (is that better, Steve?) It followed a logical organization; it was built from four other extensive (if not well-organized) convention sets and it scrupulously avoided injecting my

Re: import statement convention

2008-04-09 Thread MartinRinehart
Thanks, all. Good to know no one's been beheaded. Yes to separating test and non-test code, but no if that will just turn one modest module into two modules, smaller still. Amen to 'practicality beats purity.' Do wish we had a good, thorough convention set. I wrote one for Java. It took a lot o

import statement convention

2008-04-08 Thread MartinRinehart
By convention, I've read, your module begins with its import statements. Is this always sensible? I put imports that are needed for testing in the test code at the end of the module. If only a bit of the module has a visual interface, why pollute the global namespace with 'from Tkinter import *'?

Re: Tkinter menus made easy

2008-03-27 Thread MartinRinehart
[EMAIL PROTECTED] wrote: > menudef = """ > File > New,callNew,Ctrl-N > New Window, callNewWindow, Ctrl-Shift-N > __ > Open, lambda e=0:para(1), Ctrl-O Nice design. I looked at it for a few seconds and didn't even think about pressing F1. Mine does

Re: Tkinter menus made easy

2008-03-27 Thread MartinRinehart
Guilherme Polo wrote: > there is a > gui designer tool for tkinter called GUI Designer (what a bad name), > which used to be called SpecTcl, where you can design the menus and it > then converts to python code. I tried it. after about 10 minutes I was as far as "help not found." Is anyone out t

Tkinter Text widget

2008-03-27 Thread MartinRinehart
Is there a way of translating from the Text widget's width/height (in characters) to pixels so you can open an appropriately sized window? -- http://mail.python.org/mailman/listinfo/python-list

Tkinter menus made easy

2008-03-27 Thread MartinRinehart
Writing Tkinter menu code used to be rather tedious, uninspiring work. I figured that I could delegate the job to a program: http://www.martinrinehart.com/articles/menus.py Run it. Then look at the source (bottom of file). There's a bit more doc in the doc comment at the top. Peer review is most

Re: Tkinter menus from keyboard

2008-03-26 Thread MartinRinehart
Eric Brunel wrote: > BTW, this "standard" is not universal at all: e.g, there is no such > convention on Macs. Thanks for the info. It's standard on Windows and Linux/KDE. GNOME, anyone? -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter menus from keyboard

2008-03-26 Thread MartinRinehart
Guilherme Polo wrote: > Set the underline option to the index of the desired letter Elegant simplicity in the dropdowns. Thanks! Now, how about main menu underscores? -- http://mail.python.org/mailman/listinfo/python-list

Tkinter menus from keyboard

2008-03-26 Thread MartinRinehart
Tkinter defaults to, for example, Alt+f = File (if File is your first menu name starting with "f"). I'd like to assign my own letters and have them underscored, per the universal standard. Can this be done? -- http://mail.python.org/mailman/listinfo/python-list

lists v. tuples

2008-03-17 Thread MartinRinehart
What are the considerations in choosing between: return [a, b, c] and return (a, b, c) # or return a, b, c Why is the immutable form the default? -- http://mail.python.org/mailman/listinfo/python-list

What's Going On?

2008-03-13 Thread MartinRinehart
(Accompanied by Marvin Gaye) >>> def f(list=[0]): ...list[0]+=1 ...return list[0] ... >>> f() 1 >>> f() 2 >>> f() # 'list' is a name bound to a list (mutable) so this makes sense 3 >>> f([5]) 6 >>>f() # What's Going On? 4 Off topic: Motown chief Berry Gordy tells Gaye he won't release the

Re: Better grammar.txt

2008-03-07 Thread MartinRinehart
Jeroen Ruigrok van der Werven wrote: > >http://www.martinrinehart.com/articles/python-grammar.html: > >Unknown host www.martinrinehart.com > > Works for me. Very interesting. The link I posted works for me, while the links quoted are 404 errors, though they look identical. This really is a super

Re: Better grammar.txt

2008-03-05 Thread MartinRinehart
[EMAIL PROTECTED] wrote: > It includes three corrections to grammar.txt (imagnumber, xor_expr and > and_expr) that I've reported. Make that four corrections. Add augop. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why """, not '''?

2008-03-05 Thread MartinRinehart
D'Arcy J.M. Cain wrote: > Where did you see that? The only place I saw it was the style guide > and it was only talking about docstrings. PEP 8 and 257, and you're right, they are both about docstrings. Also, I'd never seen an example of the triple apostrophe form until I dove into the formal

Why """, not '''?

2008-03-05 Thread MartinRinehart
Why is """ the preferred delimiter for multi-line strings? -- http://mail.python.org/mailman/listinfo/python-list

Better grammar.txt

2008-03-05 Thread MartinRinehart
I previously posted a link to an improved, HTML-based, hyperlinked grammar.txt. Discard that one. This one is much better. http://www.martinrinehart.com/articles/python-grammar.html If you find it useful, thank Gabriel Genellina for encouraging me to get it really right. It includes three correc

Re: Python's BNF

2008-03-02 Thread MartinRinehart
Gabriel Genellina wrote: > About the generated page: I think it would be more useful if each symbol > links to its definition, instead of showing an alert(). This way it's > easier to navigate the tree, specially with complex declarations. That was my first shot. It didn't work. (Every line is it

Re: Python's BNF

2008-02-29 Thread MartinRinehart
Paul McGuire wrote: < plus sundry other parts of the kitchen > sink) that was passed BY PROJECT CODING STANDARDS to EVERY FUNCTION IN > EVERY MODULE! Supposedly, this was done to cure access problems to a > global data structure. Beautiful example of how totally stupid actions can be taken in t

Re: Python's BNF

2008-02-29 Thread MartinRinehart
Steve Holden wrote: > I wish you'd stop trying to defend this code and simply admit that it's > just a throwaway program to which no real significance should be > attached. *Then* I'll leave you alone ;-) You're hurting my program's feelings! Actually, I intend to keep this program as the nice H

Re: Python's BNF

2008-02-29 Thread MartinRinehart
Gabriel and Steve, Poor globals! They take such a beating and they really don't deserve it. The use of globals was deprecated, if memory serves, during the structured design craze. Using globals is now considered bad practice, but it's considered bad practice for reasons that don't stand close sc

Re: Python's BNF

2008-02-28 Thread MartinRinehart
Implemented all your suggestions, with two exceptions. Changed file read to readlines(), but not open(...).readlines(). I love to say file.close(). Gives me a feeling of security. (We could discuss RAM waste v. I/O speed but this input file is just 10KB, so neither matters.) Removed one of the th

Re: Python's BNF

2008-02-28 Thread MartinRinehart
Thanks so much Gabriel. -- http://mail.python.org/mailman/listinfo/python-list

Python's BNF

2008-02-27 Thread MartinRinehart
I spent too long Googling for Python's BNF. Eventually found it at Python.org, but only by accident. I've put Python's BNF here: http://www.martinrinehart.com/articles/python-parse-bnf.html Extensively cross-referenced. Addenda: No, Google, I didn't want the Botswana daily news with its articl

Array of functions, Pythonically

2008-02-25 Thread MartinRinehart
My parser has found an expression of the form CONSTANT_INTEGER OPERATOR CONSTANT_INTEGER. I want to fold this into a single CONSTANT_INTEGER. The OPERATOR token has an intValue attribute, '+' == 0, '-'== 1, etc. In C I'd put functions Add, Subtract, ... into an array and call ArithmeticFunctions[

Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-24 Thread MartinRinehart
re encryption I ran a small software company in the '80s. We did the unthinkable: shipped our software with a money-back guarantee. Anyone could buy the software, copy it and then request a full refund. Return rate: 0.5%. Of the returns we guessed that about half of them were for perfectly legit

Re: Tkinter: Missing the last piece of the puzzle

2008-02-24 Thread MartinRinehart
Simon Forman wrote: > yes! check out http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/464635 > > HTH, > ~Simon Thanks, Simon. Looks like that will do it. Actually, it looks like that will overdo it. I'll be setting File/Save to enabled after every keystroke. Ideally, I'd like to set my s

Tkinter: Missing the last piece of the puzzle

2008-02-23 Thread MartinRinehart
I have a simple editor built into my visual parser. It has a File menu with typical New, Open, Save, Save As ... options. I now know how to set the options [en/dis]abled and how to check the Text widget's modified flag. Now I want to [en/dis]able those options. Can I ask the text to notify me when

Re: Tkinter Menu Item Activation

2008-02-22 Thread MartinRinehart
Rob Wolfe wrote: > But I think that you should read this: > http://effbot.org/zone/vroom.htm Rob, may the gods shower you with gold coins! -- http://mail.python.org/mailman/listinfo/python-list

Tkinter Menu Item Activation

2008-02-22 Thread MartinRinehart
Tkinter definitely deserves more respect! I'm making rapid progress and it looks good. But am stuck on this: I want the File/Save state to change from disabled to enabled, depending on whether or not there is something to save (Text modified). Google returns results in every language except Python

Re: Globals or objects?

2008-02-22 Thread MartinRinehart
A fascinating, well-informed discussion. Thanks to all. Holden's suggestion re coupling and cohesion was most informative. I conclude that whether you use an object or a global (within a module, not across modules) is an implementation detail that has no impact on either cohesion or coupling. D'A

Globals or objects?

2008-02-21 Thread MartinRinehart
I had a global variable holding a count. One source Google found suggested that I wouldn't need the global if I used an object. So I created a Singleton class that now holds the former global as an instance attribute. Bye, bye, global. But later I thought about it. I cannot see a single advantage

Re: Linux/Python Issues

2008-02-21 Thread MartinRinehart
re being serious I am serious. I am seriously trying to develop a nice language for beginners. I was at Dartmouth in 1965 when BASIC was new. It let me use the computer without learning Fortran. It was very successful. I think it's past time for another one. I think we could have a lot more capabi

Re: Python Memory Manager

2008-02-20 Thread MartinRinehart
Paul Rubin wrote: > repz movsw is a pretty lame way to copy data on current x86's. > Use XMM instead. Thank you, Paul. I'm pretty sure you meant MMX, Multi-Media eXtensions. Paul's just told me to upgrade my 32-bit thinking to use newer 64-bit registers, even on a 32-bit cpu. Please divide my p

Re: Python Memory Manager

2008-02-20 Thread MartinRinehart
Steve Holden wrote: > You have a strange idea of "nearly free" ... > > Extending an integer array from 100 to 150 items is a pretty puny > operation when you compare it with the amount of data that might need to > be moved during a compactifying garbage collection of a 20MB Python > program image

Re: Python Memory Manager

2008-02-20 Thread MartinRinehart
Jeff Schwab wrote: > What's "the Intel architecture?" Do you mean the x86_64 architecture > that was actually developed by AMD, or x86 for x > some number, or do > you actually mean IA64? I mean chips of the family that goes back to the 8086 and 8088 chips, chips that support the REPZ prefix to

Re: Linux/Python Issues

2008-02-18 Thread MartinRinehart
Paul Boddie wrote: > The whole CNR stuff and the > proprietary software slant of Linspire obscures the solution, in my > opinion. Thanks for all your help, Paul. CNR, which is now free, is absolutely marvelous when it's got what you need. If Python2.5 were in the warehouse, I'd have clicked, go

Re: Python Memory Manager

2008-02-18 Thread MartinRinehart
Paul Rubin wrote: > The problem here is with a high allocation rate, you have to GC a lot > more often, which typically involves copying live data. This is last century's issue. Copying data, RAM to RAM, is nearly free using the Intel architecture. This short article, http://www.martinrinehart.

Re: Linux/Python Issues

2008-02-18 Thread MartinRinehart
Paul Boddie wrote: > Here's one page which probably tells you stuff you already know: > > http://wiki.python.org/moin/BeginnersGuide/Download Thank you! It says I need Python (which I've got) and the Python-devel package, which sounds like it might include Tkinter and IDLE. Now if only I knew wh

Re: Linux/Python Issues

2008-02-18 Thread MartinRinehart
[EMAIL PROTECTED] wrote: > IOW: all this is assumed to be > common *n*x knowledge. Both GNOME and KDE put Windows to shame. An old Windows guy, like me, can just start using either one without needing 'common *n*x knowledge.' Too bad the *n*x community isn't more welcoming to outsiders. Linspire

Re: Tkinter Confusion

2008-02-18 Thread MartinRinehart
Many thanks to all. -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter = Rodney Dangerfield?

2008-02-18 Thread MartinRinehart
Gabriel Genellina wrote: > I don't like Tk because the widgets are ugly, old-fashioned, and don't > have the right "look and feel". Take another look. A year or so back Tkinter went to platform native widgets. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Memory Manager

2008-02-17 Thread MartinRinehart
I researched this for some Java I wrote. Try to avoid shuffling physical memory - you'll write a lot less code and it will be faster, too. Use an "allocated" list and an "available" list. Keep them in address order. Inserting (moving list elements from insertion point to end) and deleting (vice-ve

Linux/Python Issues

2008-02-17 Thread MartinRinehart
I went to Python.org, DL'd Python 2.5 source code per the usual inadequate instructions and ran the make files successfully (sort of). Python 2.5 works fine. But "from Tkinter import *" gets a "What's Tkinter?" message. IDLE's no where to be found. What's not in the instructions is what directory

Tkinter Confusion

2008-02-17 Thread MartinRinehart
Everything I've read about Tkinter says you create your window and then call its mainloop() method. But that's not really true. This is enough to launch a default window from the console: >>>from Tkinter import * >>>foo = Tk() Google's great, but it has no truth meter. Do I inherit from Frame? Or

Tkinter = Rodney Dangerfield?

2008-02-17 Thread MartinRinehart
Tkinter gets no respect. But IDLE's a Tkinter-based app and every example I've Googled up shows Tkinter as needing about half as much code as wx to do the same job. I'm beginning to Tkinter up my language application. Am I making a big mistake? -- http://mail.python.org/mailman/listinfo/python-lis

Re: Operator overloading

2008-01-25 Thread MartinRinehart
Hexamorph wrote: > You mean you want the ability to change for example the + operator > for ints to something like calculating the cosine instead of doing > addition? Sure. Cosines are a monadic operation and the monadic '+' is a NOP, so why shouldn't I define +45 to return cosine of 45, (presum

Re: Operator overloading

2008-01-25 Thread MartinRinehart
Diez B. Roggisch wrote: > No, there is no way. You would change general interpreter behavior if > you could set arbitrary operators for predefined types. > > Start grumping... Thank you, Diez. If I ever design a language, please remind me that complete, easy, well-documented access to the worki

Operator overloading

2008-01-25 Thread MartinRinehart
If it were my choice, the plus sign would do this: def itemadd( i1, i2 ): if ( type(i1) == str ) or ( type(i2) == str ): return str(i1) + str(i2) else: return i1 + i2 I'd like to redefine it so it works my way but operator overloading seems strictly confined to classes I c

Newbie wants to get visual

2008-01-11 Thread MartinRinehart
I'm ready to start coding the parser for my Decaf (beginners) language. I think that a "visual" parser (one that shows what it's doing as it does it) would be nice. (And I think that it would help the parser author by saving the requirement for a bazillion print statements while debugging the tool.

Re: Python's great, in a word

2008-01-09 Thread MartinRinehart
Thanks to all for many helpful suggestions. Python, by the way, is verbose when compared to APL. (See http://catpad.net/michael/apl/ if you don't believe this.) You need to stick in an adverb (maybe "gracefully concise") as standalone "concise" is owned by APL. Basilisk96 wrote: > Did programmers

Re: I'm searching for Python style guidelines

2008-01-09 Thread MartinRinehart
Matthew Woodcraft wrote: > I think [the olpc guidlines are] mostly PEP 8, with some notes added. Took a good look. You are absolutely correct. PEP 8 is basically word processing text stuck between and tags. OLPC is Wiki HTML. Good example of how the latter is a lot bigger than the former, wit

Re: I'm searching for Python style guidelines

2008-01-08 Thread MartinRinehart
That's a great list, grflanagan! Thanks. I looked at each and copied to my disk either as a .txt (cut/paste from the browser) for a page or less or as .html (view source, chop off head and non-guideline stuff, save). This is the list plus PEP 8 minus the software. (No disrespect for the software,

Re: I'm searching for Python style guidelines

2008-01-07 Thread MartinRinehart
Guilherme Polo wrote: > foo = [ > 'too long', > 'too long too', > ... > ] OK, I'll put it there too, and it will be easy for us to read each other's code (at least in this particular). -- http://mail.python.org/mailman/listinfo/python-list

Re: I'm searching for Python style guidelines

2008-01-07 Thread MartinRinehart
Thank you both. Stupid me, went to Python.org and found Style Guidelines and thought that was the last word. Oh well. PEP 8 reminds me a lot of Sun's Java conventions, in ways I wish it didn't. The overall structure seems like a random list of topics and it omits a lot. For Java I went from Sun t

code doesn't reference immutables?

2008-01-07 Thread MartinRinehart
>From the manual: "code objects are immutable and contain no references (directly or indirectly) to mutable objects" (3.2) I thought my code worked with both mutable and immutable objects. Whassup? -- http://mail.python.org/mailman/listinfo/python-list

I'm searching for Python style guidelines

2008-01-07 Thread MartinRinehart
There's a lot of dumb stuff out there. "Algorithms should be coded efficiently ..." Thanks, I'll keep that in mind. van Rossum's guidelines tend toward "pick something and stick to it" which is OK if you have enough experience to pick something Pythonic. I'm a relative newbie, not qualified to pic

Python's great, in a word

2008-01-07 Thread MartinRinehart
I'm a Java guy who's been doing Python for a month now and I'm convinced that 1) a multi-paradigm language is inherently better than a mono-paradigm language 2) Python writes like a talented figure skater skates. Would you Python old-timers try to agree on a word or two that completes: The best

Re: Basic inheritance question

2008-01-05 Thread MartinRinehart
Jeroen Ruigrok van der Werven wrote: > Shouldn't this be: > > self.startLoc = start > self.stopLoc = stop Thanks! Of course it should. Old Java habits die slowly. -- http://mail.python.org/mailman/listinfo/python-list

Basic inheritance question

2008-01-05 Thread MartinRinehart
Working on parser for my language, I see that all classes (Token, Production, Statement, ...) have one thing in common. They all maintain start and stop positions in the source text. So it seems logical to have them all inherit from a base class that defines those, but this doesn't work: import to

Re: Fortran to Python

2008-01-05 Thread MartinRinehart
Jeroen Ruigrok van der Werven wrote: > I got someone who asked me to make changes in an old Fortran program she is > using for some calculations. Why convert? Modern Fortran is an object oriented, structured language with the singular advantage that it can run old Fortran programs. -- http://ma

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: Is this a bug in int()?

2007-12-22 Thread MartinRinehart
Tokenizer accepts "0x" as zero. Spec says its an error not to have at least one hex digit after "0x". This is a more serious bug than I had originally thought. Consider this: Joe types "security_code = 0x" and then goes off to the Guardian-of- the-Codes to get the appropriate hex string. Returnin

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: How to in Python

2007-12-22 Thread MartinRinehart
Chris Mellon wrote: > You don't seem to be implementing the > lexer in Python I am absolutely implementing my language in Python, a language I have now been writing for two entire weeks. This list has been more than helpful, tolerating numerous newbie questions. -- http://mail.python.org/mailma

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-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

How to handle multi-line quotes

2007-12-21 Thread MartinRinehart
Thinking about unclosed multi-line quotes. When you open a multi-line quote (type '"""') what does your editor do? Does it color the remainder of your text as a quote, or does it color the line with the open quote as a quote and leave the rest of your code alone? What do you want it to do? This

Re: How to in Python

2007-12-21 Thread MartinRinehart
Chris Mellon wrote: > Is there some reason that you think Python is incapable of > implementing lexers that do this, just because Python lexer accepts > it? Absolutely not. My opinion is that it's a bug. A very, very minor bug, but still six-legged. > Note that if you're using your lexer to mar

Re: How to in Python

2007-12-21 Thread MartinRinehart
If I get to add multi-line strings today, I'll have a complete tokenizer. Interior looks a lot like C minus semi-colons. (Though I did figure out that there wasn't any need for tokens that didn't come from a real to have a doubleValue field. In C++ or Java all the Tokens had a doubleValue, because

Re: How to in Python

2007-12-21 Thread MartinRinehart
Gabriel Genellina wrote: > Do you have to validate input based on that grammar? I've built a standalone tokenizer. It returns an array of Token objects. These include tokens such as UNCLOSED_QUOTE and MALFORMED_NUMBER ('1E' not followed by sign or digit, for instance). You could use this in a c

Re: How to in Python

2007-12-21 Thread MartinRinehart
John Machin wrote: > Use a proper lexer written by somebody who knows what they are doing, > as has already been recommended to you. My lexer returns a MALFORMED_NUMBER token on '0x' or '0x '. Try that in Python. -- http://mail.python.org/mailman/listinfo/python-list

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: Is this a bug in int()?

2007-12-21 Thread MartinRinehart
Tokenizer bug reported. [EMAIL PROTECTED] wrote: > >>>int('0x', 16) > 0 > > I'm working on a tokenizer and I'm thinking about returning a > MALFORMED_NUMBER token (1.2E, .5E+) -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this a bug in int()?

2007-12-21 Thread MartinRinehart
Duncan Booth wrote: > Why would you return a token rather than throwing an exception? Tokenizers have lots of uses. Colorizing text in an editor, for example. We've got a MALFORMED_NUMBER when you type '0x'. We've got an INTEGER when we get your next keystroke (probably). -- http://mail.python.

Is this a bug in int()?

2007-12-20 Thread MartinRinehart
>>>int('0x', 16) 0 I'm working on a tokenizer and I'm thinking about returning a MALFORMED_NUMBER token (1.2E, .5E+) -- http://mail.python.org/mailman/listinfo/python-list

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

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

How to in Python

2007-12-19 Thread MartinRinehart
I've got a pointer to a position in a line of code that contains either a digit or a period (decimal point). I've got this comment: Numbers are one of these: integers: digit+ 0xhex_digit+ decimals:

Re: Another newbie design question

2007-12-19 Thread MartinRinehart
This morning block comments disappeared from the Decaf design. Maybe later today they'll be instantiated in the tokenizer. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie observations

2007-12-19 Thread MartinRinehart
> My 2 cents. Eurozone? That would be 3 cents US. I meant colon, not semi-colon. I did the tutorial. I did objects 3 times. In Java, the agreed convention is to use lowerAndUpper naming for member variables. (See http://www.MartinRinehart.com/articles/code-conventions.html#5_1 .) 10 days is n

Re: Another newbie design question

2007-12-18 Thread MartinRinehart
> My 2 cents... Thanks for the feedback, Bruno. Seriously thinking about ditching the block comments and adding multi-line strings. (Block comments are the last item on my tokenizer's "todo" list. Multi-line strings would be easier.) Beginners will be programming fun things in a GUI environment.

Newbie observations

2007-12-18 Thread MartinRinehart
Warning! Complaints coming. The good news is that 10-days of part-time Python coding has convinced me that I picked the right language. Now, observations. First, it is absolutely horrible being a newbie. I'd forgot how bad it was. In addition to making a fool of yourself in public, you have to lo

Re: Another newbie design question

2007-12-18 Thread MartinRinehart
Sion Arrowsmith wrote: > Given a one-or-the-other choice, any editor worth using can do > "comment/uncomment region", and if only to-EOL comments are > available, it will do that for you instead of using block > comments. So block comments are not really a useful language > feature. I'd expect the

Re: Another newbie design question

2007-12-18 Thread MartinRinehart
Fortran (1957) had line comments. C (1972) replaced these with non- nested block comments. C++ (1983) added here-to-EOL comments. Python (1991) keeps here-to-EOL comments but replaces block comments with multi-line quotes. Block comments and multi-line quotes both serve the same purpose as doc comm

Another newbie design question

2007-12-17 Thread MartinRinehart
I've designed a language, Decaf, for beginners. I've got block comments but not multi-line strings. If you can only have one or the other, which is more helpful? Should I have both? (Make a strong argument here: my design principal is, "Designed by a backpacker: when in doubt, leave it out.") --

Re: Newbie design problem

2007-12-14 Thread MartinRinehart
Bruno Desthuilliers wrote: > Then the first move is to carefully eval existing solutions: > http://wiki.python.org/moin/LanguageParsing Always good advice, Bruno. How did you come by that list address? Google or is there something special known to Python experts? -- http://mail.python.org/mailm

Re: Newbie design problem

2007-12-14 Thread MartinRinehart
Jonathan Garnder said: > Well, if using something like PLY ( http://www.dabeaz.com/ply/ ) is > considered more Pythonic than writing your own parser and lexer... Lex is very crude. I've found that it takes about half a day to organize your token definitions and another half day to write a tokeniz

Re: Newbie design problem

2007-12-14 Thread MartinRinehart
Most unclear. My apologies. I'm trying to structure a tokenizer. The stupid concatenations are just placeholders for the actual tokenizing work. By rebuilding the input they demonstrate that the framework correctly processes all the input. I'm currently using a C-style design (my own pointers int

Newbie design problem

2007-12-13 Thread MartinRinehart
Thanks to a lot of help, I've got the outer framework for my tokenizer down to this: for line_number, line in enumerate(text): output = '' for char_number, char in enumerate(line): output += char print 'At ' + str(line_number) + ', '+ str(char_number) + ':

Re: Newbie NameError problem

2007-12-12 Thread MartinRinehart
Thanks to all! I will put my class defs first (tho not without expressing my disappointment that this is required in a late 20th century language); learn about enumerate as it looks like exactly what I need and discard my C++/Java based object model because this is a totally other thing. If someo

Newbie NameError problem

2007-12-12 Thread MartinRinehart
I don't understand what I don't understand in the following: -- # reader.py - testing char-by-char marching methods f = open('sample_decaf.d', 'r') text = f.readlines() f.close() # this is C-style, 15 lines, in Python: end_line = len(text) line_ptr = 0 whi

Re: Block comments

2007-12-11 Thread MartinRinehart
Bruno Desthuilliers wrote: > Is the array of lines the appropriate data structure here ? I've done tokenizers both as an array of lines and as a long string. The former has seemed easier when the language treats EOL as a statement separator. re not letting literal strings in code terminate bloc

Re: Dumb newbie back in shell

2007-12-11 Thread MartinRinehart
re top posting Thanks for explaining. google groups hides the quoted text, so I didn't see it. Bruno Desthuilliers wrote: > [EMAIL PROTECTED] a �crit : > > Martin, would you _please_ learn to quote properly ? top-posting and > keeping the whole text of the previous posts are two really annoying

Block comments

2007-12-11 Thread MartinRinehart
Tomorrow is block comment day. I want them to nest. I think the reason that they don't routinely nest is that it's a lot of trouble to code. Two questions: 1) Given a start and end location (line position and char index) in an array of lines of text, how do you Pythonly extract the whole block com

Re: Dumb newbie back in shell

2007-12-11 Thread MartinRinehart
got them accessed from within a function w/o > error message. > > I am confused. > > Martin > > Peter Otten wrote: > > MartinRinehart wrote: > > > > > However, here's the little tester I wrote: > > > > > > # t.py - testing > > &g

  1   2   >