unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Xah Lee <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?
Date: Wed, 5 Jan 2011 06:58:39 -0800 (PST)	[thread overview]
Message-ID: <e37b64b7-61ba-4247-a6cd-e32323c7be15@i32g2000pri.googlegroups.com> (raw)
In-Reply-To: 80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com


On Dec 31 2010, 11:04 pm, girosenth <girose...@india.com> wrote:
> How to improve the readability of (any) LISP or any highlevel
> functional language to the level of FORTH ?
>
> There are many people who have trivia complaints about parens in lisp,
> but I dont.
>
> LISP is a prefix notation.

Note that calling lisp syntax as “prefix” is misleading.

When you say “prefix” or “postfix” notation, implied in the word is
use of operators and their general ordering characteristics.

lisp syntax does not use operators, or rather, it primarily relies on
one single match-fix operator the parenthesis. And as a match-fix
operator, the word “pre-fix” doesn't make much sense because that word
is primarly for operators used in a linear (none nested) way.

for detail, see:

〈The Concepts and Confusions of Prefix, Infix, Postfix and Fully
Nested Notations〉
 http://xahlee.org/UnixResource_dir/writ/notations.html

> sequence of operations would look like this on operands (ops) :
>
> (f ops (g ops (h ops (j ops (k ops (l ops ))...))))
>
> How do you make it readable ?
> How do you home to the center or centers ?
>
> (f (g (h (j (k (l ops)))...)))
>
> is easy to read or
>
> ops l k j h g f
>
> ???
>
> Which is linear reading from L->R ? LISP or FORTH ?
>
> AND, if I must break the nested function structure, will I not be
> visiting the forbidden territory of imperative programming ?
>
> (setq L (l ops))
> (setq K (k L  ))
> ....
> ....
> (setq F (f G  ))
>
> If I use setq, I am using globals, atleast in elisp.
>
> If I use let*, I have limited options as I am constrained inside the
> rigid structure of let*
>
> (let*
>   ((L (l ops))
>    (K (k L  ))
>    ....
>    (F (f G  )))
>
> some more
> )
>
> Is there a postfix functional language that also gets rid of parens
> and is not as primitive as FORTH or POSTSCRIPT ?

you might get some tips about this from this article:

〈What's Point-free Programing? (point-free function syntax)〉
http://xahlee.org/comp/point-free_programing.html

i've thought about a syntax that does not use any match-fix operators
(nesting of symbols) whatsoever. But my current conclusion is that

• strictly no nesting whatsoever is not a desired property.
• when done to a large extend yet not 100% (e.g. APL and derivatives),
you sacrifice several advantages in syntax and also some semantic
possibilty in the lang.

also note, reduction or elimination of match-fix operators in so-
called stack
based lang such as Forth, does not really qualify as a syntactical
solution. It
rids of match-fix by a semantic solution. (i.e. there's implicit
hiding of
arguments, they went into a “stack”). Another way to view this is
that, when we
look at Forth (which am not familiar) or HP-28s calculator's language
(which i'm
familiar), or if we look at so-called “reverse polish notation” RPN,
the RPN is
not a complete syntx system on its own right, but relies on a language
system... (not sure if anyone see what i mean here... i need to do a
lot more
thinking to express this in some “formal” way, so as to clearly
indicate the
properties differences)

> What are the syntax advantages of ERLANG, ML, CAML, OCAML, HASKELL,
> PROLOG, RUBY over LISP ?

that's a loaded question of course.

but my own pet peeves is that there is to-date no major general
purpose comp lang that actually have a lexical grammar. The awareness
of the concept of a grammar for syntax is little known among
programers. Each lang basically create a bunch of ad hoc syntax, that
are not consistent nor well defined. In fact, no major general purpose
languages even have a lexical grammar per se. (what we have are just
tools that helps define and parse)

 The only close exception is XML, but of course it is just a markup
lang.

for some detail, see:

• 〈Math Notations, Computer Languages, and the “Form” in Formalism〉
http://xahlee.org/cmaci/notation/lang_notation_formalism.html

• 〈Pattern Matching vs Lexical Grammar Specification〉
http://xahlee.org/cmaci/notation/pattern_matching_vs_pattern_spec.html

> How does one improve readability so that the code is self-commenting ?

it's a common myth among programers that certain lang's syntax is so
clear that it is “self-documenting”. For example, lisp coders said it
in 1970s or earlier when sexp and the idea of a lang that reflex math
directly is new. Mathematica literature said it in 1990s because
pattern matching is a good fit for symbolic manipulation. Haskeller
has said it because they think Haskell code is so much a direct mirror
of traditional math notation (and this is quite laughable when
compared to Mathematica). And Ruby coder said it because they feel how
the syntax mirror programing algorithms so clearly and concisely.

Perl mongers to various degree also thinks of that of their lang,
because how the perl idioms allow ommision of many syntactical details
and quite flexible and they think it reflect the way human uses
natural lang (e.g. english).

so, sometimes in discussion, someone show you a line of code without
any comment or explanation. To you, you are perplexed at what the code
does. When you ask, you find out that they are honestly surprised
because they think that the code's meaning is so plain and obvious
that any additional explanation actually complicate it.

part of all these feelings is due to the fact that when you are
familiar with a lang, it becomes part of your thinking, a written
language to express your thoughts. Especially so if you don't know
much of other langs. You are too familiar with the lang to realize the
fact that different languages have always been a barrior to
communication. The more expert you are with a lang, and the less the
number of other langs you actually work with in depth, the more likely
you forgot that different langs are just different. What's obvious to
you, even just a short line, is really just a string of gibberish
symbols mixed together in weird ways to another who are not familiar
with your lang.

So, your question «How does one improve readability so that the code
is self-commenting ?» has many answers depending what you really want.
Comp lang syntax readability is a subject in the context psychology
and linguistics. Among comp lang forums among programers, they knew
nothing of it, and what you read there usually is utter garbage. But
to take a general programer practioners's point of view, for example,
Python is considered very readable, and the primary reason for sayig
so is actually just code formatting (i.e. short lines, and all neatly
indented), and the reason python code are well formatted because the
formatting is worked into the language's syntax.

take a complete different perspective, there's Mathematica. For
example, what do you think if comp lang source code are like
traditional math notation that's so-call 2-dimentional notation? e.g.
you have 「x^3」 with the 3 raised, you have 1/2 with 1 on top of a bar
and 2 below the bar, etc. And when the expression gets complex, e.g.

-b + Sqrt[b^2-4 a c]/(2 a)

it becomes much easier to read when in traditional math notation. In
Mathematica, its syntax system is such that, it can display the source
code in 2-dimentional notation automatically, if you want. you can see
some example here, also in PDF format

〈Math Typesetting, Mathematica, MathML〉 http://xahlee.org/math/typesetting_Mathematica_mathML.html

The same expression in lisp style you get this

/(+(-(b) √(+(^(b 2) -(*(4 a c))))) *(2 a))

is it readable? Many lispers insist that its the most readable syntax.

See also:
• 〈What's Function, What's Operator?〉 http://xahlee.org/math/function_and_operators.html

 Xah ∑ http://xahlee.org/

  parent reply	other threads:[~2011-01-05 14:58 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-01  7:04 How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ? girosenth
2011-01-01 11:39 ` Elena
2011-01-01 14:15 ` Pascal J. Bourguignon
2011-01-01 16:08   ` Nathan
2011-01-01 18:05     ` Jan Burse
2011-01-01 23:56     ` The Quiet Center
2011-01-02  1:10       ` Jan Burse
2011-01-02  3:45       ` LanX
2011-01-02  4:04         ` LanX
2011-01-02  5:36           ` Nathan
2011-01-02  6:46             ` Paul Rubin
2011-01-02 15:01               ` LanX
2011-01-02 15:14                 ` Jerome Baum
2011-01-02 21:21                 ` Paul Rubin
2011-01-02  7:14             ` w_a_x_man
2011-01-02  6:59       ` w_a_x_man
2011-01-03 15:22         ` LanX
2011-01-02 14:07       ` Frank GOENNINGER
2011-01-07  9:41       ` w_a_x_man
2011-01-09 10:41         ` How to improve the readability of (any) LISP or any highlevelfunctional " WJ
2011-01-03 10:29     ` How to improve the readability of (any) LISP or any highlevel functional " Didier Verna
2011-01-03 13:05       ` Tim Harig
2011-01-04  4:49         ` rusi
2011-01-04  5:39           ` D Herring
2011-01-04  8:02             ` Tim Harig
2011-01-04  9:09               ` Nicolas Neuss
2011-01-04 10:00               ` Tim Bradshaw
2011-01-04 12:21                 ` Tim Harig
2011-01-04 12:23                   ` Tim Bradshaw
2011-01-04 13:33                     ` Tim Harig
2011-01-04 12:41                   ` Tamas K Papp
2011-01-04 23:32                 ` Tim X
2011-01-05  1:35                   ` [OT] LISP community advocacy [was Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?] Tim Harig
2011-01-05  9:52                   ` How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ? Tim Bradshaw
2011-01-04  6:24           ` Pascal J. Bourguignon
2011-01-04 15:43             ` Raffael Cavallaro
2011-01-04 10:18         ` Didier Verna
2011-01-01 22:50   ` girosenth
2011-01-02 21:11     ` Thien-Thi Nguyen
2011-01-03 16:21     ` José A. Romero L.
2011-01-03 18:03     ` jacko
2011-01-02 23:45   ` Chip Eastham
2011-01-01 18:27 ` How to improve the readability of Steve Revilak
2011-01-01 19:22 ` How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ? prad
2011-01-01 23:56 ` Pascal Costanza
2011-01-02  5:39   ` D Herring
2011-01-02 14:17     ` Frank GOENNINGER
2011-01-02 14:53       ` Jerome Baum
2011-01-02 14:58         ` LanX
2011-01-02 17:55     ` Bernd Paysan
2011-01-03 18:07   ` jacko
2011-01-02 12:59 ` Doug Hoffman
2011-01-02 19:14   ` w_a_x_man
2011-01-03  5:20     ` Elizabeth D Rather
2011-01-03 10:48     ` MarkWills
2011-01-03 15:13       ` LanX
2011-01-03 18:20     ` jacko
2011-01-03 18:22     ` jacko
2011-01-03 10:18 ` Didier Verna
2011-01-04  6:47 ` pineapple
2011-01-04 14:14   ` P.M.Lawrence
2011-01-05 14:58 ` Xah Lee [this message]
2011-01-05 16:21   ` Andrew Haley
2011-01-05 21:29     ` Pascal J. Bourguignon
2011-01-06  8:57       ` Jonathan Groll
2011-01-07  5:36     ` Xah Lee
2011-01-07 13:28       ` Andrew Haley
2011-01-07 16:19         ` Xah Lee
2011-01-05 17:59   ` Elena
2011-01-05 20:13     ` Xah Lee
2011-01-05 21:42     ` Pascal J. Bourguignon
2011-01-06 13:38       ` Doug Hoffman
2011-01-06 19:20         ` Pascal J. Bourguignon
2011-01-07  0:09           ` w_a_x_man
2011-01-07 12:04           ` Doug Hoffman
2011-01-06 22:59   ` Xah Lee
2011-01-07 11:47     ` Jan Burse
2011-01-21 10:03       ` rupertlssmith
2011-01-21 16:08         ` Jan Burse
2011-01-21 21:43           ` D. J. Penton
2011-01-18 22:55 ` m_l_g3
2011-01-19 13:45   ` Doug Hoffman
2011-01-21 16:15   ` Jan Burse
  -- strict thread matches above, loose matches on Subject: below --
2011-01-02 16:50 Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e37b64b7-61ba-4247-a6cd-e32323c7be15@i32g2000pri.googlegroups.com \
    --to=xahlee@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).