htdp: prologue - nadia-sheikh/htdp GitHub Wiki

Introduction to Dr Racket<\h3>

Dr Racket as an IDE:

  • Top half is definitions area and bottom half is interactions area
  • Instructions to compute are entered in the definitions area while outputs of computation are displayed in the interactions area
  • <\ul>

    Writing programs in Dr Racket:

    • Programs consists of expressions. In the context expressions begin with a ( and end with )<\li>
    • Each set of parenthesis consists of an operator followed by one or more operands.
    • Operators may be numbers, text, boolean values, images or other expressions.
      • Operators with numerical operands (or expressions that return numbers) include:
        • +, -, /, *
        • number->string
        • >, <, =
      • Operators with string (text) operands (or expressions that return strings) include:
        • string-append, string-length, string->number
      • Operators with boolean (#true, #false) operands (or expressions that return booleans) include:
        • and, or, not
      • Operators with image operands (or expressions that return images) include:
        • image-height, image-width

      Images:

      • Expressions can be used to generate images, e.g. (circle 10 "solid" "red") will create an solid red circle with a diameter of 10, (rectangle 10 15 "outline" "blue") will create an empty rectangle with a blue outline and a width of 10 and a height of 15
      • Images can be composed using the operation overlay e.g. (overlay x y) will overlay the image x on the image y
      • A grid can be constructed using the operation empty-scene e.g. (empty-scene x y) will produce a grid with an width of x and a height of y. The origin will sit at the top left hand corner of the grid
⚠️ **GitHub.com Fallback** ⚠️