Symbols - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Symbols

Description:

Symbols. Sequences of legal characters preceded by a single forward quotation mark: ... For now, strings can be treated like special symbols ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 12
Provided by: BillL161
Category:
Tags: symbols

less

Transcript and Presenter's Notes

Title: Symbols


1
Symbols
2
Outline
  • Prerequisites
  • Basic Scheme functions
  • Boolean expressions
  • Conditionals
  • Objectives
  • Symbols
  • Strings
  • Reference
  • HTDP Section 5

3
Background
  • We frequently need to reason about ideas rather
    than numbers
  • Most languages provide the ability to express
    non-numeric ideas
  • Scheme allows the following representations of
    ideas
  • Symbols
  • Strings
  • Characters (later)
  • Images (later)

4
Symbols
  • Sequences of legal characters preceded by a
    single forward quotation mark
  • Legal characters are the upper and lower case
    letters, numbers, and some punctuation marks
  • - _ _at_ ? are safe to use
  • Do not use symbols with special meaning
  • ' " \ gt lt ltspacegt etc.
  • e.g. 'red 'perfect 'on-top-of 'where?

5
Manipulating Symbols
  • Scheme provides for comparing two symbols
  • symbol? symbol symbol -gt boolean
  • determines whether two symbols are identical
  • For example, a telephone answering system
  • auto-switch symbol -gt (dial ltnumbergt)
  • switch incoming calls to an extension
  • (define (dial n)
  • (display n))
  • (define (auto-switch choice)
  • (cond (symbol? choice 'one) (dial 12)
  • (symbol? choice 'two) (dial 8)
  • (symbol? choice 'three) (dial 0)
  • else (display "say one two or three")))

6
Strings
  • For now, strings can be treated like special
    symbols
  • 0 or more printable characters between quotes
    "..."
  • Can include spaces
  • Scheme provides for comparing two symbols
  • string? string string -gt boolean
  • determines whether two strings are
  • identical
  • Strings are really compound data objects (next
    section)

7
Demo
8
Actual Code
  • auto-switch symbol -gt (dial ltnumbergt)
  • switch incoming calls to an extension
  • (define (auto-switch choice)
  • (cond (symbol? choice 'one) (dial 12)
  • (symbol? choice 'two) (dial 8)
  • (symbol? choice 'three) (dial 0)
  • else (display "say one two or three")))
  • (define (dial n)
  • (display n))

9
Questions?
10
Summary
  • You should now know
  • Symbols
  • Strings

11
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com