const -> let

This commit is contained in:
ProgramSnail 2023-07-03 19:05:50 +03:00
parent 3ae6ed079d
commit 189306df26
33 changed files with 406 additions and 285 deletions

View file

@ -30,15 +30,15 @@ def find-prefix-hashes : str = {
alias \hash = \acc-hash[char]
decl find-substring : \string -> \string -> \array[index]
decl find-substring : ::str \string -> ::substr \string -> \array[index]
def find-substring : str substr = {
var result = \array[index]..empty:
const str-hashes = find-prefix-hashes:[hash] str
const substr-hash = \hash..of: substr
let str-hashes = find-prefix-hashes:[hash] str
let substr-hash = \hash..of: substr
for i in 0--(str-hashes..size: - substr..size:) do {
const part-hash = hash..diff: str-hashes`(i + substr..size:) str-hashes`i
let part-hash = hash..diff: str-hashes`(i + substr..size:) str-hashes`i
if part-hash == substr-hash then {
; result..push: i
@ -60,3 +60,9 @@ def mul : x y = x * y
decl mul-10 : \int -> \int
def mul-10 = mul: 10
exec main {
; find-substring:
::str "abacaba"
::substr "bac"
}