Functional programming 在if中定义

Functional programming 在if中定义,functional-programming,scheme,racket,Functional Programming,Scheme,Racket,我刚开始学球拍 我有以下代码: #lang racket (define t1 '(10 20)) (define t2 '(20 30)) (if (list? (first t1)) (define funcion1 >=) (define funcion1 >)) (if (list? (last t1)) (define funcion2 <=) (define funcion2 <)) (not (and (function1 (first t2) (fi

我刚开始学球拍

我有以下代码:

#lang racket

(define t1 '(10 20))
(define t2 '(20 30))

(if (list? (first t1)) (define funcion1 >=) (define funcion1 >))
(if (list? (last t1)) (define funcion2 <=) (define funcion2 <))

(not (and (function1 (first t2) (first t1))
          (function2 (last t2) (last t1))))
#朗球拍
(定义t1’(10-20))
(定义t2’(20 30))
(如果(列表?(第一个t1))(定义函数1>=)(定义函数1>)
(如果(列表?(最后一个t1))(定义函数2=)


我没有使用嵌套if,而是想为函数
使用一个通用id(function1function2),我想我已经找到了如何解决这个问题的方法,灵感来自于:使用

#朗球拍
(定义t1’(10-20))
(定义t2’(20 30))
(let([函数1(如果(列表)(第一个t1))>=>))

(让([function2(if(list)(last t1))
define
在函数的顶层和内部是不同的。此外,虽然不能将
define
放在a
if
侧,但可以将
if
放在
define
的表达式中:

这完全可以:

(定义函数1(如果(列表)(第一个t1))>=>)
(定义函数2(如果(列表)(最后一个t1)))]
[功能2(如果(列表)(最后一个t1)))
(定义函数2(如果(列表)(最后一个t1)))]
[功能2(如果(列表)(最后一个t1))
#lang racket

(define t1 '(10 20))
(define t2 '(20 30))

(let ([function1 (if (list? (first t1)) >=  >)])
(let ([function2 (if (list? (last t1)) <= <)])

(not (and (function1 (first t2) (first t1))
          (function2 (last t2) (last t1))))))