### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# Class Note for CS 603 at UA-Organz Program Languages (1)

### View Full Document

## 26

## 0

## Popular in Course

## Popular in Department

This 25 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Alabama - Tuscaloosa taught by a professor in Fall. Since its upload, it has received 26 views.

## Reviews for Class Note for CS 603 at UA-Organz Program Languages (1)

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 02/06/15

CS 603 Programming Language Organization Lecture 10 Spring 2004 Department of Computer Science UniveIsity of Alabama Joel Jones Outline 0 Questions S expressions y Scheme cont 0 Reading for next time mum Jae lanes S expressions s expression a symbol a number or a list S 1 S of zero or more S expressions nil list list of zero elements mum Inel lanes Operations on S Expressions 0 Review 7 car rst element oflist or 0 e cdr everything in list except rst elernent cons ifs 51s Lhenc0ns 539s is 51 Predicates remms tif equal f otherwise for nonrlists and empty lists 7 number symbol list null tif argument of type f otherwise 7 lt gt tifhoth numbers and condition holds f otherwise 0 Math 7 e like impcore mum Juel lanes Syntax changes from impcore 0 value integer quoted const value 0p ltgtcons carlcdr Inumber symbol list null print quoted const S expression S expression integer symboll S expressionquot symbol name mum Jae lanes Example of a list using function CIIIIIIIIIIIIIIIIIIIIIIIIIIIIID define length 1 if null l O 1 length cdr l mum Inel lanes Let s play at the board again No Books listl x 7 list of one element x list2 x y 7 list of two elements x and y list3 x y z 7 list of three elements x y and 2 atom x 7 t if null number or symbol f otherwise equal 11 12 7 tif two equal atoms or equal lists f otherwise Two lists are equal if same length and corresponding elements are equal mum Joel lanes Larger LISP Example 0 Calculate pn39me numbers less than I using Sieve of Eratosthenes mum Inel lanes Let s Play at the Board but your books can t play Insertion sort given a list of n elements sort the last nI recursively then insert the rst in its proper position de ne insert x l m define insertion sort l oznm Jae lanes Association Lists association lista list a list of the form k a1 km am Where the kl are symbols called keys and the al are attributes retIieve data define aSsoc x alist if null alist 390 if x caar alist cadar alist aSsoc x cdr alist mm 1031 lanes Association Lists cont 0 add data define mkassoc x y allst 1f null allst 115m llSt2 x y 1f x Caar allst Cons llSt2 x y Cdr allst Cons Car allst mkassoc x y Cdr ahstmm mum Inel lanes Let s play at the board again No Books 0 Property lists a list Where attribute is an attribute list 0 Examples Set fruitS 39 apple texture crunch banana color yellow getprop 39apple texture fruitS crunchy Write getprop x p plist Where x is the individual p is the property and plist is the property list mm 1021 lanes Let s play at the board again No Books putprop x p y plistgWe individual x value y for property p in plist set fruits putprop apple color red fruits gtapple texture crunchycolor redbanana color yellow mum Inel lanes pScheme 0 Closures 7 Pair of lambda function Value and environment lambda y x Lgt 1 7 Environment maps name to mutable location gtval counter from lambda n lambda Set n n 1 gtval ten counter from 10 procedure gtten 11 gtten 12 mum Joel Jones pScheme cont IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 0 Closures ParUp IWxitI a funcu39on mak rwithdraw hatmodels a bank accbunt balance whe re only wiLhdmwals are allowed gt va1 make withdraw lambda balance gtval W1 make withdraw 1b0 gtw1 10 90 mum Inel lanes Simple higherorder functions 0 Composition 7 de ne o f g lambda X f g X 7 de ne even n 0 mod n 2 7 val odd 0 not even PairUp Write a function mam using composition whh square and that raises the inputw the 8111 power gt de ne squarex x x square gt 39val tQSth ltproceduregt gt toSth 2 256 oznm Jae lanes Simple higherorder functions cont CurIying 7 Taking an niargurnent function and turning it into a liargurnent function returning a function expecting nil arguments also curried 7 Currying binary functions 0 de ne curry f lambda x lambda y fx y 0 de ne uncurry f lambda x y f x y oznm Juel lanes Simple higherorder functions cont Curlyng gtval Zero curry 0 gtZero 0 t gtval addl curry 1 gtadd1 4 5 gtval new uncurry curry gtnew 1 4 5 mum Inel lanes Higherorder functions on lists UIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIID 0 Filters define filter p 1 if null 1 39 if p car 1 cons car 1 lter p cdr 1 lter p cdr 1 0 Exists7 define exists p 1 if null 1 f if p car 1 t exists p cdr 1 mum Inel lanes Higherorder functions on lists cont A11 define all p 1 if null 1 t if p car 1 exists p cdr 1 f Map define map f 1 if null 1 39 cons f car 1 map f cdr 1 earguniem of filter ex 1 sts 239ahd a11iffenehrfmmdiose mum Inel lanes Higherorder functions on lists cont Foldr 0 Fold mum Inel lanes Higherorder functions for polymorphism 0 Implementing sets 7 Constructing monoemorphic sets requires de nition of equalityisimple if primitive elements gtval emphyset I gtde ne member x s exlsts curry equal x 5 gtde ne addelement x s 1 member x s s cons x s gtde ne unlon 51 52 foldl addelement 51 52 gtde ne setfromllst l foldl addelement 1 1 0 Problem is equality for complex types oznm Joel lanes Higherorder functions for polymorphism cont 1mp1ement a data type for sets which uses the usual list represenm on Therefore all you have to do is implement set gtset a b c c b a t Implement sets of sets wherethe set funcu39ons are passed an eqfun for comparing sets gtde ne member x s eqfun quota gtdefine add element X s eqfun oznm Joel lanes Higherorder functions for polymorphism cont 0 How to construct 7 Add parameter to every function 7 Make part of object set in previous example 7 Make list of functions like C templates oznm Joel lanes Reading amp Questions for Next Class 0 Chapter 311 3 14 mum Inel lanes

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

#### "I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.