Article View: comp.lang.functional
Article #1155Re: How to improve the readability of (any) LISP or any highlevel functional language to the level of FORTH ?
From: Doug Hoffman
Date: Fri, 07 Jan 2011 12:04
Date: Fri, 07 Jan 2011 12:04
49 lines
3438 bytes
3438 bytes
On 1/6/11 2:20 PM, Pascal J. Bourguignon wrote:
> Doug Hoffman<glidedog@gmail.com> writes:
>
>> 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.
>
> Now, as a Forth programmer, ask yourself what you would have to do, to
> call an operator with a variable arity?
One way to handle a variable number of input parameters is to precede
them with a count. There is at least one ANS Forth word that does this.
I've seen the technique used a lot elsewhere in Forth code. Supplying
a "mark" is also something I've seen.
If I am going to apply a single operator to a list of many items, in
Forth I would likely put the items in a list, perhaps a list of objects
depending on the nature of the items, and then iterate over the list.
Just to be clear, so we don't get sidetracked on a Lisp vs Forth
tangent: I commented that I believed the Lisp example is somewhat
readable to someone unfamiliar with Lisp, Forth is not readable to
someone unfamiliar with Forth. The standard "Fortran/spreadsheet"
syntax version is the most readable for this example regardless of
language familiarity, again in my opinion.
[snip]
> (F/ (F* a 2e)
> (F+ (FSQRT (F- (F* c a 4e)
> (F* (FDUP (- b)))))))
>
> so it becomes readable again and you can see there's a bug in the Forth
> expression.
No, I can't see any bug in the Forth example. Could you point it out
more clearly?
-Doug
Technical Details
Message-ID:
<4d270142$0$23753$14726298@news.sunsite.dk>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mailReferences:
<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> <4d25c5f5$0$23761$14726298@news.sunsite.dk> <87bp3tdejx.fsf@kuiper.lan.informatimago.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 2832dde05d,1641de092071599d X-Google-Attributes: gid2832dde05d,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail Date: Fri, 07 Jan 2011 07:04:17 -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> <4d25c5f5$0$23761$14726298@news.sunsite.dk> <87bp3tdejx.fsf@kuiper.lan.informatimago.com> In-Reply-To: <87bp3tdejx.fsf@kuiper.lan.informatimago.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 49 Message-ID: <4d270142$0$23753$14726298@news.sunsite.dk> Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 184.226.178.231 X-Trace: news.sunsite.dk DXC=e3fOVEkFb=lbJlfT[;@_ShYSB=nbEKnkk=Wf0P_7c\Zf:je<aU]h2SbF8_<o2?^;\niJ`G:KaNFPoeZO3DXA\AHh;A0X]fCeTGfFQniZF161`a X-Complaints-To: staff@sunsite.dk