Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
sweet-expressions instead of s-expressions?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 69 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Neil Toronto  
View profile  
(2 users)  More options Sep 23 2006, 2:49 pm
Newsgroups: comp.lang.lisp
From: "Neil Toronto" <neil.toro...@gmail.com>
Date: 23 Sep 2006 11:49:17 -0700
Local: Sat, Sep 23 2006 2:49 pm
Subject: sweet-expressions instead of s-expressions?
Quick background from the newb: Programmer for 22 years with assembly
and standard C-like imperatives, just recently became proficient in
Python and becoming interested in Common Lisp. Why? I want the
functional goodness and the MACROS, that's why. Also, I do computer
vision and machine learning research, and my Python code is rather
slow. I'd like something that's almost as fast as C but very
expressive, and is strict but highly dynamic and dynamically-typed.

Here's what's keeping me with Python: my code reads like pseudocode,
and I love that. When I come back to Python code I haven't seen in
months, it takes me all of five seconds to grok it again.

So has anyone seen this?

http://www.dwheeler.com/readable/readable-s-expressions.html

Short version: significant whitespace (indentation can replace parens),
"func(param1 param2)" calls, infix notation (which is good for math
code), and it still parses regular s-expressions correctly. Because it
transforms "sweet-expressions" to s-expressions, macros still work.
Example:

defun factorial (n)
   if (n <= 1)
       1
       n * factorial(n - 1)

(which even I can parse :D) is translated to:

(defun factorial (n)
   (if (<= n 1)
       1
       (* n (factorial (- n 1)))))

(which I can still parse, but with more trouble). Or this:

(2 + mystuff(7 + x) * -(henry) - correction(a b c d) + 2 - pi() - x)

which is translated to this:

(- (+ (- (+ 2 (* (mystuff (+ 7 x)) (- henry)))
         (correction a b c d)) 2) (pi) x)

He's almost got me convinced.

I understand that experienced Lispers use indentation to understand
code more than parenthesis anyway. This creates a situation (rather
like in C-like languages) where the language syntax *doesn't inherently
communicate with the coder very well*, and coder has to add redundant
formatting to make it clear. Then, like in IDEs for C-like languages,
the editors support this to make programming less painful. So why not
take the Python route and make formatting syntactically significant?
The only difference is that Python requires it, "sweet-expressions"
don't.

My main question is whether there are any downsides at all to this
approach.

And as an aside, I'd love to have Python's array (list) and dictionary
(hash table) syntax. I'd switch to Lisp and convert my entire codebase
TODAY if I had that.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
vsed...@gmail.com  
View profile  
(2 users)  More options Sep 23 2006, 3:38 pm
Newsgroups: comp.lang.lisp
From: vsed...@gmail.com
Date: 23 Sep 2006 12:38:37 -0700
Local: Sat, Sep 23 2006 3:38 pm
Subject: Re: sweet-expressions instead of s-expressions?
Take a look at Dylan:

http://www.opendylan.org/

Vladimir


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Tilton  
View profile  
(4 users)  More options Sep 23 2006, 4:37 pm
Newsgroups: comp.lang.lisp
From: Ken Tilton <kentil...@gmail.com>
Date: Sat, 23 Sep 2006 16:37:16 -0400
Local: Sat, Sep 23 2006 4:37 pm
Subject: Re: sweet-expressions instead of s-expressions?

Neil Toronto wrote:
> Quick background from the newb:

Lousy spelling.  Should be "fom the t-r-o-l-l".

hth, kenny

--
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Costanza  
View profile  
(1 user)  More options Sep 23 2006, 4:42 pm
Newsgroups: comp.lang.lisp
From: Pascal Costanza <p...@p-cos.net>
Date: Sat, 23 Sep 2006 22:42:04 +0200
Local: Sat, Sep 23 2006 4:42 pm
Subject: Re: sweet-expressions instead of s-expressions?

Neil Toronto wrote:
> Quick background from the newb: Programmer for 22 years with assembly
> and standard C-like imperatives, just recently became proficient in
> Python and becoming interested in Common Lisp. Why? I want the
> functional goodness and the MACROS, that's why. Also, I do computer
> vision and machine learning research, and my Python code is rather
> slow. I'd like something that's almost as fast as C but very
> expressive, and is strict but highly dynamic and dynamically-typed.

> Here's what's keeping me with Python: my code reads like pseudocode,
> and I love that. When I come back to Python code I haven't seen in
> months, it takes me all of five seconds to grok it again.

How long have you been learning Common Lisp?

I am asking this because it typically takes a week or two (or sometimes
a few more) until you get used to Lisp syntax. Afterwards, with more
experience, it's typically not an issue anymore. (Although it could
simply be that those for whom this is then still an issue switch to
other languages.)

[...]

> My main question is whether there are any downsides at all to this
> approach.

I don't think so. Adding a surface syntax to Lisp shouldn't be that much
of a problem, as long as the internal representation stays the same. It
could indeed be interesting if there were several different surface
syntaxes, for example including graphical ones, which would move Lisp
towards something like intentional programming.

On the other hand, I also think that adding one ore more surface
syntaxes doesn't solve a fundamental problem, and I don't expect that a
considerably large number of Lispers will take up this idea because of
that. After all, it's _just_ syntax. In other words, there aren't any
downsides, but there also aren't any essential upsides.

Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Neil Toronto  
View profile  
(3 users)  More options Sep 23 2006, 6:19 pm
Newsgroups: comp.lang.lisp
From: "Neil Toronto" <neil.toro...@gmail.com>
Date: 23 Sep 2006 15:19:57 -0700
Local: Sat, Sep 23 2006 6:19 pm
Subject: Re: sweet-expressions instead of s-expressions?

Ken Tilton wrote:
> Neil Toronto wrote:
> > Quick background from the newb:

> Lousy spelling.  Should be "fom the t-r-o-l-l".

> hth, kenny

Ah, I see. So not only is the syntax hostile, but so is the community.
Fascinating! I wonder if this is as well-studied as Lisp syntax
alternatives.

Pascal Costanza wrote:
> Neil Toronto wrote:
> > Here's what's keeping me with Python: my code reads like pseudocode,
> > and I love that. When I come back to Python code I haven't seen in
> > months, it takes me all of five seconds to grok it again.

> How long have you been learning Common Lisp?

> I am asking this because it typically takes a week or two (or sometimes
> a few more) until you get used to Lisp syntax. Afterwards, with more
> experience, it's typically not an issue anymore. (Although it could
> simply be that those for whom this is then still an issue switch to
> other languages.)

Not too long - I'm mostly just looking into it as a speedy alternative
to other dynamically-typed languages. I did spend a semester working in
Scheme, which I found to be a chore, and I never did get used to it. I
think your parenthetical remark is pretty much spot-on.

I wasn't thinking about Lispers, I was thinking about *me*. Lispers
are, by definition, just fine with the syntax as it is.

I disagree very much with the "just" in front of the "syntax" in your
post. Syntax is *extremely* important. We're not writing programs just
for the compiler, we're writing them for our future selves and other
people. If all programmers thought like compilers, we'd have no
problem. But the fact that even hard-core Lispers need to indent the
heck out of their code and learn to literally ignore a significant
portion of the syntax (the parens) indicates that something may be
lacking in the syntax. C programmers indent, sure, but they don't have
to learn to ignore.

Not that I intend to start a flame-war or anything. I know, I'm getting
close. If that happens, I fully expect the great Paul Graham to jump in
and defend me. :D Apparently, Arc's indentation will have syntactic
meaning.

By the way, thanks for writing your "Highly Opinionated Guide." It's
the only document I've found so far that provides a good summary of
Lisp's advantages over other dynamically-typed languages. Your summary
of macros was especially helpful.

Also, thanks for answering my question.

Neil


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
joswig@corporate-world.li sp.de  
View profile  
 More options Sep 23 2006, 7:17 pm
Newsgroups: comp.lang.lisp
From: "jos...@corporate-world.lisp.de" <jos...@corporate-world.lisp.de>
Date: 23 Sep 2006 16:17:29 -0700
Local: Sat, Sep 23 2006 7:17 pm
Subject: Re: sweet-expressions instead of s-expressions?

Neil Toronto wrote:
> I wasn't thinking about Lispers, I was thinking about *me*. Lispers
> are, by definition, just fine with the syntax as it is.

How to you become a 'Lisper'? Probably by learning and practicing Lisp.
That includes to learn the culture, the habits and the tools of Lisp
programming. You approach a different culture, but you are
not really open minded. Since Lisp requires a different mental
model of computation (and that includes not only syntax)
you need to be prepared to learn a few new things (for example
how to read/write/manipulate Lisp code). If you think that
this is too expensive (time, brain cells, ...) for you, I think you
should not waste your time with syntax experiments and just
skip over Lisp, and look for some other solution to your problem -
a solution that is more compatible with your current believes.

> I disagree very much with the "just" in front of the "syntax" in your
> post. Syntax is *extremely* important. We're not writing programs just
> for the compiler, we're writing them for our future selves and other
> people.

I'm not sure what that has to do with Lisp. Lisp's external syntax
is not for some compiler. Lisp programmers find it useful
because it makes tool building very easy. Macros are
just one of these tools.

> If all programmers thought like compilers,

How does a compiler think?

> we'd have no
> problem. But the fact that even hard-core Lispers need to indent the
> heck out of their code

I almost never indent the code by hand. The editor or the Lisp system
(pretty printing)
does it for me. I like indented code. Nicely indented, color coded
code.
Indented by the editor or the Lisp system. Good Lisp code is a real
pleasure to read.

> and learn to literally ignore a significant
> portion of the syntax (the parens) indicates that something may be
> lacking in the syntax.

Why should a Lisp programmer ignore the parentheses? That would be
stupid. Actually they are part of what makes Lisp programming fun.

Lisp programming has several different dimensions. One is
the manipulation of external (text-based) code and data. Programmers
need to write/read/manipulate code. Lisp is optimized to
allow tools to support you during working with external text-based
code.

Lisp allows the editor to query the Lisp system while you type code.
The running Lisp system knows all about your code (where it is defined,
the documentation, the arglists, the types, the contents, the callers,
...).

Lisp allows the editor to query the Lisp system while you read code.
You can jump to definitions, inspect values, try out examples, ...

Lisp also supports you manipulating your code. Every expression has
a very simple to find start and end. You can use simple structure-based
editing (see paredit), which has little mental overhead once learned
(it is a bit like learning to ride a bicycle). It allows you to
manipulate
your code based on list structure (select, transpose, group, extract,
copy, ...).

So, you have an editor/language combination which supports you
manipulating your code and you have a Lisp system which is
available during editing for various queries.

Then comes the interactive experience. You are working with an editor,
which is connected to a Lisp system (for example via SLIME if your
editor is Emacs). Alternatively you will use an editor-based Listener.
Then you can start thinking of code as data. You will
write some code/data in the editor/listener and the Lisp system
reads them and you can apply functions that manipulate that code.
A simple example is a macro expansion. Your editor buffer
has some code and you want to macro expand it. The editor
takes the code, the Lisp system reads it, generates data structures,
macro expands them, returns new code and your editor displays
it (possibly pretty printed).

You can also write some sketch of some code, read it
into the Lisp system and use the Lisp
system to manipulate it until it has the form you like.
Pretty print the result and place it in your editor buffer.

The whole tool chain is highly optimized around Lisp syntax,
Lisp datastructures and the various tools to read/write/manipulate
these datastructures.

More advanced systems can also parse Lisp data directly from
editor buffers (like you want to display a class graph, the
editor prompts you for a class and all class names in your
editor buffers are mouse sensitive). Or tools like McCLIM
allow you to have mouse sensitive Lisp read-eval-print-loops.

Back to your question. What is the cost of ignoring the Lisp culture
around the syntax? You will have difficulty to use the tool chain.

But then, the syntax is just the first hurdle. Be prepared for more
hurdles. Probably higher ones.

> C programmers indent, sure, but they don't have
> to learn to ignore.

Forget the 'ignore' thing.

> Not that I intend to start a flame-war or anything. I know, I'm getting
> close. If that happens, I fully expect the great Paul Graham to jump in
> and defend me. :D Apparently, Arc's indentation will have syntactic
> meaning.

Maybe you should switch to Arc. As soon as it does what you want.
2010? 2015? 2020? Who knows.

> By the way, thanks for writing your "Highly Opinionated Guide." It's
> the only document I've found so far that provides a good summary of
> Lisp's advantages over other dynamically-typed languages. Your summary
> of macros was especially helpful.

> Also, thanks for answering my question.

My final advice? If you really want to use Lisp (because it may solve
your
initial problem of finding a dynamic language with useful performance),
then you should invest the time to learn the whole culture. Most
beginners find that after some time (maybe a month) they can read
Lisp code just fine. Some are then very enthusiastic about the
excellent
readability of their Lisp code, because they suddenly can write very
high-level
problem-specific code.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ari Johnson  
View profile  
(1 user)  More options Sep 23 2006, 7:18 pm
Newsgroups: comp.lang.lisp
From: Ari Johnson <iamthe...@gmail.com>
Date: Sat, 23 Sep 2006 19:18:46 -0400
Local: Sat, Sep 23 2006 7:18 pm
Subject: Re: sweet-expressions instead of s-expressions?

Let's test the implicit hypothesis that s-expression syntax does not
inherently communicate with the programmer very well in the absence of
redundant (actually, "superfluous" is a more precise term) formatting
and that Algol syntax does:

defun factorial (n)
if (n <= 1)
1
n * factorial(n - 1)

Not any better than:

(defun factorial (x)
(if (<= n 1)
1
(* n (factorial (1- n)))))

The main difference is that it is borderline trivial to auto-indent
the second one with your editor.

Let's try another test:

defun factorial (x) if (n <= 1) 1 n * factorial(n - 1)

This is hard to read and also shows another weakness: explicit
grouping, and therefore no precedence rules to remember.  If you take
out the parentheses, you have to memorize precedence rules.
Precedence rules are one of the chief things that make it easy to
write unreadable C and Perl.

By contrast:

(defun factorial (x) (if (<= n 1) 1 (* n (factorial (1- n)))))

This is more readable and, in the event you have trouble reading it,
can still be auto-indented.

> And as an aside, I'd love to have Python's array (list) and dictionary
> (hash table) syntax. I'd switch to Lisp and convert my entire codebase
> TODAY if I had that.

I don't know Python, but Common Lisp makes it easy to add syntax.
Reader macros are normally all it takes to get the kind of syntax you
are likely after.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Bourguignon  
View profile  
 More options Sep 23 2006, 7:40 pm
Newsgroups: comp.lang.lisp
From: Pascal Bourguignon <p...@informatimago.com>
Date: Sun, 24 Sep 2006 01:40:48 +0200
Local: Sat, Sep 23 2006 7:40 pm
Subject: Re: sweet-expressions instead of s-expressions?

"Neil Toronto" <neil.toro...@gmail.com> writes:
> Ken Tilton wrote:
>> Neil Toronto wrote:
>> > Quick background from the newb:

>> Lousy spelling.  Should be "fom the t-r-o-l-l".

>> hth, kenny

> Ah, I see. So not only is the syntax hostile, but so is the community.
> Fascinating! I wonder if this is as well-studied as Lisp syntax
> alternatives.

Yes, indeed, it's a well studied subject too.

> I disagree very much with the "just" in front of the "syntax" in your
> post. Syntax is *extremely* important.

Not in Lisp.  Not *that* syntax.

> We're not writing programs just
> for the compiler, we're writing them for our future selves and other
> people. If all programmers thought like compilers, we'd have no
> problem. But the fact that even hard-core Lispers need to indent the
> heck out of their code and learn to literally ignore a significant
> portion of the syntax (the parens) indicates that something may be
> lacking in the syntax. C programmers indent, sure, but they don't have
> to learn to ignore.

It's not "ignore" literally either.  There are serveral level of
reading.  For example, at the lexical level, it hurts the eyes when
you can't write "newbie" correctly, or whey Kenny can't spell "from".
All levels are important, and you can be sure that no parenthesis is
overlooked or added gratuituously in Lisp.  It's just that at the
level that matters for programming sophisticated software, parentheses
are not a problem but part of the solution, even if a small part.  If
S-expressions were a problem, it IS ALREADY solved, as LISP was
defined in terms of M-expressions, FIFTY YEARS AGO!

So you'll have to perdon us, if after FIFTY YEARS people keep looking
half a hour at lisp and keep suggesting to modify the syntax:

- we've got better things to do,

- we've solved the problem once for all with reader macros and macros
  that allow you to modify the syntax in your program.

I'd just add that IMO, this question should be solved at the editor
level: everytime you load a source file in an editor, the editor
should apply any syntax, indenting and colorizing the programmer
prefers. (And therefore the source files should keep a consistent
form: S-expressions, and the use of reader macros should be avoided).

--
__Pascal Bourguignon__                     http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Compall  
View profile  
(2 users)  More options Sep 23 2006, 8:24 pm
Newsgroups: comp.lang.lisp
From: Stephen Compall <stephen.comp...@gmail.com>
Date: Sun, 24 Sep 2006 00:24:08 GMT
Local: Sat, Sep 23 2006 8:24 pm
Subject: Re: sweet-expressions instead of s-expressions?

Neil Toronto wrote:
> Here's what's keeping me with Python: my code reads like pseudocode,
> and I love that.

Have you considered the possibility that it is your pseudocode that
reads like Python?

--
Stephen Compall
http://scompall.nocandysw.com/blog


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Bourguignon  
View profile  
 More options Sep 23 2006, 8:30 pm
Newsgroups: comp.lang.lisp
From: Pascal Bourguignon <p...@informatimago.com>
Date: Sun, 24 Sep 2006 02:30:55 +0200
Local: Sat, Sep 23 2006 8:30 pm
Subject: Re: sweet-expressions instead of s-expressions?

"Neil Toronto" <neil.toro...@gmail.com> writes:
> Quick background from the newb: Programmer for 22 years with assembly
> and standard C-like imperatives, just recently became proficient in
> Python and becoming interested in Common Lisp. Why? I want the
> functional goodness and the MACROS, that's why. Also, I do computer
> vision and machine learning research, and my Python code is rather
> slow. I'd like something that's almost as fast as C but very
> expressive, and is strict but highly dynamic and dynamically-typed.

> Here's what's keeping me with Python: my code reads like pseudocode,
> and I love that. When I come back to Python code I haven't seen in
> months, it takes me all of five seconds to grok it again.

Here is how you write pseudo code in lisp, and have it running:

http://groups.google.com/group/comp.lang.lisp/msg/a827235ce7466a92

--
__Pascal Bourguignon__                     http://www.informatimago.com/

"You question the worthiness of my code? I should kill you where you
stand!"


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lars Rune Nøstdal  
View profile  
 More options Sep 23 2006, 9:03 pm
Newsgroups: comp.lang.lisp
From: Lars Rune Nøstdal <larsnost...@gmail.com>
Date: Sun, 24 Sep 2006 03:03:20 +0200
Local: Sat, Sep 23 2006 9:03 pm
Subject: Re: sweet-expressions instead of s-expressions?

Haha - you've just stepped right into the same "trap" almost every
newbie (I did too!) falls into. But don't worry about the elite flamers;
they can't really hurt you - you'll just resurrect anyway and try again
after you have gained some more experience. (yay; I play too much WoW ..
lol)

If you panic and try to struggle it'll get much worse; just go along with
the main ride or bail out until you're ready.

Yep; get over it as quick as possible and hold on for the rest of ride
because there will be some crazy changes. This is just the first one of
many bumps so you've better brace yourself!

Good luck and have fun .. :)

--
Lars Rune Nøstdal
http://lars.nostdal.org/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Warnock  
View profile  
(3 users)  More options Sep 24 2006, 12:19 am
Newsgroups: comp.lang.lisp
From: r...@rpw3.org (Rob Warnock)
Date: Sat, 23 Sep 2006 23:19:25 -0500
Local: Sun, Sep 24 2006 12:19 am
Subject: Re: sweet-expressions instead of s-expressions?
Pascal Costanza  <p...@p-cos.net> wrote:
+---------------
| Neil Toronto wrote:

| > http://www.dwheeler.com/readable/readable-s-expressions.html
| > My main question is whether there are any downsides at all to this
| > approach.
|
| I don't think so. Adding a surface syntax to Lisp shouldn't be that
| much of a problem, as long as the internal representation stays the
| same. It could indeed be interesting if there were several different
| surface syntaxes, for example including graphical ones, which would
| move Lisp towards something like intentional programming.
+---------------

As in ProGraph (q.v.), perhaps?  ;-}

+---------------
| On the other hand, I also think that adding one ore more surface
| syntaxes doesn't solve a fundamental problem, and I don't expect
| that a considerably large number of Lispers will take up this idea
| because of that. After all, it's _just_ syntax. In other words, there
| aren't any downsides, but there also aren't any essential upsides.
+---------------

Actually, I would say that, based on my experience with alternative
surface syntaxes for Scheme/Lisp [Google for my name and "P'Lite"
or "OPFR"], there *are* downsides for "Lispers", especially for
writing sizeable programs. I myself have abandoned each of the
surface syntaxes I've come up with for *programming*, because
they (1) got in the way, and (2) were *not* as readable when I
came back to the code weeks, months, or years later. Normal Lisp
[or Scheme] code, on the other hand, is "timeless". IMHO.

That said, I continue to advocate the use of a "mild" parentheses-
light surface syntax [OPFR] for *interactive* (command-line style
or REPL-like) use, especially for non-Lisper users, for a variety
of more-or-less dedicated "tool" programs.

The "hwtool" pattern that I seem to keep re-implementing[1] over
and over at each new job is a prime case in point. It seems to be
something of a sweet spot in design/use space, with the following
salient features:

1. When run from the shell without arguments, you get a command-line
   prompt with a REPL; given arguments, the rest of the line is taken
   as a single input command-line, then it exits.

2. The input [either REPL or shell command] is parsed by "OPFR",
   an "Outer-Parentheses-Free Repl" (q.v.). That is, to a first
   approximation [ignoring details like continuation lines],
   OPFR:OPFR-READ takes an input line string, wraps "(" & ")"
   around it, and calls READ-FROM-STRING, then does the usual EVAL,
   print [including multiple values], and loop.

3. To make life easier for Lisp-aware users [including me],
   any input that begins with "(" is assumed to be a CL s-expr,
   and normal CL:READ is called to read it.

4. For hardware debugging [its main use], the usual panoply
   of PEEK, POKE, DUMP, etc., utility functions is provided.

5. To make life easier for non-Lisper users [and for hardware
   debugging], a "0x" readmacro is enabled, and a "~/0x/" FORMAT
   function is provided to ease the writing of register dumps.

6. A large majority of things a user needs to do with the tool
   are pre-defined as functions, which therefore appear to the
   naive user as "commands" in the REPL.

7. The program sets a fairly large number of global lexical[1]
   convenience variables with values precomputed from the run-time
   environment, so that most of the time all of the "command"
   arguments a user needs are either one of the precomputed
   convenience variables or literal constants. This sharply
   lessens the need for typing actual Lisp arithmetic expressions
   as input.

A very small example:

    $ hwtool
    Hardware debug tool (CMUCL version)
    Warning: Non-root can't mmap "/dev/mem"
    hwtool> loop for i below 10 collect i

    (0 1 2 3 4 5 6 7 8 9)
    hwtool> deflex vec (vector 1 2 3 4 5)

    VEC
    hwtool> d32 vec
    0x48a0b908: 0x00000032 0x00000014 0x00000004 0x00000008
    0x48a0b918: 0x0000000c 0x00000010 0x00000014 0x00000000
    0x48a0b928: 0x48a08b3f 0x48a0b933 0x28f0000b 0x28f0000b
    0x48a0b938: 0x0000008c 0x28f0000b 0x48a0b93b 0x48a08d2b
    hwtool>

Since I don't have any poke-able hardware registers handy at
the moment, let's reach in and mess with the internals of VEC.
[Don't try this at home unless you and your GC are best of friends!]

    hwtool> w32 0x48a0b918 0x28  ; Decimal 10, as a CMUCL fixnum
    hwtool> d32 vec
    0x48a0b908: 0x00000032 0x00000014 0x00000004 0x00000008
    0x48a0b918: 0x00000028 0x00000010 0x00000014 0x00000000
    0x48a0b928: 0x48a08b3f 0x48a0b933 0x28f0000b 0x28f0000b
    0x48a0b938: 0x0000008c 0x28f0000b 0x48a0b93b 0x48a08d2b
    hwtool> vec

    #(1 2 10 4 5)
    hwtool> w32 0x48a0b920 (lisp-obj #\A)  ; Chars are immeds.

    hwtool> d32 vec
    0x48a0b908: 0x00000032 0x00000014 0x00000004 0x00000008
    0x48a0b918: 0x00000028 0x00000010 0x000041a6 0x00000041
    0x48a0b928: 0x48a08b3f 0x48a0b933 0x28f0000b 0x28f0000b
    0x48a0b938: 0x0000008c 0x28f0000b 0x48a0b93b 0x48a08d2b
    hwtool> vec

    #(1 2 10 4 #\A)
    hwtool>

As I have written before, this appears to be just enough masking
of the "Lispiness" to make such programs be quite acceptable to
general technical users (e.g., hardware engineers, C programmers).

-Rob

[1] Re-inventing, to avoid IP contamination from the PPoE.

[2] Using the now-common DEFINE-SYMBOL-MACRO hack.

-----
Rob Warnock                     <r...@rpw3.org>
627 26th Avenue                 <URL:http://rpw3.org/>
San Mateo, CA 94403             (650)572-2607


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MarkHaniford@gmail.com  
View profile  
(1 user)  More options Sep 24 2006, 2:45 am
Newsgroups: comp.lang.lisp
From: "MarkHanif...@gmail.com" <MarkHanif...@gmail.com>
Date: 23 Sep 2006 23:45:00 -0700
Subject: Re: sweet-expressions instead of s-expressions?

Neil Toronto wrote:
> Ken Tilton wrote:
> > Neil Toronto wrote:
> > > Quick background from the newb:

> > Lousy spelling.  Should be "fom the t-r-o-l-l".

> > hth, kenny

> Ah, I see. So not only is the syntax hostile, but so is the community.
> Fascinating! I wonder if this is as well-studied as Lisp syntax
> alternatives.

Yes it has.  It's called smug lisp weenieness.  Don't worry though,
they live in the bubble and like it that way.  As someone else
mentioned, you might want to take a look at Dylan.  The only problem
with Dylan is that it's even more dead than Lisp.  S-expressions aren't
that bad, but if the editor support is in there for "sweet expressions"
and you can toggle it back and forth, why not.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jayessay  
View profile  
(2 users)  More options Sep 24 2006, 12:38 pm
Newsgroups: comp.lang.lisp
From: jayessay <nos...@foo.com>
Date: 24 Sep 2006 12:38:09 -0400
Local: Sun, Sep 24 2006 12:38 pm
Subject: Re: sweet-expressions instead of s-expressions?

"Neil Toronto" <neil.toro...@gmail.com> writes:
> Ah, I see. So not only is the syntax hostile, but so is the
> community.  Fascinating! I wonder if this is as well-studied as Lisp
> syntax alternatives.

How ironic.  Someone from Python land talking about "hostile syntax"
and "hostile communities".

/Jon

--
'j' - a n t h o n y at romeo/charley/november com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Costanza  
View profile  
 More options Sep 24 2006, 12:04 pm
Newsgroups: comp.lang.lisp
From: Pascal Costanza <p...@p-cos.net>
Date: Sun, 24 Sep 2006 18:04:26 +0200
Local: Sun, Sep 24 2006 12:04 pm
Subject: Re: sweet-expressions instead of s-expressions?

...but don't interpret too much into this remark. Different people have
different preferences, and may simply think differently. The fact that
some people don't seem to get used to Lisp syntax doesn't mean that this
is an inherent problem of Lisp syntax. It also doesn't mean that this is
an inherent problem of those people. It just means that Lisp is just not
a good match for those people.

However, the fact that there is a considerable number of people who
prefer Lisp syntax, even strongly so, shows that it has its merits.

Yes, they do. Or do you really think that experienced C programmers
carefully investigate the meaning of each single semicolon? ;)

The problem with additional syntax is that by definition, you lose the
regularity of the syntax. The more you add, the worse it gets. And this
impedes with syntactic extensibility. The more syntax there already is,
the harder it is to add new syntax that fits well with the rest of a
language.

So what you get in syntactically richer languages is maybe a slight
advantage in the learning phase because of some level of familiarity of
the syntax, but a strong disadvantage in the malleability of the code
representation. In Lisp, you can make the code look like related
concepts from a given problem domain. You can't do that (so well) in
other languages. So either the languages already fit your problem
domain, or they don't in which case you have a discrepancy between the
problem and they way you have to express a solution.

You may want to take a deeper look at Dylan, which was an attempt at a
compromise. The syntax is somewhat richer than Lisp syntax, but still
relatively regular. You might want to take a look at Jonathan Bachrach's
work on "Dylan Procedural Macros" and the "Java Syntactic Extender" in
this context - see http://people.csail.mit.edu/jrb/

> By the way, thanks for writing your "Highly Opinionated Guide." It's
> the only document I've found so far that provides a good summary of
> Lisp's advantages over other dynamically-typed languages. Your summary
> of macros was especially helpful.

> Also, thanks for answering my question.

You're welcome.

Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jshra...@gmail.com  
View profile  
(4 users)  More options Sep 24 2006, 12:43 pm
Newsgroups: comp.lang.lisp
From: JShra...@gmail.com
Date: 24 Sep 2006 09:43:59 -0700
Local: Sun, Sep 24 2006 12:43 pm
Subject: Re: sweet-expressions instead of s-expressions?
You have utterly missed the point of Lisp. (Plesae don't take this
personally; everyone new to lisp does, which is why this conversation
happens over and over and over again.) Let me repeat your own words to
you:

"[I am] becoming interested in Common Lisp. Why? I want the functional
goodness and the MACROS, that's why."

The whole point of Lisp -- the thing that makes Lisp Lisp and not any
other language -- is the amazing discovery that both the programmer and
the computer can in fact read and write THE SAME CODE!

If we did what you propose -- if we gave Lisp some sort of random
surface syntax. (Python is an especially random example of this --
using, of all things, whitespace and lineturns (!!) as syntax) which
was read differently by the programmer and the computer, then all the
magic of Lisp, esp. Macros, which you claim to be the thing that
brought you to Lisp, would suddenly vanish in a puff of syntax.

You don't understand this yet, but you will if you keep at it, and esp.
when you get to macros.

Now, closely related to this, your second point:

"And as an aside, I'd love to have Python's array (list) and dictionary
(hash table) syntax. I'd switch to Lisp and convert my entire codebase
TODAY if I had that."

You do have that; They are called hash tables and the only differences
are that you have to declare them before using them, and they have a
slightly more long-winded syntax than python's. Here's a challenge for
your first experiment in macros: You want python-style dictionaries. By
the magic of Lisp syntax and macros, you can in fact, have them!
Remember in thinking through this: Don't fight the syntax! If you try
to have both python dicts AND python syntax, you'll lose, and you'll
lose macros and you might as well go back to Python. But you'll know
that you've learned to think in Lisp when you can see that this, and
anything else you want, you can have; the only limitation is your
imagination! A small price to pay, I'd say, for having to say (+ 1 2)
instead of 1+2....

'Jeff


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Bourguignon  
View profile  
(1 user)  More options Sep 24 2006, 1:22 pm
Newsgroups: comp.lang.lisp
From: Pascal Bourguignon <p...@informatimago.com>
Date: Sun, 24 Sep 2006 19:22:46 +0200
Local: Sun, Sep 24 2006 1:22 pm
Subject: Re: sweet-expressions instead of s-expressions?

JShra...@gmail.com writes:
> Now, closely related to this, your second point:

> "And as an aside, I'd love to have Python's array (list) and dictionary
> (hash table) syntax. I'd switch to Lisp and convert my entire codebase
> TODAY if I had that."

> You do have that; They are called hash tables and the only differences
> are that you have to declare them before using them, and they have a
> slightly more long-winded syntax than python's. Here's a challenge for
> your first experiment in macros: You want python-style dictionaries. By
> the magic of Lisp syntax and macros, you can in fact, have them!

(defun literal-hash-table (key-value-others)
  (loop
     :with table = (make-hash-table :test (function equal))
     :for (key value) :on key-value-others :by (function cddr)
     :do (setf (gethash key table) value)
     :finally (return table)))

(defun python-dictionary-reader-macro (stream brace)
  (declare (ignore brace))
  (literal-hash-table (read-delimited-list #\} stream t )))

(set-macro-character #\{ (function python-dictionary-reader-macro))

(gethash "to" { "for" "four" "to" "two" })
--> "two" ;
    T

You could work harder to allow : and , inside {}, but it's not worth
it, they're just noise.

> Remember in thinking through this: Don't fight the syntax! If you try
> to have both python dicts AND python syntax, you'll lose, and you'll
> lose macros and you might as well go back to Python. But you'll know
> that you've learned to think in Lisp when you can see that this, and
> anything else you want, you can have; the only limitation is your
> imagination! A small price to pay, I'd say, for having to say (+ 1 2)
> instead of 1+2....

> 'Jeff

--
__Pascal Bourguignon__                     http://www.informatimago.com/

"You cannot really appreciate Dilbert unless you read it in the
original Klingon"


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ari Johnson  
View profile  
(1 user)  More options Sep 24 2006, 1:50 pm
Newsgroups: comp.lang.lisp
From: Ari Johnson <iamthe...@gmail.com>
Date: Sun, 24 Sep 2006 13:50:17 -0400
Local: Sun, Sep 24 2006 1:50 pm
Subject: Re: sweet-expressions instead of s-expressions?

With the example of reader macros I gave at
http://devpit.org/wiki/Lisp you can do:

#[key1 "value1" key2 "value2"] to construct,
#100[key1 "value1"] to construct with a specified hash table size, and
[hashtab key1] to retrieve (this is setf-able)

And it's this simple:

(set-dispatch-macro-character #\# #\[
  #'(lambda (stream subchar arg)
      (declare (ignore subchar))
      (let ((list (read-delimited-list #\] stream t))
            (keys '())
            (values '())
            (hashtab (gensym)))
        (do ((key list (cddr key))
             (value (cdr list) (cddr value)))
            ((null key))
          (when (not (symbolp (car key)))
            (error "Keys must be symbols"))
          (push (car key) keys)
          (push (car value) values))
        (setf keys (nreverse keys))
        (setf values (nreverse values))
        `(let ((,hashtab ,(if arg
                              `(make-hash-table :test #'equalp :size ,arg)
                              '(make-hash-table :test #'equalp))))
           ,@(mapcar #'(lambda (key value)
                         `(setf (gethash ',key ,hashtab) ,value))
                     keys
                     values)
           ,hashtab))))

(set-macro-character #\[
  #'(lambda (stream char)
      (declare (ignore char))
      (let ((list (read-delimited-list #\] stream t)))
        (when (/= (length list) 2)
          (error "Invalid number of arguments to []"))
        (when (not (symbolp (cadr list)))
          (error "Key must be a symbol"))
        `(gethash ',(cadr list) ,(car list)))))

(set-macro-character #\] (get-macro-character #\)))


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Javier  
View profile  
(1 user)  More options Sep 24 2006, 2:00 pm
Newsgroups: comp.lang.lisp
From: "Javier" <javu...@gmail.com>
Date: 24 Sep 2006 11:00:02 -0700
Local: Sun, Sep 24 2006 2:00 pm
Subject: Re: sweet-expressions instead of s-expressions?

Neil Toronto ha escrito:

> Ken Tilton wrote:
> > Neil Toronto wrote:
> > > Quick background from the newb:

> > Lousy spelling.  Should be "fom the t-r-o-l-l".

> > hth, kenny

> Ah, I see. So not only is the syntax hostile, but so is the community.
> Fascinating! I wonder if this is as well-studied as Lisp syntax
> alternatives.

Don't worry too much about Ken hostilities, or you'll learn in the hard
way that it is a waste of time. Just ignore him.

My answer to your question (which might be wrong) is that Lisp syntax
is the way it is because of macros. Try to learn and use macros and
you'll discover that for having a powerfull use of them an infix syntax
is a must, otherwise you are limited to the more simplistic ones of C.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jshra...@gmail.com  
View profile  
(3 users)  More options Sep 24 2006, 2:44 pm
Newsgroups: comp.lang.lisp
From: JShra...@gmail.com
Date: 24 Sep 2006 11:44:22 -0700
Local: Sun, Sep 24 2006 2:44 pm
Subject: Re: sweet-expressions instead of s-expressions?
Not to throw cold water on this impressive series of demos, these
aren't excellent but somewhat tangential to what I had in mind. Mark my
words: "Remember in thinking through this: Don't fight the syntax! If
you try to have both python dicts AND python syntax, you'll lose, and
you'll lose macros and you might as well go back to Python."

What you (both) have demonstrated is the power or reader macros in
defining new syntax, but I don't think that new syntax (in the sense of
reader macros) is either necessary nor particularly appropriate in the
context of the present discussion. I had mind mind something at the
same time hack-wise simpler, yet coneptually more complex: Not just
letter one type: {for bar baz frob} -- forget the braces etc. Rather,
what I had in mind (Neil puzzling through himself) was what the central
concept(s) is(are) of dictionaries and how, using standard Lisp macros,
one could get the >concepts<, not just the baces and brackets. Of
course, the concepts are almost already there (as I pointed out) in
Lisp (in the guise of hash tables, mostly), and I don't think that he
wants -- or shouldn't want -- what you have offered, which is the
syntax. Rather, he wants (or should want) hash-tables to be as
convenient as dictionaries. The only things really limiting this in
Lisp are the need to declare them, and the ability to use
comprehensions (i.e., slicing expressions aka comprehensions aka
generators) as the targets of setting operations. (Some would say that
generators are themselves a conceptual advantage of Python, but these
are trivally obtainable using, or if you like, macofying in of Lisp
generators, and there are already lisp packages that do this!)

Neither of these is a huge stumbling block (although the former:
declaration) may cause efficiency problems -- which may be why Lisp
requires this; I'm not sure).  And the examples hereabove by Ari and
Pascal contain part of the story, but in reading their code, I would
say to ignore their syntactic offerings and focus on their semantic
offerings, and expand from there. Adding syntax is usually simple (as
demonstrated) but generally a bad idea (as I have previously argued)
because it breaks the model of code as data and v.v.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Thingstad  
View profile  
(2 users)  More options Sep 24 2006, 3:16 pm
Newsgroups: comp.lang.lisp
From: "John Thingstad" <john.things...@chello.no>
Date: Sun, 24 Sep 2006 21:16:18 +0200
Local: Sun, Sep 24 2006 3:16 pm
Subject: Re: sweet-expressions instead of s-expressions?

This is a library implementingg list comprehentions
not ulike python. Is this what you are missing?

http://user.it.uu.se/~svenolof/Collect/

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andras Simon  
View profile  
(1 user)  More options Sep 24 2006, 4:20 pm
Newsgroups: comp.lang.lisp
From: Andras Simon <asi...@math.bme.hu>
Date: 24 Sep 2006 22:20:17 +0200
Local: Sun, Sep 24 2006 4:20 pm
Subject: Re: sweet-expressions instead of s-expressions?

"Neil Toronto" <neil.toro...@gmail.com> writes:
> Here's what's keeping me with Python: my code reads like pseudocode,
> and I love that. When I come back to Python code I haven't seen in
> months, it takes me all of five seconds to grok it again.

> So has anyone seen this?

> http://www.dwheeler.com/readable/readable-s-expressions.html

> Short version: significant whitespace (indentation can replace parens),
> "func(param1 param2)" calls, infix notation (which is good for math
> code), and it still parses regular s-expressions correctly. Because it
> transforms "sweet-expressions" to s-expressions, macros still work.

If readability is your concern, write an s-expr->sweet-expr converter
and define a SLIME command that invokes it. Then, if you have problems
reading a complicated s-expr, you can just press M-s or whatever, and
see it as a sweet-expr.

Andras


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jshra...@gmail.com  
View profile  
(1 user)  More options Sep 24 2006, 4:36 pm
Newsgroups: comp.lang.lisp
From: JShra...@gmail.com
Date: 24 Sep 2006 13:36:04 -0700
Local: Sun, Sep 24 2006 4:36 pm
Subject: Re: sweet-expressions instead of s-expressions?

> This is a library implementingg list comprehentions
> not ulike python. Is this what you are missing?

It's not me that's missing it, it's Neil, but, yes, this is exactly
what I was refering to.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Tilton  
View profile  
(3 users)  More options Sep 24 2006, 9:01 pm
Newsgroups: comp.lang.lisp
From: Ken Tilton <kentil...@gmail.com>
Date: Sun, 24 Sep 2006 21:01:36 -0400
Local: Sun, Sep 24 2006 9:01 pm
Subject: Re: sweet-expressions instead of s-expressions?

Sucker. :)

kt

--
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ken Tilton  
View profile  
(3 users)  More options Sep 24 2006, 10:07 pm
Newsgroups: comp.lang.lisp
From: Ken Tilton <kentil...@gmail.com>
Date: Sun, 24 Sep 2006 22:07:41 -0400
Local: Sun, Sep 24 2006 10:07 pm
Subject: Re: sweet-expressions instead of s-expressions?

Pascal Costanza wrote:
> Neil Toronto wrote:

>> Pascal Costanza wrote:

>>> Neil Toronto wrote:

>>>> Here's what's keeping me with Python: my code reads like pseudocode,
>>>> and I love that. When I come back to Python code I haven't seen in
>>>> months, it takes me all of five seconds to grok it again.

...

> However, the fact that there is a considerable number of people who
> prefer Lisp syntax, even strongly so, shows that it has its merits.

God how I love watching otherwise intelligent people trying to justify a
notation with fifty years of success to a user of (were he honest) three
days.

:)

Did I say "user"? PWUAHAHHAHAHAHHAAH.... I meant self-important
dilettante. "Hey, guys! Just found Lisp! Love it! Here is how we can fix
it...your thoughts?" PWUAUUAUAUAUAHAHAHAHH... I slay myself.

kenny

--
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 69   Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google