Re: [racket] Calculating cumulative sum of the list

2015-01-22 Thread William James
Using recursion: (define (cum-sums xs) (let run ((xs xs) (sum 0)) (if (null? xs) '() (let ((sum (+ sum (car xs (cons sum (run (cdr xs) sum)) Using map: (define (cum-sums xs) (define sum 0) (define (add x) (set! sum (+ sum x)) sum) (map add xs)) > (cum-sums '(1

Re: [racket] Calculating cumulative sum of the list

2015-01-22 Thread William James
Here's a way using map-accum in Gauche. (use gauche.collection) (define (cumulative-sums xs) (map-accum (lambda (x sum) (values (+ x sum) (+ x sum))) 0 xs)) (cumulative-sums '(1 3 5 7)) ===> (1 4 9 16) On Thu, 1/22/15, Alexandr M wrote: Subjec

Re: [racket] Calculating cumulative sum of the list

2015-01-22 Thread William James
(require srfi/1) (unfold-right null? (curry apply +) cdr (reverse '(1 3 5 7))) ===> '(1 4 9 16) On Thu, 1/22/15, Alexandr M wrote: Subject: [racket] Calculating cumulative sum of the list To: users@racket-lang.org Date: Thursday, January 22, 201

Re: [racket] Define several procedures in a macro

2015-01-22 Thread William James
The old-fashioned way: (require compatibility/defmacro) (defmacro define-instruction (name&args body) (let ((name (car name&args)) (args (cdr name&args)) (body (cdr body))) `(define (,(string->symbol (format "~a-simulation" name)) ,@args) ,@body))) (define-instruction (hello a b c)

[racket] Bug in srfi-42

2015-01-09 Thread William James
Racket bug: Welcome to Racket v6.1.1. > (require srfi/42) > (list-ec (: n 2 8) (if (odd? n)) n) '(3 5 7) > (first-ec #f (: n 2 8) (if (odd? n)) n) stdin::80: :until: expected in in: (if (odd? n)) context...: C:\Program Files\Racket\share\pkgs\srfi-lib\srfi\42\expansion.scm:68:2: gener ator

Re: [racket] Help with simple macro

2012-05-16 Thread William James
On Wed, 5/16/12, Harry Spier wrote: > I'm trying to create a macro to > simplify the syntax of having a local > scope with an indexed sequence generator. > > Instead of entering this: > (let-values ([(more? get next) (sequence-generate > (in-indexed SOME-SEQUENCE)]) >         (get-next) > ...

[racket] match-loop

2012-05-16 Thread William James
Another looping macro. (define-syntax-rule (do-match-loop (sym ...) (pat ...) (lst ...) (expr ...)) (let loop ((sym lst) ...) (when (andmap cons? (list sym ...)) (match-let ((pat sym) ...) (call-with-values (lambda () expr ...) loop) (define-syntax match-loop-aux (sy

Re: [racket] Rationale behind missing string-trim

2012-05-09 Thread William James
--- On Wed, 5/9/12, Chad Albers wrote: > I did write my own string-trim-both function using Racket's > regexp as follows: > > (define (string-trim-both string) > (cadr (regexp-match #px"[\\s]*(\\S+)[\\s]*" string))) Note: emails to this mailing-list should be in plain text. (string-trim-both

Re: [racket] idioms for abstracting over definitions

2012-05-08 Thread William James
--- On Mon, 5/7/12, Patrick Mahoney wrote: > Hello all, in a quest for greater concision, I'm looking for a > way to abstract over the following code containing mostly > definitions. Is there an accepted practice for abstraction over > definition introduction? > > > (define top-right-x > (la

Re: [racket] Wikipedia article update

2012-05-03 Thread William James
--- On Thu, 5/3/12, Hendrik Boom wrote: > From: Hendrik Boom > Subject: Re: [racket] Wikipedia article update > To: users@racket-lang.org > Date: Thursday, May 3, 2012, 8:51 PM > On Thu, May 03, 2012 at 05:02:08PM > -0700, John Clements wrote: > > > > and updated the Wikipedia page to reflect m

Re: [racket] Formatted output of floating-point numbers?

2012-05-01 Thread William James
On Thu, Jan 12, 2012 at 4:53 AM, Dmitry Pavlov wrote: > I have been looking for a way to do in Racket > something you can easily do in C: > > printf("%10.5lf\n", 12.345678); > > so it properly cuts the fractional part to 5 digits > and adds padding to get 10 characters in total, > producing "