laurent.orseau
2020-11-24 09:37:15

split-at


laurent.orseau
2020-11-24 09:41:14

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.


sorawee
2020-11-24 09:45:57

Great idea, but how will #f be useful? If there’re only error and non error variant, a better keyword name IMO is strict?.


sorawee
2020-11-24 09:49:43

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:]).


laurent.orseau
2020-11-24 09:50:43

Yeah, that would work too. I’m also using the 'at-most variant a lot more than the #f one.


laurent.orseau
2020-11-24 09:50:57

(that is, I often define a take-at-most )


laurent.orseau
2020-11-24 09:52:33

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


laurent.orseau
2020-11-24 09:52:47

probably a little too hacky for Racket’s taste though


sorawee
2020-11-24 09:53:51

I really like negative indexing. It’s nice to… not having to write (vector-length ...) or (length ...).


laurent.orseau
2020-11-24 10:12:38

there’s take-right and friends though


chansey97
2020-11-24 20:10:25

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 ))


popa.bogdanp
2020-11-24 20:24:29

Yes, you can do that with a predicate pattern:

(match exp [(? number?) exp])


chansey97
2020-11-24 20:29:04

@popa.bogdanp Thanks!