User Tools

Site Tools


en:pfw:library

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:pfw:library [2024-09-04 13:04] – [The viewer] willemen:pfw:library [2025-02-06 17:59] (current) – [A library for Forth] willem
Line 1: Line 1:
 ====== A library for Forth ====== ====== A library for Forth ======
 +
 +*W.O.*
  
  
Line 9: Line 11:
 The interface consists of the following word: ''%%NEED%%'' The interface consists of the following word: ''%%NEED%%''
  
-  * ''%%NEED%%''  ''%%( "name" -- i*x )%%'' Make sure “name” is present in the dictionary. If not, load it from a library. If "name" already exists, do nothing.+  * ''%%NEED%%''  ''%%( i*x "name" -- j*x )%%'' Make sure “name” is present in the dictionary. If not, load it from a library. If "name" already exists, do nothing.
  
 An optional word as suggested by Ulrich Hoffmann An optional word as suggested by Ulrich Hoffmann
Line 15: Line 17:
  
 Optional words as suggested by Willem Ouwerkerk Optional words as suggested by Willem Ouwerkerk
-  * ''%%NEEDED%%''  ''%%( a b -- i*x )%%'' Make sure that name represented by the string a b is present in the dictionary. If not, load it from a library. If name already exists, do nothing.+  * ''%%NEEDED%%''  ''%%( i*x a b -- j*x )%%'' Make sure that name represented by the string a b is present in the dictionary. If not, load it from a library. If name already exists, do nothing
 +  * ''%%RUN%%'' ''%%( i*x "name" -- j*x )%%'' Find "name" in the library and load & run the script from a library.
   * ''%%.LIB%%''  ''%%( -- )%%'' Show all section/chapter headers of the current library in one or more columns   * ''%%.LIB%%''  ''%%( -- )%%'' Show all section/chapter headers of the current library in one or more columns
   * ''%%VIEW%%'' ''%%( "name" -- )%%'' View the code from the libary, that belongs to "name".   * ''%%VIEW%%'' ''%%( "name" -- )%%'' View the code from the libary, that belongs to "name".
Line 65: Line 68:
 They act as separators and are not part of the text itself. They act as separators and are not part of the text itself.
  
-The ''%%09%%'' marks the end beginning of a chapter, like this:\\ +The ''%%09%%'' marks the end of a chapter, like this:\\ 
-Note that: The library starts with a dummy ''%%09%%'' so that the first keyword line can be found.\\ + 
-  * ''%%09%%'' chapter-1 ''%%09%%'' chapter-2 ''%%09%%'' last-chapter ''%%09%%''+  * chapter-1 ''%%09%%'' chapter-2 ''%%09%%'' last-chapter ''%%09%%''
  
 The ''%%0D%%'' marks the end of a line:\\ The ''%%0D%%'' marks the end of a line:\\
   * line-1 ''%%0D%%'' line-2 ''%%0D%%'' last-line ''%%0D%%''   * line-1 ''%%0D%%'' line-2 ''%%0D%%'' last-line ''%%0D%%''
  
-The first line of each library chapter starts with case insensitive keyword(s) separated by spaces. The word ''%%CHAPTER%%'' builds this the first line, and provides this line with a+The first line of each library chapter starts with case insensitive keyword. The word ''%%CHAPTER%%'' builds this the first line, and provides this line with a
 backslash to prevent the keywords for being executed while loading a chapter. Then it adds all source code until the ''<nowiki>%%</nowiki>'' marker is found. The end of each chapter is marked by ''%%09%%'' backslash to prevent the keywords for being executed while loading a chapter. Then it adds all source code until the ''<nowiki>%%</nowiki>'' marker is found. The end of each chapter is marked by ''%%09%%''
 The end of the library is kept in a pointer that is updated when we extend the library.\\ The end of the library is kept in a pointer that is updated when we extend the library.\\
Line 113: Line 116:
  
 <code> <code>
-Function: NEEDED   ( a +n -- i*x )+Function: NEEDED   i*x a +n -- j*x )
     a) Save the string a +n and make the string uppercase     a) Save the string a +n and make the string uppercase
     b) If this string is already present in the dictionary, do nothing     b) If this string is already present in the dictionary, do nothing
Line 120: Line 123:
     e) When a keyword is not found issue an error message     e) When a keyword is not found issue an error message
          
-Function: NEED     ( "name" -- i*x )+Function: NEED     i*x "name" -- j*x )
     a) Parse the next word form the input stream and perform the function of NEEDED     a) Parse the next word form the input stream and perform the function of NEEDED
  
Line 276: Line 279:
 </code> </code>
  
-===== The viewer =====+===== viewer for the library ===== 
 + 
 +This viewer shows 16 or less lines at a time. 
 +It stops at a <09> character, prints a divider line and waits for user input. 
 +When the spacebar was hit, it goes on displaying the next chapter. 
 +Any other key leaves the viewer.
  
 <code forth> <code forth>
 ( A library consists of 09 {tab}, 0D {cr} and ASCII chars ) ( A library consists of 09 {tab}, 0D {cr} and ASCII chars )
 ( ranging from blank to ~ others chars are not allowed ) ( ranging from blank to ~ others chars are not allowed )
-v: inside also  definitions \ Show the library source code of a chapter+\ Show the library source code of a chapter
 : .LINE     ( a1 -- a2 ch ) begin c@+ dup BL < 0= while emit repeat ; : .LINE     ( a1 -- a2 ch ) begin c@+ dup BL < 0= while emit repeat ;
-: .DIVIDER  ( -- )          cr  10 for ." -- " next  cr ;+: .DIVIDER  ( -- )          cr  10 0 do ." -- " loop  cr ;
  
 : LIBTYPE   ( a -- ) : LIBTYPE   ( a -- )
Line 295: Line 303:
     repeat  drop ;     repeat  drop ;
  
-v: extra definitions +: VIEW      ( "name" -- )       bl word count  lib-find libtype ; 
-: VIEW      ( ccc -- )          bl-word count  lib-find libtype ; + 
-v: fresh</code>+</code>
 ===== A sample library source ===== ===== A sample library source =====
 This examples shows how many different code parts can be used inside the library.\\ This examples shows how many different code parts can be used inside the library.\\
Line 420: Line 428:
 ==== A little extra ==== ==== A little extra ====
  
-Loading a lot of library code in one go. it is used like this: ''%%need( -rot -2rot d- asm\ )%%''\\+Loading a lot of library code in one go. It must be used like this: ''%%need( -rot -2rot d- asm\ )%%''\\
 Note that ''%%BL-WORD%%'' is a typical noForth word that uses ''%%REFILL%%'' inside, so it can load multiple lines of library words when you need too. Note that ''%%BL-WORD%%'' is a typical noForth word that uses ''%%REFILL%%'' inside, so it can load multiple lines of library words when you need too.
  
en/pfw/library.1725447851.txt.gz · Last modified: 2024-09-04 13:04 by willem