Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"When the going gets weird, the weird turn pro..." -- Hunter S. Thompson


devel / comp.lang.forth / Re: conditional parameter passing

SubjectAuthor
* conditional parameter passingKrishna Myneni
+* Re: conditional parameter passingdxforth
|`- Re: conditional parameter passingKrishna Myneni
+* Re: conditional parameter passingPaul Rubin
|+* Re: conditional parameter passingKrishna Myneni
||+- Re: conditional parameter passingMarcel Hendrix
||`* Re: conditional parameter passingAnton Ertl
|| `- Re: conditional parameter passingKrishna Myneni
|`* Re: conditional parameter passingKrishna Myneni
| +- Re: conditional parameter passingKrishna Myneni
| `* Re: conditional parameter passingPaul Rubin
|  `* Re: conditional parameter passingminf...@arcor.de
|   `* Re: conditional parameter passingPaul Rubin
|    +* Re: conditional parameter passingKrishna Myneni
|    |`- Re: conditional parameter passingPaul Rubin
|    `* Re: conditional parameter passingminf...@arcor.de
|     +- Re: conditional parameter passingPaul Rubin
|     +* Re: conditional parameter passingDoug Hoffman
|     |+* Re: conditional parameter passingminf...@arcor.de
|     ||`- Re: conditional parameter passingDoug Hoffman
|     |`* Re: conditional parameter passingKrishna Myneni
|     | `* Re: conditional parameter passingDoug Hoffman
|     |  `- Re: conditional parameter passingKrishna Myneni
|     `* Re: conditional parameter passingKrishna Myneni
|      `* Re: conditional parameter passingdxforth
|       `* Re: conditional parameter passingKrishna Myneni
|        `- Re: conditional parameter passingdxforth
+* Re: conditional parameter passingAnton Ertl
|`* Re: conditional parameter passingKrishna Myneni
| `- Re: conditional parameter passingAnton Ertl
+- Re: conditional parameter passingKrishna Myneni
`- Re: conditional parameter passingminf...@arcor.de

Pages:12
Re: conditional parameter passing

<sdrfk3$eau$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14070&group=comp.lang.forth#14070

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: conditional parameter passing
Date: Wed, 28 Jul 2021 06:38:41 -0500
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <sdrfk3$eau$1@dont-email.me>
References: <sdim55$n0v$1@dont-email.me> <87r1fnnd0r.fsf@nightsong.com>
<sdm34a$q78$1@dont-email.me> <87mtq9nldl.fsf@nightsong.com>
<df8a9523-1dd4-415c-bee5-d669e681b0e0n@googlegroups.com>
<87im0wolcj.fsf@nightsong.com>
<3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
<61008794$0$706$14726298@news.sunsite.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 28 Jul 2021 11:38:43 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="dd4a5a046f1d4f151a1b9754e46fc97e";
logging-data="14686"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Xdvc5nQHFacEF/dtIbD03"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:59pCfW8csUEpGTcVn70hWKyRs3A=
In-Reply-To: <61008794$0$706$14726298@news.sunsite.dk>
Content-Language: en-US
 by: Krishna Myneni - Wed, 28 Jul 2021 11:38 UTC

On 7/27/21 5:24 PM, Doug Hoffman wrote:
> On 7/27/21 4:38 AM, minf...@arcor.de wrote:
>
>> To do that in Forth, the parser of a new word would have to evaluate
>> the stack annotation as necessary part of the word definition. Next step
>> would be a syntax tree in the compiler, etc etc.
>>
>> It wouldn't be Forth anymore.
>
>
> FMS2, ANS Forth extension. I believe it's still Forth.
>
> -Doug
>
>
> 0 ' + i{ 1 2 3 4 5 } :apply . \ => 15 ok
>
....

IIUC, this is not the same as Paul's Lisp example. In that example APPLY
is not iterating the function, the function itself does the iteration,
e.g. in Lisp one can write

(+ 1 2)

or

(+ 1 2 3 4 5)

so the Lisp example of

(apply #'+ '(1 2 3))

is performing

(+ 1 2 3)

However, the number of arguments passed to + are determined at run-time
rather than at compile-time, since one can use a variable to represent
the list, e.g.

(apply #'+ x)

and + performs the iteration over the list elements of x, not APPLY.

(setq x '(1 2 3))
(apply #'+ x)
(setq x '(1 2 3 4 5))
(apply #'+ x)

-- Krishna

Re: conditional parameter passing

<610148a7$0$700$14726298@news.sunsite.dk>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14071&group=comp.lang.forth#14071

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail
Subject: Re: conditional parameter passing
Newsgroups: comp.lang.forth
References: <sdim55$n0v$1@dont-email.me> <87r1fnnd0r.fsf@nightsong.com>
<sdm34a$q78$1@dont-email.me> <87mtq9nldl.fsf@nightsong.com>
<df8a9523-1dd4-415c-bee5-d669e681b0e0n@googlegroups.com>
<87im0wolcj.fsf@nightsong.com>
<3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
<61008794$0$706$14726298@news.sunsite.dk> <sdrfk3$eau$1@dont-email.me>
From: dhoffman...@gmail.com (Doug Hoffman)
Date: Wed, 28 Jul 2021 08:08:02 -0400
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0)
Gecko/20100101 Thunderbird/78.12.0
MIME-Version: 1.0
In-Reply-To: <sdrfk3$eau$1@dont-email.me>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Lines: 61
Message-ID: <610148a7$0$700$14726298@news.sunsite.dk>
Organization: SunSITE.dk - Supporting Open source
NNTP-Posting-Host: 3382ae06.news.sunsite.dk
X-Trace: 1627474087 news.sunsite.dk 700 glidedog@gmail.com/68.55.82.126:51763
X-Complaints-To: staff@sunsite.dk
 by: Doug Hoffman - Wed, 28 Jul 2021 12:08 UTC

On 7/28/21 7:38 AM, Krishna Myneni wrote:
> On 7/27/21 5:24 PM, Doug Hoffman wrote:
>> On 7/27/21 4:38 AM, minf...@arcor.de wrote:
>>
>>> To do that in Forth, the parser of a new word would have to evaluate
>>> the stack annotation as necessary part of the word definition. Next step
>>> would be a syntax tree in the compiler, etc etc.
>>>
>>> It wouldn't be Forth anymore.
>>
>>
>> FMS2, ANS Forth extension. I believe it's still Forth.
>>
>> -Doug
>>
>>
>> 0 ' + i{ 1 2 3 4 5 } :apply . \ => 15 ok
>>
> ...
>
> IIUC, this is not the same as Paul's Lisp example. In that example APPLY
> is not iterating the function, the function itself does the iteration,
> e.g. in Lisp one can write
>
> (+ 1 2)

I don't know Lisp so I can't comment.

....

> However, the number of arguments passed to + are determined at run-time
> rather than at compile-time,

FMS determines the number of arguments at run-time,
not at compile time. The lists are dynamically resizable.

> since one can use a variable to represent
> the list, e.g.

All objects fit in one cell in FMS so it is simple to use a variable:

i{ 1 2 3 4 5 } value x
: go ( -- sum) 6 x :add 0 ['] + x :apply ;
go . \ => 21 ok

But yes, FMS is not Lisp, if that is your point.

-Doug

> (apply #'+ x)
>
> and + performs the iteration over the list elements of x, not APPLY.
>
> (setq x '(1 2 3))
> (apply #'+ x)
> (setq x '(1 2 3 4 5))
> (apply #'+ x)
>
> -- Krishna
>

Re: conditional parameter passing

<sdssfi$b42$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14084&group=comp.lang.forth#14084

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: conditional parameter passing
Date: Wed, 28 Jul 2021 19:24:16 -0500
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <sdssfi$b42$1@dont-email.me>
References: <sdim55$n0v$1@dont-email.me> <87r1fnnd0r.fsf@nightsong.com>
<sdm34a$q78$1@dont-email.me> <87mtq9nldl.fsf@nightsong.com>
<df8a9523-1dd4-415c-bee5-d669e681b0e0n@googlegroups.com>
<87im0wolcj.fsf@nightsong.com>
<3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
<61008794$0$706$14726298@news.sunsite.dk> <sdrfk3$eau$1@dont-email.me>
<610148a7$0$700$14726298@news.sunsite.dk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 29 Jul 2021 00:24:18 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f329095f045b1457a2c97c1c75e0b637";
logging-data="11394"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2V7JbmfMnHX1eWCnkC2Hv"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:xsCjoUx0yXAjY/S7sgIV44xOyEo=
In-Reply-To: <610148a7$0$700$14726298@news.sunsite.dk>
Content-Language: en-US
 by: Krishna Myneni - Thu, 29 Jul 2021 00:24 UTC

On 7/28/21 7:08 AM, Doug Hoffman wrote:
> On 7/28/21 7:38 AM, Krishna Myneni wrote:
>> On 7/27/21 5:24 PM, Doug Hoffman wrote:
>>> On 7/27/21 4:38 AM, minf...@arcor.de wrote:
>>>
>>>> To do that in Forth, the parser of a new word would have to evaluate
>>>> the stack annotation as necessary part of the word definition. Next
>>>> step
>>>> would be a syntax tree in the compiler, etc etc.
>>>>
>>>> It wouldn't be Forth anymore.
>>>
>>>
>>> FMS2, ANS Forth extension. I believe it's still Forth.
>>>
>>> -Doug
>>>
>>>
>>> 0 ' + i{ 1 2 3 4 5 } :apply . \ => 15 ok
>>>
>> ...
>>
>> IIUC, this is not the same as Paul's Lisp example. In that example
>> APPLY is not iterating the function, the function itself does the
>> iteration, e.g. in Lisp one can write
>>
>> (+ 1 2)
>
> I don't know Lisp so I can't comment.
>
> ...
>
>> However, the number of arguments passed to + are determined at
>> run-time rather than at compile-time,
>
> FMS determines the number of arguments at run-time,
> not at compile time. The lists are dynamically resizable.
>

Yes, but your :APPLY is most likely just taking two parameters off the
stack and not passing the list elements all at once on the stack to the
function, which is the example that Paul gave, so I think it has no
relevance to the current discussion about passing a variable number of
parameters on the Forth stack to a given word.

Krishna

Re: conditional parameter passing

<sdu2pn$1dn$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14087&group=comp.lang.forth#14087

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: conditional parameter passing
Date: Thu, 29 Jul 2021 06:18:13 -0500
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <sdu2pn$1dn$1@dont-email.me>
References: <sdim55$n0v$1@dont-email.me> <87r1fnnd0r.fsf@nightsong.com>
<sdm34a$q78$1@dont-email.me> <87mtq9nldl.fsf@nightsong.com>
<df8a9523-1dd4-415c-bee5-d669e681b0e0n@googlegroups.com>
<87im0wolcj.fsf@nightsong.com>
<3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 29 Jul 2021 11:18:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f329095f045b1457a2c97c1c75e0b637";
logging-data="1463"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pHSOybCCp+lIcjY9uz+OF"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:W0qOn06uk0ssKISvuBDmqEemXvw=
In-Reply-To: <3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
Content-Language: en-US
 by: Krishna Myneni - Thu, 29 Jul 2021 11:18 UTC

On 7/27/21 3:38 AM, minf...@arcor.de wrote:
> Paul Rubin schrieb am Montag, 26. Juli 2021 um 22:45:35 UTC+2:
>> "minf...@arcor.de" <minf...@arcor.de> writes:
>>>> (apply #'+ '(1 2 3)) => returns 6 ...
>>> That must have been said with tongue in cheek. ;-)
>>> FWIW my Forth can do
>>> m[ 1 2 ; 5 7 ] minv
>> I don't understand about tongue and cheek? '(1 2 3) is not passed to +
>> as a list, it is passed as args. (apply #'cons '(1 2)) is the same as
>> (cons 1 2). Cons takes exactly two args and (apply #'cons (1 2 3))
>> would throw a error from cons, because of the wrong arg count.
>
> https://dictionary.cambridge.org/de/worterbuch/englisch/tongue-in-cheek
>
> To do that in Forth, the parser of a new word would have to evaluate
> the stack annotation as necessary part of the word definition. Next step
> would be a syntax tree in the compiler, etc etc.
>
> It wouldn't be Forth anymore.
>

Yes, I agree it would not be Forth anymore if variable length parameter
lists required that kind of additional support, but it's not necessary.
One can pass variable length parameters in standard Forth. The trivial
kind of variable length parameter passing in Forth is where the
parameter count is specified on the stack, in addition to the remaining
parameters being passed.

: sumn ( m1 m2 ... mn n -- sum )
1- 0 ?DO + LOOP ;

2 3 4 5 6 5 sumn .

Another example is initializing an array from the stack.

create a1 5 cells allot

init-array ( m1 ... mn n addr -- )

2 3 4 5 6 5 a1 init-array

It is easy to implement these cases with a simple loop. Other cases may
require simple relational test(s) of a parameter on top of the stack.

In the general case, a word which takes a variable number, and type, of
arguments on the stack can be written by mapping a fixed number of
parameters on top of the stack, typically just one additional parameter
on top, to the number, type, and ordering of parameters to be consumed
by the word.

I'm not suggesting that one should program in this way. There are
special instances, for example, when two words deal with nearly the same
arguments, and have nearly identical functions and meaning, but have
only a slight difference in what they do. This was the example in my
original post.

--
Krishna

Re: conditional parameter passing

<sdu60g$1t89$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14089&group=comp.lang.forth#14089

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: conditional parameter passing
Date: Thu, 29 Jul 2021 22:13:04 +1000
Organization: Aioe.org NNTP Server
Message-ID: <sdu60g$1t89$1@gioia.aioe.org>
References: <sdim55$n0v$1@dont-email.me> <87r1fnnd0r.fsf@nightsong.com>
<sdm34a$q78$1@dont-email.me> <87mtq9nldl.fsf@nightsong.com>
<df8a9523-1dd4-415c-bee5-d669e681b0e0n@googlegroups.com>
<87im0wolcj.fsf@nightsong.com>
<3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
<sdu2pn$1dn$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="62729"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Thu, 29 Jul 2021 12:13 UTC

On 29/07/2021 21:18, Krishna Myneni wrote:
> On 7/27/21 3:38 AM, minf...@arcor.de wrote:
>> Paul Rubin schrieb am Montag, 26. Juli 2021 um 22:45:35 UTC+2:
>>> "minf...@arcor.de" <minf...@arcor.de> writes:
>>>>> (apply #'+ '(1 2 3)) => returns 6 ...
>>>> That must have been said with tongue in cheek. ;-)
>>>> FWIW my Forth can do
>>>> m[ 1 2 ; 5 7 ] minv
>>> I don't understand about tongue and cheek? '(1 2 3) is not passed to +
>>> as a list, it is passed as args. (apply #'cons '(1 2)) is the same as
>>> (cons 1 2). Cons takes exactly two args and (apply #'cons (1 2 3))
>>> would throw a error from cons, because of the wrong arg count.
>>
>> https://dictionary.cambridge.org/de/worterbuch/englisch/tongue-in-cheek
>>
>> To do that in Forth, the parser of a new word would have to evaluate
>> the stack annotation as necessary part of the word definition. Next step
>> would be a syntax tree in the compiler, etc etc.
>>
>> It wouldn't be Forth anymore.
>>
>
> Yes, I agree it would not be Forth anymore if variable length parameter
> lists required that kind of additional support, but it's not necessary.
> One can pass variable length parameters in standard Forth. The trivial
> kind of variable length parameter passing in Forth is where the
> parameter count is specified on the stack, in addition to the remaining
> parameters being passed.
>
> : sumn ( m1 m2 ... mn n -- sum )
> 1- 0 ?DO + LOOP ;
>
> 2 3 4 5 6 5 sumn .
>
> Another example is initializing an array from the stack.
>
> create a1 5 cells allot
>
> init-array ( m1 ... mn n addr -- )
>
> 2 3 4 5 6 5 a1 init-array
>
> It is easy to implement these cases with a simple loop. Other cases may
> require simple relational test(s) of a parameter on top of the stack.
>
> In the general case, a word which takes a variable number, and type, of
> arguments on the stack can be written by mapping a fixed number of
> parameters on top of the stack, typically just one additional parameter
> on top, to the number, type, and ordering of parameters to be consumed
> by the word.
>
> I'm not suggesting that one should program in this way. There are
> special instances, for example, when two words deal with nearly the same
> arguments, and have nearly identical functions and meaning, but have
> only a slight difference in what they do. This was the example in my
> original post.

Not sure the above examples represent anything new. Their equivalent
can't be written in other languages? The parameter list would be
passed as an address (how those languages work) but how is that bad?

Re: conditional parameter passing

<sdu7vk$2tn$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14090&group=comp.lang.forth#14090

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: krishna....@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: conditional parameter passing
Date: Thu, 29 Jul 2021 07:46:42 -0500
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <sdu7vk$2tn$1@dont-email.me>
References: <sdim55$n0v$1@dont-email.me> <87r1fnnd0r.fsf@nightsong.com>
<sdm34a$q78$1@dont-email.me> <87mtq9nldl.fsf@nightsong.com>
<df8a9523-1dd4-415c-bee5-d669e681b0e0n@googlegroups.com>
<87im0wolcj.fsf@nightsong.com>
<3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
<sdu2pn$1dn$1@dont-email.me> <sdu60g$1t89$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 29 Jul 2021 12:46:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f329095f045b1457a2c97c1c75e0b637";
logging-data="2999"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pqoiIeE6UroVENX2lbc0g"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:V+cJmZWmvSQk4UmUxtKvzBfTjcg=
In-Reply-To: <sdu60g$1t89$1@gioia.aioe.org>
Content-Language: en-US
 by: Krishna Myneni - Thu, 29 Jul 2021 12:46 UTC

On 7/29/21 7:13 AM, dxforth wrote:
> On 29/07/2021 21:18, Krishna Myneni wrote:
>> On 7/27/21 3:38 AM, minf...@arcor.de wrote:
>>> Paul Rubin schrieb am Montag, 26. Juli 2021 um 22:45:35 UTC+2:
>>>> "minf...@arcor.de" <minf...@arcor.de> writes:
>>>>>> (apply #'+ '(1 2 3)) => returns 6 ...
>>>>> That must have been said with tongue in cheek. ;-)
>>>>> FWIW my Forth can do
>>>>> m[ 1 2 ; 5 7 ] minv
>>>> I don't understand about tongue and cheek? '(1 2 3) is not passed to +
>>>> as a list, it is passed as args. (apply #'cons '(1 2)) is the same as
>>>> (cons 1 2). Cons takes exactly two args and (apply #'cons (1 2 3))
>>>> would throw a error from cons, because of the wrong arg count.
>>>
>>> https://dictionary.cambridge.org/de/worterbuch/englisch/tongue-in-cheek
>>>
>>> To do that in Forth, the parser of a new word would have to evaluate
>>> the stack annotation as necessary part of the word definition. Next step
>>> would be a syntax tree in the compiler, etc etc.
>>>
>>> It wouldn't be Forth anymore.
>>>
>>
>> Yes, I agree it would not be Forth anymore if variable length parameter
>> lists required that kind of additional support, but it's not necessary.
>> One can pass variable length parameters in standard Forth. The trivial
>> kind of variable length parameter passing in Forth is where the
>> parameter count is specified on the stack, in addition to the remaining
>> parameters being passed.
>>
>> : sumn ( m1 m2 ... mn n -- sum )
>>       1- 0 ?DO + LOOP ;
>>
>> 2 3 4 5 6 5 sumn .
>>
>> Another example is initializing an array from the stack.
>>
>> create a1 5 cells allot
>>
>> init-array ( m1 ... mn n addr -- )
>>
>> 2 3 4 5 6 5 a1 init-array
>>
>> It is easy to implement these cases with a simple loop. Other cases may
>> require simple relational test(s) of a parameter on top of the stack.
>>
>> In the general case, a word which takes a variable number, and type, of
>> arguments on the stack can be written by mapping a fixed number of
>> parameters on top of the stack, typically just one additional parameter
>> on top, to the number, type, and ordering of parameters to be consumed
>> by the word.
>>
>> I'm not suggesting that one should program in this way. There are
>> special instances, for example, when two words deal with nearly the same
>> arguments, and have nearly identical functions and meaning, but have
>> only a slight difference in what they do. This was the example in my
>> original post.
>
> Not sure the above examples represent anything new.  Their equivalent
> can't be written in other languages?  The parameter list would be
> passed as an address (how those languages work) but how is that bad?

It is not a new technique, but it is also not that common to see in
Forth programs. Of course their equivalents can be written, but not
necessarily by variable argument counts determined at run time and
passed to a function. There is no judgement about passing a parameter
list as an address being made -- it's perfectly acceptable.

The purpose of this discussion was to illustrate that variable parameter
counts are supported by Forth's data stack, as well as other stack-based
languages, and that the parameter counts can be determined at run time,
not at compile time. It allows for word overloading and may have
interesting uses. I don't understand the somewhat defensive nature of
some of the replies here. It's about exploring possibilities.

--
Krishna

Re: conditional parameter passing

<sduj42$di7$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=14092&group=comp.lang.forth#14092

 copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!aioe.org!7AktqsUqy5CCvnKa3S0Dkw.user.46.165.242.75.POSTED!not-for-mail
From: dxfo...@gmail.com (dxforth)
Newsgroups: comp.lang.forth
Subject: Re: conditional parameter passing
Date: Fri, 30 Jul 2021 01:56:49 +1000
Organization: Aioe.org NNTP Server
Message-ID: <sduj42$di7$1@gioia.aioe.org>
References: <sdim55$n0v$1@dont-email.me> <87r1fnnd0r.fsf@nightsong.com>
<sdm34a$q78$1@dont-email.me> <87mtq9nldl.fsf@nightsong.com>
<df8a9523-1dd4-415c-bee5-d669e681b0e0n@googlegroups.com>
<87im0wolcj.fsf@nightsong.com>
<3fa7328f-8593-4455-b725-91ca1a13cf84n@googlegroups.com>
<sdu2pn$1dn$1@dont-email.me> <sdu60g$1t89$1@gioia.aioe.org>
<sdu7vk$2tn$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="13895"; posting-host="7AktqsUqy5CCvnKa3S0Dkw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Content-Language: en-GB
X-Notice: Filtered by postfilter v. 0.9.2
 by: dxforth - Thu, 29 Jul 2021 15:56 UTC

On 29/07/2021 22:46, Krishna Myneni wrote:
> ...
> The purpose of this discussion was to illustrate that variable parameter
> counts are supported by Forth's data stack, as well as other stack-based
> languages, and that the parameter counts can be determined at run time,
> not at compile time. It allows for word overloading and may have
> interesting uses. I don't understand the somewhat defensive nature of
> some of the replies here. It's about exploring possibilities.

When conventional wisdom says don't do at run-time what can be done at
compile-time, it's going to raise eyebrows. OOP gives me hives while
others swear by it. Who am I to judge?

Pages:12
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor