Simple database: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 575:
 
=={{header|Forth}}==
Simple in-memory database. Load/dump database from/to a file.
 
Works in GNU Forth 0.7.0 shell. Example file `test.sdb':
 
+: betty 1974.03.03;coworker;reading;
 
+: geea 1980.01.01;friend;sketch writer;
 
+: tom 1991.03.07;family member;reading;
 
+: alice 1987.09.01;coworker;classical music;
 
+: gammaQ3.14 3045.09.09;friend;watch movies, star walking;
Line 652 ⟶ 653:
wordlist constant SDB \ DB keys
wordlist constant FIELDS \ DB fields
 
: -SDB?EXIT ( -- ; Continue if `SDB' non-empty )
SDB cell+ @ 0= IF rdrop exit THEN ;
 
\ MACROS
Line 710 ⟶ 714:
 
: _sdb-walk ( MACRO: | xt[--] -- | )
]] -SDB?EXIT here dup SDB cell+
LIST I name>int swap !+ LOOP-LIST [[ 1 cells ]] literal -
DO I @ |comp| [[ -1 cells ]] literal +LOOP [[ ; immediate
 
2variable category
: msg_nocategory ( -- )
." No such category!" cr ;
 
\ --- USER definitions
Line 730 ⟶ 738:
IF name>int execute .record ELSE drop THEN ;
 
2variable category
: .lastbycategory ( "field-name" -- )
here 0 category 2! parse-name FIELDS search-wordlist
Line 738 ⟶ 745:
IF .record cr dup execute 2@ category 2@ ($+) category 2! THEN
LOOP-LIST drop
ELSE cr['] ."msg_nocategory Nostderr such category!" crOUTFILE-EXECUTE THEN ;
 
: .bydate ( -- )