Re: S-expressions
Aaron Optimizer Digulla <[email protected]> Wed, 6 Aug 2003 21:19:04 +0200
| Newsgroups | gmane.comp.programming.pragmatic |
|---|---|
| Message-ID | <[email protected]> |
On Wed, Aug 06, 2003 at 05:07:19PM -0000, Eric Merritt wrote:
> How many of you out there actually have a problem with s-expressions? For those
> of you that do not know s-expressions imply a lisp like syntax, ie
>
> (some-fun arg2 arg2)
>
> The reason I ask is becuase s-expressions make quite a bit of the langauge
> design easier. Macros become fairly simple, extensions integrate well etc. I tend
> to lean to this side of things. However, I am not the only one interested in this
> project.
>
> So an open question, do you have a dislike of s-expressions and if so why? This
> is a chance to make yourself heard.
I have never used s-expressions but I don't like the syntax.
For me, the first problem is: What is a function and what is an
argument?
The lisp/scheme syntax always looked very strange for me because of
the enormous amount of parens. I felt it always hard to match them
and to understand which arguments belonged together, etc.
Then, what exactly does this make easier? It might be easier to
parse (a (b (c (d (e f g h ))))) but so what? I don't care how complex
some code is to parse *as long as it is simple to read for a human*.
Who cares if the parser is complex? At most five persons in the whole
world will see this code. But millions of people will see the language.
Also a note about macros: When I do C, I need macros. The language
is just so limited in what it can do without.
When I do Java, I wished I had a preprocessor. And hey, Java 1.5 will
have something like that. Makes me wonder, why ;-)
When I do Python, I never missed macros.
Here are a few things which make macros almost unecessary:
- Modules and parts of it can be imported with a different name.
Example:
from Image import resize as scaleImage2
def scaleImage (...):
...do something smart...
return scaleImage2 (...)
or
import Image
def scaleImage (...):
...do something smart...
return Image.scaleImage (...)
This allows me to easily put code in the call chain without
having to use macros. I could also create another module
named "Image2" which imports "Image" but overwrites all
the functions that I don't like. Then I would replace
all "import Image" with "import Image2" and I would be fine.
- Python uses two data structures very extensively which
allow to solve most problems with very little code: Lists
and hashmaps (dictionaries).
dict = { 'a': aHandler, 'b': bHandler, }
Also, all attributes and methods of an objects can be
found in the special dictionary __dict__ to which you can
add at runtime. This, for example, allows to implement
"remote objects" without having to change any of the
classes which you want to access remotely.
- You can put functions and methods in variables.
This makes callbacks and many other things incredibly
simple.
Actually, when you want to extend an existing class,
you can do this:
class A:
...
def newMethod (self, ...):
# self is an instance of A
A.shinyNewMethod = newMethod
a = A()
a.shinyNewMethod ()
- Python allows variable argument list with the
syntax *args (args will be the list which contains the
additional arguments) and **keywords (keywords will
be a dictionary of all name=value pairs in the argument).
Example:
class HTMLImage:
def __init__ (self, src, alt='', border=0, **kw):
# src: neccessary parameter
# alt: If not given, then the empty string
# kw: anything else
self.src, self.alt, self.border = src, alt, border
self.extraAttributes = kw
img = HTMLImage ('demo.png', border=2, id='demo')
May I suggest that you have a very close look at Python? :-)
--
==============================================
Sowatec AG, CH-8330 Pfäffikon (ZH)
Witzbergstr. 7, http://www.sowatec.com
Tel: +41-(0)1-952 55 55
Fax: +41-(0)1-952 55 66
----------------------------------------------
Aaron "Optimizer" Digulla, [email protected]
==============================================
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/W4wwlB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
pragmatic_lang-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/