I'm a C# programmer learning Scheme, and I have a lot of troubles, because I don't understand Scheme.
I have write it this code with a lot of help:
#lang racket
(define sort-asc-by-second
(lambda (lst)
(sort lst
(lambda (x y) (< (cdr x) (cdr y))))))
(define sum
(lambda (lst)
(apply + (map cdr lst))
)
)
(define my-function
(lambda (lst)
(
(define sorted (sort-asc-by-second lst))
(define suma (sum lst))
(define lista (map (lambda (p) (cons (car p) (/ (cdr p) suma)))))
))
)
But I get the following error:
define: not allowed in an expression context in: (define sorted (sort-asc-by-second lst))
At this line:
(define sorted (sort-asc-by-second lst))
How can I declare a variable? Maybe, the problem here is that I'm a C# programmer and I don't understand Scheme.