程序代写代做 C clock ; A program is a sequence of “top level” expressions and statements.

; A program is a sequence of “top level” expressions and statements.
; ! Expression Forms !
; • Literal Value •
; inserted/pasted image
function-name ; function by name, from the language or from a definition ±n.n ±n/n ; number as decimal or fraction
#true #false ; boolean
“⋯characters⋯” ; text
(list literal-value etc) ; list
; • Variable Reference : variable-name ; from a definition
; • Function Call : (function-name argument-expression etc)
; • Parameter Reference : parameter-name ; in the body of a function definition
; • Conditional : (if condition-expression consequent-expression else alternative-expression)
; ! Statement Forms !
; • Definition of Variable or Function •
(define variable-name value-expression)
(define (function-name parameter-name etc) ; “header”
; Function Examples
; ! Equality Predicate :
; ! Type Predicates !
(true! (image?
(true! (function? flip)) (true! (number? -12.3))
(false! (same? 3 2))
(true! (boolean? #false)) (true! (text? “Hi!”)) (true! (list? (list 5)))
; ; ; ; ; ; ; ; ;
;
; ;
• For a function from a definition :
If the number of arguments and parameter names differ : report an error.
If the function name or this whole call is a hide option : skip to result value. Otherwise : copy the function’s body and substitute the arguments in place of
the parameter names wherever those names occur in the body.
• For the function map or combine : match its first pattern below, then :
If the expression doesn’t match its pattern : report an error.
Otherwise : determine the literal values for f a b c … , then substitute those
into the rule’s second pattern.
(mapf(listabcetc)→(list(fa)(fb)(fc)etc) (combine f (list a b c etc) → (f a b c etc)
• For any other function from our language :
If there are the wrong number or kind of arguments : report an error.
Otherwise : substitute a directly computed value (see the “Function Examples”)
)
)
)
)
)
(same! (solid-triangle (same! (solid-circle (same! (solid-square
7
9) 9) 9)
body-expression)
) )
(same! expression expression
(true! expression) (false! expression)
; • Assertion / Test :
; • Inspect Evaluation •
; until reaching the literal value of the expression or encountering an error.
(function-name literal etc)
etc)
(step (hide function-name/call etc)
)
) (same! (triangle (same! (circle
9) 9) 9)
) ) )
(step expression)
; Show expressions produced by replacing sub-expressions that are in the following forms,
expression)
(same! (square (same! (oval
(same! (rectangle 7
variable-name → literal ; • Substitute variable’s previously-computed value. (if ⋯) ; • Based on the evaluation state of the condition :
(same! (+ 2 10 3) 15)
(same! (* 2 10 3) 60) (same! (-
(if #true consequent else alternative)
→ consequent
(if non-boolean-literal ⋯) ; report an error
(if condition ⋯) ; evaluate condition first ; ! Function Design !
; Goal Example :
; Full Design :
(same! (function-name argument etc) literal) (same! (function-name argument etc)
(same! (length (list (same! (first (list
(same! (rest (list
(same! (reverse (list
5 #false)) 3) 5 #false)) )
(if #false consequent else alternative)
fully-generalizable-expression)
; …wherethegeneralizableexpressiononlyusestheargumentsas-is,soitcanbeused
; as the body of the function’s definition by replacing arguments with parameter names.
; Partial Design : (same! (function-name argument etc) partially-general-expression)
; … where the partially general expression is not fully generalizable, but not just literal.
5 #false)) (list 5 #false))
5 #false)) (list #false 5 ))
→ alternative
(same! (scale (same! (small
(same! (large (same! (above
1.5) )
)
) )
) )
15) ) 15) )
) ) )
15) ) 15) )
(same! (above-left (same! (above-right
(same! (beside )
(same! (beside-top )
(same! (beside-bottom )
(same! (overlaid ; ! Numeric Functions !
)
) )
(true! (same? (+ 1 1) 2))
; ! Function Predicates : ; ! Image Functions !
(true! (unary? flip)) (false! (binary? flip))
(same! (mirror ) (same! (flip )
(same! (turn 30) (same! (clockwise (same! (anti-clockwise
)
) )
)
(same! (scale-width )
(same! (scale-height )
1.5) 1.5)
) )
))
(same! (- (same! (number->text -12) “-12”)
; ! Text Functions !
(same! (text-length “one”) 3)
(same! (text-join “Hi” ” human” “!”) “Hi human!”)
(same! (text->image “Hi!”) )
(same! (text->list “Hi!”) (list “H” “i” “!”))
; ! List Functions !
(same! (list (star 10) (+ 2 3) (text? 4)) (list
(same!(range 8)(list01234567))
(same! (range 3 8) (list 3 4 5 6 7)) (same! (range 3 8 2) (list 3 5 7))
) )
) )
(same! (wide (same! (thin
(same! (tall (same! (short
) )
)
(same! (solid-oval
(same! (solid-rectangle 7
(same! (width (oval 7 15)) 7) (same! (height (oval 7 15)) 15)
12) -12) (same! (/ 12 3) 4) 12 3) 9)
5 #false))
7