[racket] Order of Operations - Getting the brackets.

From: Sayth Renshaw (flebber.crue at gmail.com)
Date: Wed Dec 22 23:21:32 EST 2010

On Thu, Dec 23, 2010 at 2:26 AM, Todd O'Bryan <toddobryan at gmail.com> wrote:

> 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
> >>
> >
>

Thanks for the tip on the parentheses. Having a close and open without an
operator " ) ( " between them really through me. Yes I speak
Australian/British English this hasn't been too much of a hurdle though in
HTDP I wont be doing Ex 2.3.1 as I have no idea about nickels and dimes. The
book is very good regardless of that minor localisation.

Sayth
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20101223/6b775154/attachment.html>

Posted on the users mailing list.