mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2026-01-03 12:48:18 +00:00
const -> let
This commit is contained in:
parent
3ae6ed079d
commit
189306df26
33 changed files with 406 additions and 285 deletions
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue