Eroxl's Notes
Terminology

Answer Expression

The answer expression expression is the expression evaluated if a given question expression is evaluated as true.

Example

(cond [(> 3 3) "more"]     
      [(< 3 3) "less"]     
      [else "same"])

In this example "more", "less" and "same" are all answer expressions

Question Expression

The question expression is the expression evaluated to determine if the answer expression should be evaluated. Question expressions are always evaluated to either true or false.

(cond [(> 3 3) "more"]     
      [(< 3 3) "less"]     
      [else "same"])

In this example, (< 3 3) and (> 3 3) are question expressions.

If Statement

An if statement is flow control statement that chooses a command depending on a expression.

Example

(define c 10)

(if (< c 0)
    "positive"
    "negative")

In this example (if (< c 0) "positive" "negative") is the if statement

Argument

The argument is the value(s) which result from evaluating the operands in the function call.

Example

(bulb (string-append "r" "ed"))

In the context of bulb it's argument is "red" as (string-append "r" "ed") evaluates to "red".

Atomic Distinct

Atomic distinct describes a type that represents itself.

Example

(@htdd Example)
;; Example is "example-1"

(@dd-template-rules atomic-distinct)

(define (fn-for-example e) (...))

Examples of Values

  • "red"
  • false
  • empty

Constant Definition

A constant definition is the definition of a constant value

Example

(define BALL (circle BALL-RADIUS "solid" "white"))

Constant Name

A constant name is the name given to a constant value

Example

(define BALL (circle BALL-RADIUS "solid" "white"))
(define MTS (rectangle WIDTH HEIGHT "solid" "green"))

(place-image BALL 10 10 MTS)

In this example both BALL and MTS are both constant names

Data Example

A data example is an example of the type of data a data definition represents

Example

(@htdd Time)
;; Time is Natural
;; interp. number of clock ticks since start of game

(define START-TIME 0)
(define OLD-TIME 1000)

(@dd-template-rules atomic-non-distinct)

(define (fn-for-time t)
  (... t))

In this example both (define START-TIME 0) and (define OLD-TIME 1000) are data examples of Time

DD Template Rule

DD Template Rules are a series of rules that are used as a guide to create Data Definitions. In the beginning of every Data Definition you can specify which rules to use so that if someone else is reading your definition, they can quickly understand it and use it in their code.

Example

(@htdd Time)
;; Time is Natural
;; interp. number of clock ticks since start of game

(define START-TIME 0)
(define OLD-TIME 1000)

(@dd-template-rules atomic-non-distinct)

(define (fn-for-time t)
  (... t))

In this example atomic-non-distinct is a dd Template Rule

(@htdd ListOfBall)
;; ListOfBall is one of:
;;  - empty
;;  - (cons Ball ListOfBall)
;; interp. a list of balls

(define LOB-1 empty)
(define LOB-2 (cons (make-ball (/ WIDTH 2) (/ HEIGHT 2) 4 -3) empty))
(define LOB-3 (cons (make-ball 1 2 4 -3) (cons (make-ball 3 5 4 -3) empty)))


(@dd-template-rules one-of
                    atomic-distinct
                    compound
                    ref
                    self-ref)

(define (fn-for-lob lob)
  (cond
    [(empty? lob) (...)]
    [else (... (fn-for-ball (first lob))
               (fn-for-lob (rest lob)))]))

In this example atomic-distinct, compound, ref, and self-ref are all dd template rules

Expression

Expression

Expressions are anything that can be evaluated to a value. Expressions always take the form of either (<primitive> <expression>...) or just a single <value>.

Examples

  • (+ 2 3)
  • (* 4 5)
  • (sqrt (+ (sqr 3) (sqr 4)))
  • 1
  • #i1.4142135623730951

Function Body

The Function Body is the executed portion of a function

Example

(define (convert-fn c)
  (* 9/5 c))

In this example (* 9/5 c) is the function-body of convert-fn.

Function Call Expression

A function call expression is an expression that represents calling a function with some arguments

Example

(circle 10 "solid" "red")

Function Definition

A function definition is the full definition of a function which includes the function body.

Example

(define (convert-fn c)
  (* 9/5 c))

Function Example

A function example is the tests written before a function (usually check-expect's).

Example

(@htdf preference?)
(@signature Rating -> Boolean)
;; produces true if a rating reflects a clear opinion

(check-expect (preference? "n/a") false)
(check-expect (preference? 1) true)
(check-expect (preference? 3) false)
(check-expect (preference? 5) true)

; (define (preference? rating) true)  ; this is the stub

(@template-origin Rating)

(@template   
 (define (preference? r)
   (cond [(and (string? r) (string=? r "n/a")) (...)]
         [else
          (... r)])))

(define (preference? r)
   (cond [(and (string? r) (string=? r "n/a")) false]
         [else (not (= r 3))]))

In this example (check-expect (preference? "n/a") false), (check-expect (preference? 1) true), (check-expect (preference? 3) false), and (check-expect (preference? 5) true) are all function examples.

Function Name

A function name is a name given to a function definition or function call expression.

Example

(define (area c)
  (* 9/5 c))

In this example area is the function name

Metadata Annotation

A metadata annotation is a piece of information added to help the programmer use the function or data structure. Usually, this is used for the beginning of Data Definitions or Function Definitions. Metadata annotations

Example

(@problem 1)

(@htdf main)
(@signature Ball -> Ball)
;; start the game, call with (main B1)
;; <no tests for main functions>

(@template-origin htdw-main)

(define (main b)
  (big-bang b
    (on-draw   render-ball)   ;Ball -> Image
    (on-tick   next-ball)     ;Ball -> Ball
    (on-mouse  handle-mouse)));Ball Integer Integer MouseEvent -> Ball
            

In this example (@problem 1), (@htdf main), (@signature Ball -> Ball), and (@template-origin htdw-main) are all metadata annotations.

Operand

The expressions following the function name in a function call expression are called operands.

Example

(define (bulb c)
  (color 40 "solid" c))

(bulb (string-append "r" "ed"))

In this example (string-append "r" "ed") is the operand of bulb and "r" and "ed are the operands of string-append.

Parameter

A parameter is an identifier (or name) used in a function declaration that represents the input values.

(define (bulb c)
  (color 40 "solid" c))

(bulb (string-append "r" "ed"))

In this example c is the parameter of bulb.

Structure Definition

Structure definitions are constructs that provide a way for storing data with different pieces and naming these individual pieces. This is helpful when you want to store different types of data but group them together for ease of use.

Example

(struct book (title author pages))

Template

A template describes the basic structure or backbone of the function independent of its details.

Example

(@htdd DinnerOrder)
;; DinnerOrder is one of:
;; - "No dinner"
;; - "Chicken"
;; - "Pasta"
;; interp. "No dinner" means the passenger does not want dinner,
;;         the other values are dinner options

(@dd-template-rules one-of
				    atomic-distinct
				    atomic-distinct
				    atomic-distinct)

(define (fn-for-dinner d) 
  (cond [ (string=? d "No dinner") (...) ]
		[ (string=? d "Chicken") (...) ]
		[ (string=? d "Pasta") (...) ]))

In this example the entire function definition fn-for-dinner would be the template for functions that operate on DinnerOrder.

Type Comment

A type comment is used to describe the usage of a specific type for a parameter to a function or for a variable definition.

Example

(@htdd DinnerOrder)
;; DinnerOrder is one of:
;; - "No dinner"
;; - "Chicken"
;; - "Pasta"
;; interp. "No dinner" means the passenger does not want dinner,
;;         the other values are dinner options

(@dd-template-rules one-of
				    atomic-distinct
				    atomic-distinct
				    atomic-distinct)

(define (fn-for-dinner d) 
  (cond [ (string=? d "No dinner") (...) ]
		[ (string=? d "Chicken") (...) ]
		[ (string=? d "Pasta") (...) ]))

In this example DinnerOrder is one of:, - "No dinner - "Chicken" - "Pasta" all make up the type comment for DinnerOrder

Type Name

The type name is the name / identifier given to a specific type

Example

(@htdd DinnerOrder)
;; DinnerOrder is one of:
;; - "No dinner"
;; - "Chicken"
;; - "Pasta"
;; interp. "No dinner" means the passenger does not want dinner,
;;         the other values are dinner options

(@dd-template-rules one-of
				    atomic-distinct
				    atomic-distinct
				    atomic-distinct)

(define (fn-for-dinner d) 
  (cond [ (string=? d "No dinner") (...) ]
		[ (string=? d "Chicken") (...) ]
		[ (string=? d "Pasta") (...) ]))

In this example DinnerOrder would be the type name