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