Hacker News new | ask | show | jobs
by Y_Y 682 days ago

    ~ $ racket -I rhombus
    Welcome to Racket v8.13 [bc].
    > fun is_sorted(list):
        match list:
        | []: #true
        | [_]: #true
        | [head, next, ...]:
            head .<= next && is_sorted([next, ...])

    ; readline-input:6:19: next: cannot use repetition binding as an expression
    ;   in: next
    ; [,bt for context]

From there I got to "repetition binding" in the docs: https://plt.cs.northwestern.edu/pkg-build/doc/rhombus/Repeti...

From what I can understand, the "..." isn't independent of the previous expression in the list (as I would have expected from e.g. Prolog or Haskell). Instead you are defining a kind of pattern to reuse later, so tail gives a name to the rest of the list (so that it doesn't get associated with next).

1 comments

Ah, now that makes sense, the three dots need to be assigned to a variable. It's just how they do it is completely new to me. Thank you for finding out!