小编Gam*_*r41的帖子

Racket Iterate over list and get Index

Im learning Racket and have some troubles.

I want to iterate over a list and find the index of some value. I have the following code:

(define (index list entry)
  (define index 0)
  (for ([i list])
    #:break (equal? i entry)
    (+ index 1))
    index)
Run Code Online (Sandbox Code Playgroud)

But the function always returns 0. Can anyone point out my mistake?

I know that there are functions for that, but I want to learn the syntax.

functional-programming racket

5
推荐指数
1
解决办法
339
查看次数

标签 统计

functional-programming ×1

racket ×1