Re: [racket-users] Fast way to map over a list many times, changing ONE element each time?

2015-06-26 Thread Alexander D. Knauth
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]

Re: [racket-users] Fast way to map over a list many times, changing ONE element each time?

2015-06-21 Thread Alexis King
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

Re: [racket-users] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Michael Titke
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

Re: [racket-users] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Jens Axel Søgaard
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)

Re: [racket-users] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Jon Zeppieri
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)]

Re: [racket-users] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Jens Axel Søgaard
#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

[racket-users] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Luke Miles
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