🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #1161

Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?

#1161
From: Doug Hoffman
Date: Thu, 06 Jan 2011 13:38
67 lines
4045 bytes
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
Technical Details
Message-ID: <4d25c5f5$0$23761$14726298@news.sunsite.dk>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!news2.euro.net!newsfeed.freenet.ag!news.netcologne.de!ramfeed1.netcologne.de!news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> <e37b64b7-61ba-4247-a6cd-e32323c7be15@i32g2000pri.googlegroups.com> <767329f7-d300-4090-93cb-717d70fbadc4@i17g2000vbq.googlegroups.com> <87ei8rdo38.fsf@kuiper.lan.informatimago.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 107f24,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: f4fd2,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: 103b8b,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: fd7c9,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Thread: f907c,1641de092071599d
X-Google-NewGroupId: yes
X-Google-Attributes: gid4e63bbc566,gidf85ca024c1,gid39ae015015,gid2832dde05d,gidee3de009bc,domainid0,public,usenet
X-Google-Language: ENGLISH,UTF8
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder.news-service.com!news2.euro.net!newsfeed.freenet.ag!news.netcologne.de!ramfeed1.netcologne.de!news.tele.dk!feed118.news.tele.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Date: Thu, 06 Jan 2011 08:38:59 -0500
From: Doug Hoffman <glidedog@gmail.com>
Reply-To: glidedog@gmail.com
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
MIME-Version: 1.0
Newsgroups: comp.lang.functional,comp.lang.lisp,gnu.emacs.help,comp.lang.forth,comp.lang.prolog
Subject: Re: How to improve the readability of (any) LISP or any highlevel
 functional language to the level of FORTH ?
References: <80ceeca0-1d32-47d1-ba96-feb4d9729c3a@v17g2000yqv.googlegroups.com> <e37b64b7-61ba-4247-a6cd-e32323c7be15@i32g2000pri.googlegroups.com> <767329f7-d300-4090-93cb-717d70fbadc4@i17g2000vbq.googlegroups.com> <87ei8rdo38.fsf@kuiper.lan.informatimago.com>
In-Reply-To: <87ei8rdo38.fsf@kuiper.lan.informatimago.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 67
Message-ID: <4d25c5f5$0$23761$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: 108.98.224.54
X-Trace: news.sunsite.dk DXC=W^nmh[5O`ZMMG4[9BMmA=KYSB=nbEKnkK[R[7PZBi8oN:je<aU]h2SBF8_<o2?^;\N=nR^mRETY^Kemd4oaPj7>G4AC05oXo^BN
X-Complaints-To: staff@sunsite.dk