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
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
(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
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:
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
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)
> ...
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
--- 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
--- 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
--- 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
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 "
11 matches
Mail list logo