<#3374#>Figure: The planets as images in DrScheme<#3374#>
Like numbers, symbols are atomic pieces of data. Their purpose is to
represent things such as family and first names, job titles, commands, and
announcements, and so on. Scheme provides only one basic operation on
symbols: <#60855#><#3376#>symbol=?<#3376#><#60855#>, a comparison operation. It consumes two symbols and
produces <#60856#><#3377#>true<#3377#><#60856#> if and only if the two symbols are identical:
Symbols were first introduced to computing by researchers in artificial
intelligence who wanted to design functions that could have conversations
with people. Consider the function <#60865#><#3412#>reply<#3412#><#60865#>, which replies with some
remark to the following greetings: ``good morning,'' ``how are you,''
``good afternoon,'', and ``good evening.'' Each of those short sentences
can be represented as a symbol: <#60866#><#3413#>'<#3413#><#3414#>GoodMorning<#3414#><#60866#>, <#60867#><#3415#>'<#3415#><#3416#>HowAreYou<#3416#><#60867#>,
<#60868#><#3417#>'<#3417#><#3418#>GoodAfternoon<#3418#><#60868#>, and <#60869#><#3419#>'<#3419#><#3420#>GoodEvening<#3420#><#60869#>. Thus, <#60870#><#3421#>reply<#3421#><#60870#>
consumes a symbol and replies with a symbol:
<#70729#>;; <#60871#><#3426#>reply<#3426#> <#3427#>:<#3427#> <#3428#>symbol<#3428#> <#3429#><#3429#><#3430#>-;SPMgt;<#3430#><#3431#><#3431#> <#3432#>symbol<#3432#><#60871#><#70729#>
<#70730#>;; to determine a reply for the greeting <#60872#><#3433#>s<#3433#><#60872#><#70730#>
<#3434#>(define<#3434#> <#3435#>(reply<#3435#> <#3436#>s)<#3436#> <#3437#>...)<#3437#>
Furthermore, the function must distinguish among four different situations.
This means our design recipe from section~#secdesign2#3441><#3447#>(d<#3447#><#3448#>efine<#3448#> <#3449#>(reply<#3449#> <#3450#>s)<#3450#>
<#3451#>(c<#3451#><#3452#>ond<#3452#>
<#3453#>[<#3453#><#3454#>(symbol=?<#3454#> <#3455#>s<#3455#> <#3456#>'<#3456#><#3457#>GoodMorning)<#3457#> <#3458#>...]<#3458#>
<#3459#>[<#3459#><#3460#>(symbol=?<#3460#> <#3461#>s<#3461#> <#3462#>'<#3462#><#3463#>HowAreYou?<#3463#><#3464#>)<#3464#> <#3465#>...]<#3465#>
<#3466#>[<#3466#><#3467#>(symbol=?<#3467#> <#3468#>s<#3468#> <#3469#>'<#3469#><#3470#>GoodAfternoon)<#3470#> <#3471#>...]<#3471#>
<#3472#>[<#3472#><#3473#>(symbol=?<#3473#> <#3474#>s<#3474#> <#3475#>'<#3475#><#3476#>GoodEvening)<#3476#> <#3477#>...]<#3477#><#3478#>))<#3478#>
The <#60874#><#3482#>cond<#3482#><#60874#>-clauses match the four symbols, which is naturally much
easier than matching four intervals.
From this function <#60875#><#3483#>TEMPLATE<#3483#><#60875#> it is a short step to the final
function. Here is one version of <#60876#><#3484#>reply<#3484#><#60876#>:
<#3489#>(d<#3489#><#3490#>efine<#3490#> <#3491#>(reply<#3491#> <#3492#>s)<#3492#>
<#3493#>(c<#3493#><#3494#>ond<#3494#>
<#3495#>[<#3495#><#3496#>(symbol=?<#3496#> <#3497#>s<#3497#> <#3498#>'<#3498#><#3499#>GoodMorning)<#3499#> <#3500#>'<#3500#><#3501#>Hi]<#3501#>
<#3502#>[<#3502#><#3503#>(symbol=?<#3503#> <#3504#>s<#3504#> <#3505#>'<#3505#><#3506#>HowAreYou?<#3506#><#3507#>)<#3507#> <#3508#>'<#3508#><#3509#>Fine]<#3509#>
<#3510#>[<#3510#><#3511#>(symbol=?<#3511#> <#3512#>s<#3512#> <#3513#>'<#3513#><#3514#>GoodAfternoon)<#3514#> <#3515#>'<#3515#><#3516#>INeedANap]<#3516#>
<#3517#>[<#3517#><#3518#>(symbol=?<#3518#> <#3519#>s<#3519#> <#3520#>'<#3520#><#3521#>GoodEvening)<#3521#> <#3522#>'<#3522#><#3523#>BoyAmITired]<#3523#><#3524#>))<#3524#>
We can think of many different ways of how to replace the ``...'' in the
template with replies. But no matter what we replace them with, the basic
template could be defined without concern for the output of the function. We
will see in subsequent sections that this focus on the input data is
actually the norm and that concern for the output data can be postponed.
<#3528#>A Note on Strings<#3528#>: A <#60877#><#3529#>STRING<#3529#><#60877#> is a second form of symbolic
data. Like a symbol, a string consists of a sequence of keyboard characters, but
they are enclosed in string quotes:
<#60878#><#3531#>``the<#3531#>\ <#3532#>dog''<#3532#><#60878#> <#60879#><#3533#>``isn'<#3533#><#3534#>t''<#3534#><#60879#><#60880#><#3535#>``made<#3535#>\ <#3536#>of''<#3536#><#60880#>
<#60881#><#3537#>``chocolate''<#3537#><#60881#><#60882#><#3538#>``two^<#3538#><#3539#>3''<#3539#><#60882#><#60883#><#3540#>``and<#3540#>\ <#3541#>so<#3541#>\ <#3542#>on?<#3542#><#3543#>''<#3543#><#60883#>
In contrast to symbols, strings are not atomic. They are compound data,
which we discuss later in the book. For now, we use strings as if they were
fancy symbols; the only operation needed is <#60884#><#3545#>string=?<#3545#><#60884#>, which
compares two strings the way <#60885#><#3546#>symbol=?<#3546#><#60885#> compares two
symbols. Otherwise we ignore strings, and when we use them, we act as if
they were symbols.~<#60886#><#60886#>
<#3549#>A Note on Images<#3549#>: An <#60887#><#3550#>IMAGE<#3550#><#60887#> is a third form of symbolic
data, and it is fun to develop functions that process images. Like symbols, images
don't have any <#3551#>a priori<#3551#> meaning, but we tend to connect them easily with
the intended information.
DrScheme supports images: see figure~#figplanetspics#3552>