
Is there a version of fold where the lambda is passed a copy of the list as well as the index position of the current item?

Or is that better done as a general recursive function?

(basically the reduce from JS)

@slack1 for the index of the list, you can use sequence-fold
or for/fold
with in-indexed
. for the copy of the list part… I’m not sure why you would want that, since the list will be in scope where you call foldl
, since lambdas are closures.

so if your list is called lst
, you can just write (foldl (lambda (x acc) #\| lst is in-scope in here \|#) init lst)

ah I see, thanks!

my motivation was a compare-multiple-sequential-items problem

you probably don’t want to use the index for that. lists are not random-access, so getting an element by index is O(n)

maybe it would make sense to use some sort of sliding window sequence instead?

oh I see, vector has no fold equivilent

you could use in-vector
with for/fold
or sequence-fold

ah thanks for the directions

looking into them slowly…