Is Python really "Lisp without parentheses"? So would it be easy to*implement* a lot of Python in S

C

Chris Seberino

I've heard it said, by no less a guru than Peter Norvig, that Python is a lot like Lisp without the parentheses.... at least for the basics of Python.

For pedagogical reasons, I'm wondering if it would be easy to implement a big subset of Python in Scheme.

The basics of Scheme or Lisp are amazingly easy to implement. Would implementing a subset of Python in a Scheme subset be a clever way to easily implement a lot of Python?

(This isn't for practical reasons....I'm just curious.)

Chris
 
R

Rustom Mody

I've heard it said, by no less a guru than Peter Norvig, that Python is a lot like Lisp without the parentheses.... at least for the basics of Python.

For pedagogical reasons, I'm wondering if it would be easy to implement a big subset of Python in Scheme.

The basics of Scheme or Lisp are amazingly easy to implement.

Because parsing and unparsing (aka printing) are so trivial for s-expressions
Would implementing a subset of Python in a Scheme subset be a clever way
to easily implement a lot of Python?

At the innards of lisp and python are garbage collected data structures.
Building one with the other gets you that for free
[Doing it in a lower level language like C is what invokes the humorous:
Greenspuns tenth law]
So yes in that one respect what you say is true.
But then theres also (apart from parsing) all kinds of semantic differences eg:
- exceptions
- modules
- OOP milarky
- C interfacing in Baskin Robbins number of flavours
- carefully crafted portable veneer on top of intrinsically non portable OSes

All these have to be handled one way or other
(This isn't for practical reasons....I'm just curious.)

A crucial difference between python and lisp is that python is
practical and lisp is utopian
 
C

Chris Seberino

Exceptions, modules, OOP, etc. would be tricky to implement in Scheme but at least the basics like for loops, while loops, assignment etc. would seem doable and very instructive for students.....they would thereafter, for alltime, have a mental image of what the Python interpreter is doing.
 
C

Chris Seberino

A lecturer of mine back in university did this (implemented a subset

of Python in Racket). My understanding is that this is primarily

interesting to show that Racket is not as crazily different as it

looks from the syntax.

Is that on the web anywhere? That would be very interesting to look at. I'm sure others would find it useful too.
 
R

Roy Smith

Devin Jeanpierre said:
// C++
Foo x = y;
x.bar = 3;

// Java
Foo x = y;
x.bar = 3;

// Scheme
(define x y)
(foo-bar x 3)

The syntax of the first two is identical, so the uneducated would
assume they do the same thing.

This is one of the things that tripped me up when I first tried to learn
JavaScript. They syntax is superficially identical to C++, so I assumed
it worked the same way. Bad assumption.
 
R

Rustom Mody

Exceptions, modules, OOP, etc. would be tricky to implement in Scheme butat least the basics like for loops, while loops, assignment etc. would seem doable and very instructive for students.....they would thereafter, for all time, have a mental image of what the Python interpreter is doing.

If thats the intent, sure, scheme is heaven for such
In particular, take a language, break it up into a dozen or so
'little-languages' eg
one for types, one for control structures, one for scoping/parameter
passing etc while 'stubbing out' the rest -- for such scheme is simply
unbeatable.
And this includes IDEAS of oop modules etc.

Its only when you then start demanding: "Why cant this become
realistic?" that things start creaking and groaning at the edges

A simple example:
One of the much touted features of modern functional languages like
Haskell (actually its the SML family) is pattern matching. I
implemented a macro -- destruct -- to do it in scheme -- all of 91
lines!

Now one gets greedy and says: "Hey! Neat! Only small catch is that
haskell patterns looks so much neater than these home-cooked
Lots-of-Irritating-Single-Parenthesis (aka Lisp-y) patterns." And
Wham! The shit begins to hit the ceiling

To my mind, scheme is so powerful that even Abelson and Sussman dont
get how powerful. I wrote a blog post on that but then diluted the
title :D
http://blog.languager.org/2013/08/applying-si-on-sicp.html

On the whole though, functional languages are distinctly weaker than
lisps but much easier for students. Heres an old Wadler paper
explaining that:
http://www.cs.kent.ac.uk/people/staff/dat/miranda/wadler87.pdf
 
D

Devin Jeanpierre

Is that on the web anywhere? That would be very interesting to look at. I'm sure others would find it useful too.

As far as I know, no. There was an early version of it that was part
of a course, but as I understand it he did something much more
thorough later on. Even that course content seems to be offline and
not very available by archive.org; the relevant bits aren't archived:
https://web.archive.org/web/20111119221012/http://www.cs.toronto.edu/~gfb/csc324/2010F/content.shtml

Feel free to dig around and try to find something, but as I recall the
assignment on that page was to write some very minor interpreter
actions with a list generated from the AST of a python source file.
His later work was translating Python to Racket, with macros to
implement various Python operations. That wasn't an assignment or
course content, it was stuff he'd show to students during office hours
and such.


I believe the end goal was to turn it into a real tool for teaching
programming. The idea there was that Python is 90% irrelevant to
teaching students how to program, and the full generality of Python
makes it harder for students to learn due to weird behaviours or
unreasonable complexity. If you decide to only implement the 10% of
Python that you care to teach, then it's much easier to implement (in
fact, without that, the goal isn't even achievable for one person),
plus it serves your goals potentially better than Python does.

Regardless of if it's a particularly good idea, this is what Python
must look like if you try to elegantly directly translate it to Scheme
(or any lisp), just because the semantics will be so different once
you get out of the basics and the trivial things. If the translation
is to be clean, the input language can't actually be Python. If the
input language is Python, the output will be a horrible mess that
isn't useful for the student, and also it will take a lot of work
until it is even correct. Scheme is far simpler and smaller than
Python is.

-- Devin
 
C

Chris Seberino

Thanks.. I think your 10% Python idea is the way to go. And you are right
that most of Python is not needed in an intro course.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top