CS计算机代考程序代写 #lang racket #| * CSC324H5 Fall 2021: Assignment 1 * |#

#lang racket #| * CSC324H5 Fall 2021: Assignment 1 * |#
#|
Module: a1
Description: Assignment 1: Checking for Tail Recursion
Copyright: (c) University of Toronto Mississsauga
CSC324 Principles of Programming Languages, Fall 2021
|#

; This specifies which functions this module exports. Don’t change this!
(provide is-tail-recursive)

; Import the testing library
(module+ test
(require rackunit))

#|
(is-tail-recursive def) -> boolean?
def: (and/or symbol? number?)
A function definition that follows the grammar for in the handout.
You may assume that the function defined in def is recursive.

Returns whether the definition is tail recursive
|#
(define (is-tail-recursive def)
(let* ([fname (first (second def))]
[body (third def)])
(void))) ; TODO: replace (void) with your code

; You can write helper functions freely
(module+ test
; We use rackunit’s test-equal? to define some simple tests.
(test-equal? “Simple test for tail recursion” ; Test label
(is-tail-recursive ‘(def (f x) (f x))) ; Actual value
#t) ; Expected value
(test-equal? “Recursive call in if expression conditional”
(is-tail-recursive ‘(def (f x) (if (f x) x x)))
#f)
(test-equal? “Recursive call in let* definition”
(is-tail-recursive ‘(def (f x) (let* ([a (f x)]) (g a))))
#f)
(test-equal? “Recursive call in let* body”
(is-tail-recursive ‘(def (f x) (let* ([a (g x)]) (f a))))
#t)

; TODO: Write more tests. Testing is an important part of programming,
; so ou and your partner must write your own tests. Do not share your
; tests with anyone else.
)