Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <v98sed$kldc$2@dont-email.me>
Deutsch   English   Français   Italiano  
<v98sed$kldc$2@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Ruvim <ruvim.pinka@gmail.com>
Newsgroups: comp.lang.forth
Subject: Re: Juggling system-compilation items
Date: Sun, 11 Aug 2024 03:17:31 +0400
Organization: A noiseless patient Spider
Lines: 116
Message-ID: <v98sed$kldc$2@dont-email.me>
References: <v957nr$jq4q$2@dont-email.me>
 <0ec1b5bb411c30d7598c4d5cae50fcdf@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 11 Aug 2024 01:17:33 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="aeb8ee31ec6e39a8b25b82ab00e99322";
	logging-data="677292"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18aPNDrhbgkW8aIY3Xan/Qg"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:K2FMkL1uj+mKYyeAyTLAaolm2PY=
Content-Language: en-US
In-Reply-To: <0ec1b5bb411c30d7598c4d5cae50fcdf@www.novabbs.com>

On 2024-08-10 12:57, PMF wrote:
> On Fri, 9 Aug 2024 14:05:47 +0000, Ruvim wrote:
> 
>> Do you know a Forth system in which the following definition for "const"
>> is compiled but does not work as expected?
>>
>>
>> : const ( x "<spaces>name" -- )
>>    depth >r          ( x )                   ( R: n.depth )
>>    :                 ( x colon-sys )         ( R: n.depth )
>>    depth r> -        ( x colon-sys n.size )  ( R: )
>>    n>r               ( x )                   ( R: i*x n.size )
>>    postpone literal  (   )                   ( R: i*x n.size )
>>    nr>               ( colon-sys n.size )    ( R: )
>>    drop              ( colon-sys )
>>    postpone ;        (   )
>> ;
>>
>>
>> t{ 123 const foo -> }t
>> t{ foo -> 3 }t
>>
>>
>> Note 3.1.5.1 System-compilation types
>> <https://forth-standard.org/standard/usage#subsubsection.3.1.5.1>
>>
>>
>> -- 
>> Ruvim
> 
> Yes if fails on both my systems lxf and lxf64!
> the reason if fails is that : stores the current depth and ; later
> compares it with the actual
> at that point. This is to catch unmatched loops and conditionals.
> The usual use of >r r> works as intended
> 
> : const >r : r> postpone literal postpone ; ;

Yes, my definition can be implemented simpler, but it is given only for 
illustration and test.


Another use case is to get xt that `:noname` leaves under colon-sys 
(published many times in comp.lang.forth since 2000 [1])

For example:

   : rec: ( "<spaces>name" -- colon-sys )
     defer  depth >r :noname depth r> - 1- roll
     latest-name name> defer!
   ;

   \ Usage example
   rec: fib ( u.index -- u.value )
     dup 2 u< if exit then
     dup 2 - fib swap 1- fib +
   ;

   t{ 0 fib 1 fib 2 fib 3 fib 4 fib -> 0 1 1 2 3 }t


Another real-life example in [2]. Regarding `latest-name` see [3].


Another use case is to factor out a definition builder using a helper 
method like this:

   : build-noname-with ( i*x xt.builder -- j*x xt.new  )
     \ xt.builder ( i*x -- j*x )
     depth >r :noname depth r> - n>r
       execute
     nr> drop postpone ;
   ;

   \ Usage example
   : compose-before ( xt2 xt1 -- xt3 )
     [: compile, compile, ;] build-noname-with
   ;
   : compose ( xt1 xt2 -- xt3 )
     swap compose-before
   ;

   t{ [: 1 ;] [: 2 ;] compose execute -> 1 2 }t



All such techniques are not available if the Forth system does not allow 
the stack depth to be changed between `:` and `;`.

Would you like to see these techniques available to standard programs?



> 
> I think !csp and ?csp are common also in other systems. I certainly did
> not invent them.

Yes, it's a simple method to check the control-flow structures balance 
from the FIG-Forth model.

I would suggest avoiding this method in Forth implementations.




[1] subject: colon-sys and ANS, 2000
<https://groups.google.com/g/comp.lang.forth/c/BU0sVOhxHQo/m/xJ7xXmNjV9YJ>
[2] minos2/md-viewer.fs
<https://github.com/forthy42/gforth/blob/3008f604af74aafd/minos2/md-viewer.fs#L356>
[3] [Proposal] New words: latest-name and latest-name-in
<https://forth-standard.org/proposals/new-words-latest-name-and-latest-name-in?hideDiff#reply-1249>


--
Ruvim