My target is do define list as local variable in order to get max element from it. My code:
#lang racket
(define (f a b c)
(list (+ (* a a) (* b b) (* c c)) (+ a c))
(define (max-of-list-2 lst)
(foldr max (first lst) (rest lst)))
(max max_from_list 12))
(f 5 6 7)
In second row I have defined list with calculated falues. My target is to pass it to next row in order to get max number from it, and finaly to get max from max of list and 12. What I do wrong. How to handle it?
You can use several define
s at the top of your function.
So you meant
(define (f a b c)
(define lst (list (+ (* a a) (* b b) (* c c))
(+ a c)))
(define (max-of-list-2 lst)
(foldr max (first lst) (rest lst)))
(max (max-of-list-2 lst) 12))
but that's just equivalent to
(define (f a b c)
(foldr max 12 (list (+ (* a a) (* b b) (* c c))
(+ a c))))