help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to improve the readability of (any) LISP or any highlevel functi


From: Doug Hoffman
Subject: Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?
Date: Thu, 06 Jan 2011 08:38:59 -0500
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.5; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2

On 1/5/11 4:42 PM, Pascal J. Bourguignon wrote:
Elena<egarrulo@gmail.com>  writes:

On Jan 5, 3:58 pm, Xah Lee<xah...@gmail.com>  wrote:
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.

And here is why: http://blo.udoidio.info/2008/09/lisp-syntax-is-great.html

He's wrong, the most readable is:

   (divide (minus (square-root (minus (square b) (* 4 a c)))
                  b)
           2 a)

or, for wanbees:

   (/ (- (sqrt (- (square b) (* 4 a c))) b)
      2 a)

Without getting into the issues of the proper way to handle the quadratic (this has been thoroughly hashed thru on comp.lang.forth) and sticking with just the simple equation as presented (I'll ignore the issue of taking the square root of negative numbers) I would make the following observations:

1)
> (divide (minus (square-root (minus (square b) (* 4 a c))) b) 2 a)

This may be very readable for Lispers.  For others not so much.

2) The following is one way (of many) to approach this in standard Forth:

: quad f{ a b c -- root }
  b FNEGATE b FDUP F* 4e a c F* F* F- FSQRT F+ 2e a F* F/
  ;

-2e 7e 15e quad f.
-1.500000

Is it readable? Unless you're a Forther I would say no. But notice the complete lack of parentheses and operator precedences to resolve. Any competent Forther could quickly see exactly what is going on.

3) We have available in Forth a FORmula TRANslator utility (it is not part of the official ANS Forth standard). It could be applied in this situation as follows:

: quad2 f{ a b c -- root }
  f' (-b + sqrt(b^2 - 4*a*c))/(2*a)'
  ;

-2e 7e 15e quad2 f.
-1.500000

Is it readable? I would say yes. Note that it compiles *exactly* the same Forth code as quad in 2).

4) I am able to do a copy/paste of
   =(-b + sqrt(b^2 - 4*a*c))/(2*a)
into an Excel spreadsheet and with the variables a, b, and c defined the spreadsheet gives the expected results.

-Doug


reply via email to

[Prev in Thread] Current Thread [Next in Thread]