From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help 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) Organization: http://groups.google.com Message-ID: References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1294262089 28279 80.91.229.12 (5 Jan 2011 21:14:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 5 Jan 2011 21:14:49 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 05 22:14:40 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Paagl-0006jD-7I for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Jan 2011 22:14:39 +0100 Original-Received: from localhost ([127.0.0.1]:49912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Paagi-00018m-83 for geh-help-gnu-emacs@m.gmane.org; Wed, 05 Jan 2011 16:14:32 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!i32g2000pri.googlegroups.com!not-for-mail Original-Newsgroups: comp.lang.functional, comp.lang.lisp, gnu.emacs.help, comp.lang.forth, comp.lang.prolog Original-Lines: 209 Original-NNTP-Posting-Host: 76.126.112.84 Original-X-Trace: posting.google.com 1294239519 17008 127.0.0.1 (5 Jan 2011 14:58:39 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 5 Jan 2011 14:58:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i32g2000pri.googlegroups.com; posting-host=76.126.112.84; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10, gzip(gfe) Original-Xref: usenet.stanford.edu comp.lang.functional:69123 comp.lang.lisp:297294 gnu.emacs.help:184017 comp.lang.forth:160367 comp.lang.prolog:44039 X-Mailman-Approved-At: Wed, 05 Jan 2011 16:10:44 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:78232 Archived-At: On Dec 31 2010, 11:04=C2=A0pm, girosenth 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 =E2=80=9Cprefix=E2=80=9D is misleading. When you say =E2=80=9Cprefix=E2=80=9D or =E2=80=9Cpostfix=E2=80=9D 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 =E2=80=9Cpre-fix=E2=80=9D doesn't make much sense becaus= e that word is primarly for operators used in a linear (none nested) way. for detail, see: =E3=80=88The Concepts and Confusions of Prefix, Infix, Postfix and Fully Nested Notations=E3=80=89 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 =C2=A0)) > .... > .... > (setq F (f G =C2=A0)) > > 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* > =C2=A0 ((L (l ops)) > =C2=A0 =C2=A0(K (k L =C2=A0)) > =C2=A0 =C2=A0.... > =C2=A0 =C2=A0(F (f G =C2=A0))) > > 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: =E3=80=88What's Point-free Programing? (point-free function syntax)=E3=80= =89 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 =E2=80=A2 strictly no nesting whatsoever is not a desired property. =E2=80=A2 when done to a large extend yet not 100% (e.g. APL and derivative= s), 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 =E2=80=9Cstack=E2=80=9D). Another way to view t= his 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 =E2=80=9Creverse polish notation=E2= =80=9D 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 =E2=80=9Cformal=E2=80=9D way, so as to cle= arly 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: =E2=80=A2 =E3=80=88Math Notations, Computer Languages, and the =E2=80=9CFor= m=E2=80=9D in Formalism=E3=80=89 http://xahlee.org/cmaci/notation/lang_notation_formalism.html =E2=80=A2 =E3=80=88Pattern Matching vs Lexical Grammar Specification=E3=80= =89 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 =E2=80=9Cself-documenting=E2=80=9D. For example, lisp code= rs 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 =C2=ABHow does one improve readability so that the code is self-commenting ?=C2=BB 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 =E3=80=8Cx^3=E3=80=8D with the 3 raised, you have 1/2 with 1 on to= p 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 =E3=80=88Math Typesetting, Mathematica, MathML=E3=80=89 http://xahlee.org/m= ath/typesetting_Mathematica_mathML.html The same expression in lisp style you get this /(+(-(b) =E2=88=9A(+(^(b 2) -(*(4 a c))))) *(2 a)) is it readable? Many lispers insist that its the most readable syntax. See also: =E2=80=A2 =E3=80=88What's Function, What's Operator?=E3=80=89 http://xahlee= .org/math/function_and_operators.html Xah =E2=88=91 http://xahlee.org/ =E2=98=84