As usual I didn't read the manual which is a little bit cryptic for a non
native speaker.
The signature of fodl is ('a -> 'b -> 'b) -> 'b -> 'a list -> 'b
I was used to the signature of List.fold_left of OCaml where the signature
is : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
The arguments are rev
Jens answered your question, but I'll note two convenient shorthands:
> #lang racket
> (require racket/format)
racket/format is provided by #lang racket, so you can skip that.
This:
(define fp
(lambda (s n)
(string-append (pp_number n) " + " s)))
is the same as this:
(define (fp s n)
Try reversing the order for arguments for both fp and f.
/Jens Axel
Den tir. 14. dec. 2021 kl. 19.48 skrev Cyrille DEUSS <
cyrille.de...@gmail.com>:
> #lang racket
> (require racket/format)
>
> (define pp_number
> (lambda (n)
> (~a n #:width 6 #:align 'right #:left-pad-string "0")))
>
>
#lang racket
(require racket/format)
(define pp_number
(lambda (n)
(~a n #:width 6 #:align 'right #:left-pad-string "0")))
(define fp
(lambda (s n)
(string-append (pp_number n) " + " s)))
(define f
(lambda (s n)
(format "~a + ~a" n s)))
(foldl f "" '(1 2 3))
; works great !
4 matches
Mail list logo