[wplug] first language

Matthew Danish mdanish at andrew.cmu.edu
Tue Apr 1 15:30:44 EST 2003


On Tue, Apr 01, 2003 at 03:06:19PM -0500, bgtrio at yahoo.com wrote:
> Languages enforce some sort of standards, but they use different syntactic 
> elements to do it.  Lisp uses Lots of Irritating, Silly Parentheses, C 
> uses brackets, Python uses whitespace.  Other languages ignore whitespace 
> to allow people to pick their own indentation style.

Both Lisp and C ignore [extra] whitespace.

> But why do you use an indentation style?  To hint at the meaning of the 
> text, the same way writers use whitespace to indicate various things, like 
> paragraph beginnings and quoted selections.  Python just guarantees that 
> anyone can understand these hints since they're a part of the language and 
> therefore standardized.

Except that using whitespace to structure code isn't very fine-grained.

Interestingly enough, there is a parser called Sugar[1] which can
structure code via parenthesis or via whitespace.  It looks like (it was
designed for Scheme):

define
 fac x
 if
  = x 0
  1
  * x
    fac
     - x 1

Personally, I think

(define (fac x)
  (if (= x 0)
     1
     (* x (fac (- x 1)))))

Is far more readable, but I'm not a python-language programmer (just a
python hacker, sorta [2] ;).  Scheme normally ignores [extra] whitespace
as well.

The difference between this and

# hope I have the syntax right
def fac(x):
  if x = 0:
    return 1
  else:
    return (x * fac (x - 1))

Is that the Scheme expression can be easily converted into a Scheme list
with structure at every level which prints back out very similar to the
original code, but the Python needs to be parsed into a very different
looking abstract syntax tree which is a pain in the ass to deal with.


[1] http://redhog.org/Projects/Programming/Current/Sugar/index.html
[2] But no one will understand that here :-(  Not even CMU people...

-- 
; Matthew Danish <mdanish at andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."



More information about the wplug mailing list