Is there a split-at-reverse anywhere, equivalent to split-at except that the
first return value is reversed?
If not, should that be added somewhere like srfi/1?
I’m asking because wanted to be able to write functions like:
(define ((drop-lens n) lst)
(define-values [fst-lst rst-lst]
As it turns out, this is a perfect application for my persistent vectors
library. I used the following test harness, matching your examples and using
the more “elegant” style of tackling the problem using for loops. I think the
performance speaks for itself.
#lang racket/base
(require
On 19/06/2015 21:24, Luke Miles wrote:
Say I have a list ls and I want to produce a list of
lists where the i'th list has the i'th element of ls tripled,
but all other elements are the same.
e.g. '(3 5 7) = '((9 5 7) (3 15 7) (3 5 21))
What is a fast way to do this?
I could do a loop with
A more efficient version using append-reverse from srfi/1.
#lang racket
(require (only-in srfi/1 append-reverse))
(define (list-splits xs)
(define (loop ys zs) ; xs = (append (reverse ys) yz)
(match zs
['() '()]
[(cons z zs*) (cons (list ys zs)
It's unlikely that an implementation using continuations would be
faster than one that does not.
An idiomatic solution might look like:
(define (map-once fn xs)
(for/list ([i (in-range (length xs))])
(for/list ([(x j) (in-indexed (in-list xs))])
(cond [(= i j) (fn x)]
#lang racket
(define (list-splits xs)
(define (loop ys zs) ; xs = (append (reverse ys) yz)
(match zs
['() '()]
[(cons z zs*) (cons (list ys zs)
(loop (cons z ys) zs*))]))
(loop '() xs))
(define (map-once f xs)
(for/list ([ys+zs
Say I have a list ls and I want to produce a list of
lists where the i'th list has the i'th element of ls tripled,
but all other elements are the same.
e.g. '(3 5 7) = '((9 5 7) (3 15 7) (3 5 21))
What is a fast way to do this?
I could do a loop with appending.
(define (map-once f ls)
(let M
7 matches
Mail list logo