6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat May 11, 2024 11:44 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sun Dec 02, 2018 9:30 pm 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 247
I'm currently implementing SET-ORDER in Tali Forth 2. The ANS 2012 standard says at https://forth-standard.org/standard/search/SET-ORDER the following:

Quote:
SET-ORDER ( widn ... wid1 n -- )
Set the search order to the word lists identified by widn ... wid1. Subsequently, word list wid1 will be searched first, and word list widn searched last. If n is zero, empty the search order. If n is minus one, set the search order to the implementation-defined minimum search order. The minimum search order shall include the words FORTH-WORDLIST and SET-ORDER. A system shall allow n to be at least eight.

For -1 as the input, I'm just setting FORTH-WORDLIST as the 1 wordlist, as it contains both FORTH-WORDLIST and SET-ORDER as the standard dictates. This is my "minimum search order".

My question has to do with passing 0 for n (with no wordlist IDs). The standard is saying to empty the search order, but wouldn't that make all the words disappear? My thought is that, in this particular case, the minimum search order would also make sense... but the comment for the minimum search order looks like it only applies to -1 on the stack.

The example implementation (available at the above link) seems to simply empty the entire search order, and that's currently what my code does as well. That seems like a mean thing to do to a user, but Forth is very much a no-training-wheels kind of language, and technically they asked for it if they typed "0 SET-ORDER".

I'm curious what others think of this situation and what the best behavior might be.


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 03, 2018 12:09 am 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
I think that the distinction between a "minimal" search order and an "empty" search order is, and must be, significant. If the search order is "minimal", there's still a wordlist there, since it must include at least FORTH-WORDLIST and SET-ORDER. If there are no wordlists in the search order, no words can be found.

I shall also take the position that -1 SET-ORDER (to set a minimal search order) should leave an entry on the stack, preferably -1. Justification: ( widn ... wid1 n -- ) absorbs n wordlists, and n. If n is zero, it absorbs zero wordlists and n. If n is -1, it clearly _produces_ a stack entry after removing n, and that stack entry might as well be n. Counterarguments appreciated.


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 03, 2018 1:34 am 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 247
nyef wrote:
I shall also take the position that -1 SET-ORDER (to set a minimal search order) should leave an entry on the stack, preferably -1. Justification: ( widn ... wid1 n -- ) absorbs n wordlists, and n. If n is zero, it absorbs zero wordlists and n. If n is -1, it clearly _produces_ a stack entry after removing n, and that stack entry might as well be n. Counterarguments appreciated.


:lol: I like your thought that -1 should "remove" -1 items from the stack, thereby leaving one. It took me a couple of minutes to figure out what you were talking about.

The example implementation they give is:
Code:
: SET-ORDER ( wid1 ... widn n -0 )
   DUP -1 = IF
     DROP <push system default word lists and n>
   THEN
   DUP #order !
   0 ?DO I CELLS context + ! LOOP
;

It looks like they are just using the -1 as a flag, replacing it with whatever wordlists (more than 1 seems to be allowed) and an appropriate n before the code continues processing the normal way. #order is a variable holding the number of wordlists in the search order, and context is an array that holds the wids (Wordlist IDentifiers).

If you do set 0 wordlists in the search order, then every word you type after that point is undefined, right? There's no way to fix that except to reset the system. That's the part that I'm having trouble with, but it seems like the standard calls for that behavior (if the user asks for it, of course).


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 03, 2018 1:59 am 
Offline

Joined: Sun Jul 28, 2013 12:59 am
Posts: 235
It might not be particularly useful to leave the system with no wordlists in the search order, but that doesn't mean that it might not be useful for the system to be in such a state temporarily, especially in the context of implementing some higher-level vocabulary mechanism. And the SEARCH-ORDER word set was defined (per the dpans94 rationale) as a primitive set from which various other schemes could be defined.


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 05, 2018 1:33 am 
Offline

Joined: Sun May 13, 2018 5:49 pm
Posts: 247
That makes a little more sense to me, nyef. A compiled word has already looked up all of it's words; it could temporarily remove all of the wordlists from the search order while it's running, as long as it put something back before it went back to interactive mode (if it ever goes back to interactive mode). Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Wed Dec 05, 2018 3:59 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
That's the way I read it too.

I you accidentally end up with an empty word search order, you're pretty much out of luck and need to restart your system. In that state, all you can theoretically do is put numbers on the stack.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 15, 2018 8:48 am 
Offline

Joined: Mon Jan 07, 2013 2:42 pm
Posts: 576
Location: Just outside Berlin, Germany
I'm sorry to say this, and I recognize there was lots of historical baggage that the ANS people had to deal with, but the whole wordlist structure of ANS Forth is too complicated and downright nuts. It's no wonder people still use vocabulary. Gforth makes it a little better with >order (https://www.complang.tuwien.ac.at/forth ... Lists.html) which puts a wid at the top of the search order.

Now admittedly, the fact that you can crash your system with the suicide sequence 0 set-order is very useful if you have a nuclear missile silo programmed in ANS Forth and Dr. No is about to break into the control room. I'm at a loss for other uses, though. And don't get me started on the fact that order displays the wordlist order in the exact opposite way of the normal stack notation, that is, top wordlist on the left.

Thank you, I feel better now. It's probably best that Sam is taking care of the wordlist stuff for Tali Forth, not me. :D


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 16, 2018 7:42 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 858
scotws wrote:
I'm sorry to say this, and I recognize there was lots of historical baggage that the ANS people had to deal with, but the whole wordlist structure of ANS Forth is too complicated and downright nuts. It's no wonder people still use vocabulary

One of the reasons I still use Forth-83.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: