| Deutsch English Français Italiano |
|
<66e69759$1@news.ausics.net> View for Bookmarking (what is this?) Look up another Usenet article |
Date: Sun, 15 Sep 2024 18:14:17 +1000
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Avoid treating the stack as an array [Re: "Back & Forth" is
back!]
Newsgroups: comp.lang.forth
References: <nnd$61e0ad9a$48ed61c2@b4d945e456041481>
<vasqjd$icjm$1@dont-email.me> <66d26c4b$1@news.ausics.net>
<vaubf7$tbke$1@dont-email.me> <nnd$04cff141$0193ba04@301336b8dd8ed69a>
<vbfqnd$v4c4$1@dont-email.me> <nnd$26b4d59b$27bdb181@ce638e508b04426e>
<87bk0vbvgk.fsf@nightsong.com> <66e0fa58$1@news.ausics.net>
<66e11d64$1@news.ausics.net> <877cbh4b6z.fsf@nightsong.com>
<66e2a497$1@news.ausics.net> <2024Sep14.143207@mips.complang.tuwien.ac.at>
<e29088cacf765cd0da6519e333fa78f1@www.novabbs.com>
<2024Sep14.170836@mips.complang.tuwien.ac.at>
<06f3574dfa63a100a731c944d8e16473@www.novabbs.com>
Content-Language: en-GB
From: dxf <dxforth@gmail.com>
In-Reply-To: <06f3574dfa63a100a731c944d8e16473@www.novabbs.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <66e69759$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 76
X-Complaints: abuse@ausics.net
Path: ...!news.misty.com!weretis.net!feeder9.news.weretis.net!news.bbs.nz!news.ausics.net!not-for-mail
Bytes: 4325
On 15/09/2024 3:13 am, Ahmed wrote:
> On Sat, 14 Sep 2024 15:08:36 +0000, Anton Ertl wrote:
>
>> I wonder if the notation "mf(x;a,b,c)" indicates that a,b,c is a tuble
>> that tends to get passed around without changing it. In that case
>> defining it as a structure in memory and accessing its members there
>> might be a solution.
>
> a, b and are the parameters of the membership function.
> Yes, we can use structures, arrays ...
>
>
>>
>> But OTOH, unless you see programming in Forth as a religious exercise,
>> why worry, as long as your solution works.
>
> I did it without locals as an exercise. Here it is:
>
>
> Without locals:
>
> : tri_mf: ( f: a b c )
> create frot f, fswap f, f,
> does> ( ad_a) ( f: x)
> dup fdup ( ad_a ad_a) ( f: x x)
> f@ ( ad_a) ( f: x x a)
> f>= ( ad_a -1|0) ( f: x)
> over float+ ( ad_a -1|0 ad_b) ( f: x)
> fdup f@ ( ad_a -1|0) ( f: x x b)
> f< and if ( ad_a) ( f: x)
> dup f@ f- ( ad_a) ( f: x-a)
> dup f@ ( ad_a) ( f: x-a a)
> float+ ( ad_b) ( f: x-a a)
> f@ fswap f- ( f: x-a b-a)
> f/ ( f: [x-a]/[b-a])
> exit
> then
> float+ ( ad_b) ( f: x)
> dup fdup ( ad_b ad_b) ( f: x x)
> f@ ( ad_b) ( f: x x b)
> f>= ( ad_b -1|0) ( f: x)
> over float+ ( ad_b -1|0 ad_c) ( f: x)
> fdup f@ ( ad_b -1|0) ( f: x x c)
> f< and if ( ad_b) ( f: x)
> dup float+ f@ ( ad_b) ( f: x c)
> f- ( ad_b) ( f: x-c)
> dup float+ ( ad_b ad_c) ( f: x-c)
> swap f@ f@ f- ( f: x-c b-c)
> f/ ( f: [x-c]/[b-c])
> exit
> then
> drop fdrop
> 0e
> ;
That appears no better than FVALUEs ...
0e fvalue a
0e fvalue b
0e fvalue c
0e fvalue x
: tri_mf() ( f: x a b c -- mv)
to c to b to a to x
x a f>=
x b f< and if
x a f- b a f- f/ exit
then
x b f>=
x c f< and if
c x f- c b f- f/ exit
then
0e
;