split-at
Also I’d like take to have something like a keyword #:if-short that can be one of 'error ,#f or 'at-most: If there are fewer elements than what is requested, 'error throws an error (as currently), while 'at-most just returns the list (takes at most n elements) and #f returns #f.
Great idea, but how will #f be useful? If there’re only error and non error variant, a better keyword name IMO is strict?.
I don’t think that’s what @wanpeebaw wants. He wants the slice operation, like xs[beg:end] in Python. split-at on the other hand returns (xs[:i], xs[i:]).
Yeah, that would work too. I’m also using the 'at-most variant a lot more than the #f one.
(that is, I often define a take-at-most )
oh my bad. Yeah, a slice is missing. Also, I like in Python that you can write negative numbers as relative to the end, that’s pretty useful
probably a little too hacky for Racket’s taste though
I really like negative indexing. It’s nice to… not having to write (vector-length ...) or (length ...).
there’s take-right and friends though
Is there way to remove the #:when in the match’s clause? For example, (define (eval exp)
(match exp
[x #:when (number? x) x]
; other cases
)) I’d like to remove the #:when. (define (eval exp)
(match exp
[(number?) exp] ;<--- something like that
; other cases
))
Yes, you can do that with a predicate pattern:
(match exp
[(? number?) exp])
@popa.bogdanp Thanks!