[racket] Order of Operations - Getting the brackets.

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Dec 22 10:26:22 EST 2010

I just realized something. You probably speak British (or at least
un-American) English. One of my former students from Manchester said
the first two weeks of math were very confusing because what we call
parentheses he called brackets and what we called brackets, he called
something else.

Here's an English to English dictionary:

( and ) = open and close parentheses
[ and ] = open and close brackets
{ and } = open and close (curly-)braces

You tend to use parentheses in Racket, except in some special forms,
which use brackets instead. (These occur when you'd have a couple of
parentheses in a row and are just there to make visual parsing
easier.)

Hope that helps,
Todd

On Wed, Dec 22, 2010 at 10:22 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> Here's an algorithm for converting from "normal math" to Racket.
>
> Write your expression:
>
> people * ticket-price - (number-of-shows * 20 + people * ticket-price)
>
> Notice that I didn't put parentheses anywhere that order of operations
> didn't require them.
>
> Now, add exactly one pair of parentheses for every operator that
> doesn't have one. Make sure you don't add too many and make sure you
> don't add too few. You should end up with the same number of operators
> as pairs of parentheses:
>
> ((people * ticket-price) - ((number-of-shows * 20) + (people * ticket-price)))
>
> Notice 5 operators (*, -, *, +, and *), 5 open parens, and 5 close parens.
>
> Now, move each operator to right after the open paren of the pair that
> encloses it. In other words, I'll move the first * to in front of
> people (i.e. after the second open parenthesis), but the - will move
> after the first open parenthesis.
>
> (- (* people ticket-price) (+ (* number-of-shows 20) (* people ticket-price)))
>
> Don't worry. This gets much easier with practice.
>
> Todd
>
> On Wed, Dec 22, 2010 at 5:44 AM, Sayth Renshaw <flebber.crue at gmail.com> wrote:
>> What I am having trouble navigating is the brackets.
>>
>> Simply in normal math what I am trying to do is
>>
>> (people * ticket price)-((number of shows * 20)+(people * cost per person))
>>
>> Contrcat : total profit : attendees performance -> number
>>
>> ;; Purpose to calculate total profit of a theatre per show
>>
>> ;;Example: (total profit 20 1) should produce $70
>>
>> ;;Defintion: ( define (- profit cost))
>> (* patrons 5( - (* patrons 0.5(+ (* shows 20)))))
>>
>> (define (patrons p)
>>     ;p     a number
>>     ...
>>     )
>>
>> (define (shows s)
>>     ;s        a number
>>     ...
>>     )
>>
>> (define (total_profit p s)
>>     (* p 5( - (* p 0.5(+ s 20)))))
>>
>>
>>
>> _________________________________________________
>>  For list-related administrative tasks:
>>  http://lists.racket-lang.org/listinfo/users
>>
>


Posted on the users mailing list.