Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news-transit.tcx.org.uk!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'skip': 0.04; 'subject:Python': 0.05; 'compiler': 0.07; 'space.': 0.07; 'whichever': 0.07; '(it': 0.09; 'defined.': 0.09; 'inclined': 0.09; 'namespace': 0.09; 'used)': 0.09; 'am,': 0.12; 'bindings': 0.16; 'compiling,': 0.16; 'done),': 0.16; "function's": 0.16; 'jumps': 0.16; 'received:192.168.1.104': 0.16; 'sees': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'cc:addr:python-list': 0.16; 'syntax': 0.16; 'wrote:': 0.18; '(which': 0.19; 'cc:no real name:2**0': 0.20; '(or': 0.22; 'header:In-Reply-To:1': 0.22; 'changed': 0.23; 'cc:2**0': 0.24; 'compiled': 0.25; 'work,': 0.26; "i'm": 0.26; 'fact': 0.27; 'all,': 0.28; 'bit': 0.28; 'compile': 0.29; 'explicit': 0.29; 'toward': 0.29; 'cc:addr:python.org': 0.29; 'nov': 0.29; 'definition': 0.30; 'turned': 0.30; 'ansi': 0.30; 'conditional': 0.30; 'false.': 0.30; 'ran': 0.30; 'recursion': 0.30; 'syntax,': 0.30; 'chris': 0.30; 'tue,': 0.32; 'pretty': 0.32; "can't": 0.32; 'header:User-Agent:1': 0.33; 'actually': 0.33; 'it.': 0.34; 'visible': 0.34; 'languages': 0.35; 'something': 0.35; 'unless': 0.35; 'uses': 0.36; 'but': 0.37; 'received:192': 0.37; 'another': 0.37; 'could': 0.37; 'easiest': 0.38; 'steven': 0.38; 'some': 0.38; 'itself.': 0.39; 'word,': 0.39; 'either': 0.39; 'should': 0.39; 'being': 0.39; 'else': 0.39; 'called': 0.40; "it's": 0.40; 'might': 0.40; 'received:192.168': 0.40; '2011': 0.61; 'fall': 0.64; 'immediate': 0.65; 'memory,': 0.67; 'special': 0.68; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'forth': 0.77; 'compiles': 0.84; 'definition:': 0.84; 'recursion.': 0.84; 'subject:Reference': 0.84; 'officially': 0.95 Date: Tue, 29 Nov 2011 03:53:16 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15 MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: Using the Python Interpreter as a Reference References: <79379487-0081-4067-92ed-c6717652e1ff@y7g2000vbe.googlegroups.com> <4eb0af60-26b3-45d5-8aff-566505003d6a@m10g2000vbc.googlegroups.com> <4ed2cddc$0$29988$c3e8da3$5496439d@news.astraweb.com> <4ed40a2e$0$29988$c3e8da3$5496439d@news.astraweb.com> <861e1820-e70b-4f17-b668-53c4052974f5@w3g2000vbw.googlegroups.com> <4ed493d8$0$14018$c3e8da3$76491128@news.astraweb.com> In-Reply-To: <4ed493d8$0$14018$c3e8da3$76491128@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:tVM1sAyG38JjY8+QFmDnzl+C4R/BeqAyT+408uPn2LA a5lLf6++GG4tEcSyIKUtNPXlPtDQtRqKqzL3KT43acYPTqaIb7 ny1P1lrKCFDNG2e/d3zrS60fR5LW7bRgu35EzeEwufEv8YnP9W +aygVhbdrBk25DYWEFcueBdX1Flapt6B7xSDvA29V0Dd2ojVm2 6LPKtgpduMdDFv8fc3IeG0rv7hzTNJaU3UdSMA9zEn0cZwK6CU vqxTxz14yEvFxkYNtQmdYDriY2nZL/H410xkRafzLBChcG3ogC xjH9oAuthtvX3rdStDJdgDtHQzRThzxLQM/oppTI1dQA4iL+g= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: d@davea.name List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1322556828 news.xs4all.nl 6938 [2001:888:2000:d::a6]:46906 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:16383 On 11/29/2011 03:12 AM, Steven D'Aprano wrote: > On Tue, 29 Nov 2011 13:57:32 +1100, Chris Angelico wrote: > >> I'm inclined toward an alternative: explicit recursion. Either a >> different syntax, or a special-case on the use of the function's own >> name, but whichever syntax you use, it compiles in a "recurse" opcode. >> That way, if name bindings change, it's still going to recurse - >> something few languages guarantee, and therefore few languages can >> optimize. > As I recall, Forth uses (or used) a special RECURSE word which turned on > the recursion bit while compiling, so that the compiled word could see > itself. > > By memory, the (incomplete) definition: > > : fact dup 1- fact * ; > > would fail, unless you happened to already have another word called fact > existing at compilation time. To make it recurse correctly, the compiler > needs to make sure that the namespace fact sees includes itself: > > RECURSE : fact dup 1- fact * ; > > which should work, apart from the embarrassing fact that I don't recall > the syntax for conditional jumps and so the recursion never terminates. > > :) > The way I remember it, the current definition was "smudged" which made it invisible (it basically changed the name to something unlikely) during the compilation. After all, if you actually ran it at compile time (which was frequently done), you could fall right into uninitialized space. Anyway, some implementations had an immediate SMUDGE word, which toggled the smudge bit and made it visible again. Other implementations had an immediate word RECURSE, which compiled in whatever word was being currently defined. I'm pretty sure neither FIG nor Forth79 had either of these. But I don't recall the ANSI standard (X3J14 ?), even though I was officially an observer. I can't even remember what happened to my printed copy of the standard. The easiest word for conditional is IF/ELSE/THEN. IF will skip to the ELSE or THEN if the condition is false. So something resembling: : fact dup 1- dup 0<> if recurse * then ; might do it. That's very rough, however. It's been a long time. -- DaveA