Python syntax in Lisp and Scheme

Thomas F. Burdick tfb at famine.OCF.Berkeley.EDU
Thu Oct 9 14:19:58 EDT 2003


Andreas Rossberg <rossberg at ps.uni-sb.de> writes:

> Dirk Thierbach wrote:
> > 
> >>>you can use macros to do everything one could use HOFs for (if you
> >>>really want).
> > 
> > I should have added: As long as it should execute at compile time, of
> > course.
> > 
> >>Really? What about arbitrary recursion?
> > 
> > I don't see the problem. Maybe you have an example? I am sure the
> > Lisp'ers here can come up with a macro solution for it.
> 
> I'm not terribly familiar with the details of Lisp macros but since 
> recursion can easily lead to non-termination you certainly need tight 
> restrictions on recursion among macros in order to ensure termination of 
> macro substitution, don't you? Or at least some ad-hoc depth limitation.

I'm not terribly familiar with the details of Python's iteration constructs
but since iteration can easily lead to non-termination you certainly need tight
restrictions on ...

In some cases, recursive macros and functions are easier to get right
(avoid infinite recursion) than their iterative counterparts.
Careless coders will always find a way to code themselves into
infinite loops.  The easy way to avoid infinite recursion is:

  (cond
   ((===> base case <===) ...)
   ((===> another base case? <===) ...)
   ((...) recursive call)
   ((...) recursive call)
   ...
   (t recursive call))

Most of the time, it's easy to ensure that all recursive calls "move
up" the cond tree.  Times when you can't do that (or not easily), you
should be writing iterative code, or you're just doing something
inherently difficult.

> "Computer games don't affect kids; I mean if Pac Man affected us
>   as kids, we would all be running around in darkened rooms, munching
>   magic pills, and listening to repetitive electronic music."
>   - Kristian Wilson, Nintendo Inc.

(That's a great sig!)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               




More information about the Python-list mailing list