Simplifying Dr.Racket alien code I am using Dr.Racket, Intermediate Student with Lambda. I was wondering if there was any way I can simplify this code using any sort of method like lambda, abstraction, map, filter, etc.

 ; alien-at-edge?: alien --&gt; boolean
(define (alien-at-edge? an-alien)
(or (alien-at-right-edge? an-alien)
(alien-at-left-edge? an-alien)))    

; any-alien-at-edge?: loa --&gt; boolean 
(define (any-alien-at-edge? a-loa) 
(cond [(empty? a-loa) false] 
[else (or (alien-at-edge? (first a-loa)) 
      (any-alien-at-edge? (rest a-loa)))])) 

;alien-at-left-edge?: alien --&gt; boolean
(define (alien-at-left-edge? an-alien)
 (&lt;= (- (posn-x an-alien) ALIEN-DELTA-X) alien-half))  

;alien-at-right-edge?: alien --&gt; boolean
(define (alien-at-right-edge? an-alien)
(&gt;= (+ (posn-x an-alien) ALIEN-DELTA-X) (- WIDTH alien-half))) 

;any-alien-at-right-edge?: loa --&gt; boolean 
(define (any-alien-at-right-edge? a-loa) 
(cond [(empty? a-loa) false] 
[else (or (alien-at-right-edge? (first a-loa)) 
      (any-alien-at-right-edge? (rest a-loa)))])) 

;any-alien-at-left-edge?: loa --&gt; boolean 
(define (any-alien-at-left-edge? a-loa) 
(cond [(empty? a-loa) false] 
[else (or (alien-at-left-edge? (first a-loa)) 
      (any-alien-at-left-edge? (rest a-loa)))]))
; alien-at-edge?: alien --&gt; boolean
(define (alien-at-edge? an-alien)
(or (alien-at-right-edge? an-alien)
(alien-at-left-edge? an-alien)))


Not much to do here but don't forget about indentation to make your code readable.

; any-alien-at-edge?: loa --&gt; boolean 
(define (any-alien-at-edge? a-loa) 
(cond [(empty? a-loa) false] 
[else (or (alien-at-edge? (first a-loa)) 
      (any-alien-at-edge? (rest a-loa)))]))


This pattern occurs a lot in functional programming: produce a value (a boolean here) by applying a function (or here) to your list. You can rewrite your function as:

; any-alien-at-edge?: loa --&gt; boolean 
(define (any-alien-at-edge? a-loa) 
  (foldl or false a-loa)


You can also use ormap if foldl is hard to understand.

;alien-at-left-edge?: alien --&gt; boolean
(define (alien-at-left-edge? an-alien)
 (&lt;= (- (posn-x an-alien) ALIEN-DELTA-X) alien-half))  

;alien-at-right-edge?: alien --&gt; boolean
(define (alien-at-right-edge? an-alien)
(&gt;= (+ (posn-x an-alien) ALIEN-DELTA-X) (- WIDTH alien-half))) 


Watch out for indentation and trailing spaces.

;any-alien-at-right-edge?: loa --&gt; boolean 
(define (any-alien-at-right-edge? a-loa) 
(cond [(empty? a-loa) false] 
[else (or (alien-at-right-edge? (first a-loa)) 
      (any-alien-at-right-edge? (rest a-loa)))])) 

;any-alien-at-left-edge?: loa --&gt; boolean 
(define (any-alien-at-left-edge? a-loa) 
(cond [(empty? a-loa) false] 
[else (or (alien-at-left-edge? (first a-loa)) 
      (any-alien-at-left-edge? (rest a-loa)))]))


Those ones can also be implemented using foldl. Try it out!