Re: [racket-users] Beginner's question

2021-12-15 Thread Cyrille DEUSS
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 reversed...
Thx

Le mardi 14 décembre 2021 à 20:11:26 UTC+1, Jens Axel Søgaard a écrit :

> Try reversing the order for arguments for both fp and f.
>
> /Jens Axel
>
> Den tir. 14. dec. 2021 kl. 19.48 skrev Cyrille DEUSS  >:
>
>> #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 !
>>
>> (foldl fp "" '(1 2 3))
>> ; and why not this one ?
>>
>> Thanks in advance.
>> Cyrille
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/e72b954e-0b48-4830-b253-34b904d726bcn%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> -- 
> Jens Axel Søgaard
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/0010ca71-2fb7-46c8-b49e-3f0085d99713n%40googlegroups.com.


Re: [racket-users] Beginner's question

2021-12-14 Thread David Storrs
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)
(string-append (pp_number n) " + " s)))



On Tue, Dec 14, 2021 at 1:48 PM Cyrille DEUSS 
wrote:

> #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 !
>
> (foldl fp "" '(1 2 3))
> ; and why not this one ?
>
> Thanks in advance.
> Cyrille
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/e72b954e-0b48-4830-b253-34b904d726bcn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKoeiVYvsCFuJgHYvK9Eg7cDpSTAkGpk4h2x8aNoe8YHOzg%40mail.gmail.com.


Re: [racket-users] Beginner's question

2021-12-14 Thread Jens Axel Søgaard
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")))
>
> (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 !
>
> (foldl fp "" '(1 2 3))
> ; and why not this one ?
>
> Thanks in advance.
> Cyrille
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/e72b954e-0b48-4830-b253-34b904d726bcn%40googlegroups.com
> 
> .
>


-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgxN5%2B%2BSxfLganjeVB%3DpwuRXUEBEsbofoLh5asmcZ%2BWpBQ%40mail.gmail.com.