Paste: Syntax for trivial incremental constants
Author: | nomennescio |
Mode: | factor |
Date: | Sun, 16 Jan 2022 23:01:52 |
Plain Text |
USING: kernel lexer math parser words.constant ;
IN: indices
SYNTAX: INDEX: 0 ";" [ create-word-in over define-constant 1 + ] each-token drop ;
Author: | nomennescio |
Mode: | factor |
Date: | Sun, 16 Jan 2022 23:09:37 |
Plain Text |
SYNTAX: +INDEX: scan-number ";" [ create-word-in over define-constant 1 + ] each-token drop ;
Author: | nomennescio |
Mode: | factor |
Date: | Sun, 16 Jan 2022 23:14:32 |
Plain Text |
USING: kernel lexer math parser words.constant ;
IN: indices
: (create-indices) ( n -- m ) ";" [ create-word-in over define-constant 1 + ] each-token ;
SYNTAX: INDEX: 0 (create-indices) drop ;
SYNTAX: +INDEX: scan-number (create-indices) drop ;
Author: | nomennescio |
Mode: | factor |
Date: | Mon, 17 Jan 2022 10:15:06 |
Plain Text |
One could argue the 0 based index would be the exceptional situation, and having a numerical argument the base case.
The following reflect that in their naming
SYNTAX: 0INDEX: 0 (create-indices) drop ;
SYNTAX: INDEX: scan-number (create-indices) drop ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 18 Jan 2022 04:14:24 |
Plain Text |
Given the common cases of 0 or 1 based indices, one could say a single version of the word which always has a numerical argument would suffice.
INDEX: 0 zero one two three four five six seven eight nine ;
INDEX: 0 sunday monday tuesday wednesday thursday friday saturday ;
As an alternative name, John Benediktsson suggested INDEX-FROM: for +INDEX
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 18 Jan 2022 04:35:08 |
Plain Text |
SYNTAX: INDEX0: 0 (create-indices) drop ;
SYNTAX: INDEX1: 1 (create-indices) drop ;
SYNTAX: INDEX: scan-number (create-indices) drop ;
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 3 Oct 2023 11:01:32 |
Plain Text |
INDEX: sunday monday tuesday wednesday thursday friday saturday ;
\ sunday present
->
"sunday"
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 3 Oct 2023 11:14:30 |
Plain Text |
IN: your-vocab
INDEX: sunday monday tuesday wednesday thursday friday saturday ;
: >index ( string -- index )
manifest get current-vocab>> lookup-word ;
"sunday" >index
->
sunday
Author: | nomennescio |
Mode: | factor |
Date: | Tue, 3 Oct 2023 11:42:16 |
Plain Text |
"sunday" search
->
sunday
New Annotation