Paste: Syntax for trivial incremental constants

Author: nomennescio factor Sun, 16 Jan 2022 23:01:52
Plain Text |
```! 2022 nomennescio
USING:  kernel lexer math parser words.constant ;
IN: indices

SYNTAX: INDEX: 0 ";" [ create-word-in over define-constant 1 + ] each-token drop ;

! usage:
! INDEX: zero one two three four five six seven eight nine ;
! INDEX: sunday monday tuesday wednesday thursday friday saturday ;

! idea for additional words : "+INDEX:" to start counting from an offset```

Annotation: +INDEX: definition

Author: nomennescio factor Sun, 16 Jan 2022 23:09:37
Plain Text |
```SYNTAX: +INDEX: scan-number ";" [ create-word-in over define-constant 1 + ] each-token drop ;

! usage :
! +INDEX: 0 zero one two three four five six seven eight nine ;```

Annotation: refactor

Author: nomennescio factor Sun, 16 Jan 2022 23:14:32
Plain Text |
```! 2022 nomennescio
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 ;

! usage:
! INDEX: zero one two three four five six seven eight nine ;
! INDEX: sunday monday tuesday wednesday thursday friday saturday ;

! usage :
! +INDEX: 0 zero one two three four five six seven eight nine ;```

Annotation: Relabeling?

Author: nomennescio factor 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 ;```

Annotation: Always have numeric argument?

Author: nomennescio factor 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```

Annotation: More alternative names

Author: nomennescio factor 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 ;```

Annotation: Get strings from indices

Author: nomennescio factor Tue, 3 Oct 2023 11:01:32
Plain Text |
```INDEX: sunday monday tuesday wednesday thursday friday saturday ;
\ sunday present

->
"sunday"```

Annotation: Conversion: Get indinces from strings

Author: nomennescio factor Tue, 3 Oct 2023 11:14:30
Plain Text |
```IN: your-vocab

INDEX: sunday monday tuesday wednesday thursday friday saturday ;

! the current vocab is a bit cumbersome
: >index ( string -- index )
manifest get current-vocab>> lookup-word ;

"sunday" >index

->
sunday```

Annotation: Conversion: Get indices from strings (alternative)

Author: nomennescio factor Tue, 3 Oct 2023 11:42:16
Plain Text |
```! only works in parsing words
"sunday" search

->
sunday
```