the jo ys of sc heme daniel p f riedman computer science
play

The Jo ys of Sc heme Daniel P F riedman Computer - PDF document

The Jo ys of Sc heme Daniel P F riedman Computer Science Depa rtmert Indiana Universit y XX Conferencia Latinoamericana de Info rmatica P ANEL Mexico Cit y The Jo ys of Sc


  1. � � The Jo ys of Sc heme Daniel P � F riedman Computer Science Depa rtmert Indiana Universit y XX Conferencia Latinoamericana de Info rmatica� P ANEL ����� Mexico Cit y � � The Jo ys of Sc heme� ���

  2. � � Desiderata � Keep it in y our head � Simple Syn tax� � Simple Seman tics� � F reedom of Expression � Tink erto ys � High P aradigmicit y � � Dynamically �but Strongly� T yp ed� � W e shouldn�t ha v e to do that� � Automatic Memory Managemen t � In teractiv e Program Dev elopmen t � � The Jo ys of Sc heme� ���

  3. � � Outline � Ov erview of the language � Iden tifying Characteristics � Basic Data T yp es � Basic Con trol Structures � Simple Program St yles � Quic ksort � An illustration of basic features � The algorithm � A list implemen tation � Adv anced F eatures � Syn tax Extensions � Fixed�P oin ts � Another Example � Con tin uations � Milestones� Devils and Angels � Using Con tin uations � Exception Handling � Engines � Am b �simple v ersion� � Numeric Multiple In tegration � � The Jo ys of Sc heme� ���

  4. � � An Ov erview of Sc heme � � The Jo ys of Sc heme� ���

  5. � � Iden tifying Characteristics � Ev erything is data� � Pro cedures � Con tin uations � All ob jects ha v e inde�nite exten t� � Pro cedures� � Dynamic� Strong T yping � List�based syn tax� � � The Jo ys of Sc heme� ���

  6. � � Syn tax expr ession � liter al � variable � �expr ession � � � � � � lamb da �variable � � � � expr ession � � � � � � set� variable expr ession� � � if expr ession expr ession expr ession� � There are also additional sp e cial forms � � They denote other language constructs� � But are built from this small set� � � The Jo ys of Sc heme� ���

  7. � � W riting Recursiv e Programs �de�ne � �lamb da �n m� �cond ��zero� n� �� �else ��� � � �sub� n� m������ � What is the value of �� � W e reason as follo ws� � � � � �� � �� � � � � �� � �� � Ho w do w e �ll in �� to turn �� into ��� � Simple� w e add � to it� � Lucky fo r us� m is �� � What is the value of � � It must b e the identit y of � �that is ��� � � The Jo ys of Sc heme� ���

  8. � � Multiplication �de�ne � �lamb da �n m� �cond ��zero� n� �� �else �� m � � �sub� n� m������ � � � �� � �� � � The Jo ys of Sc heme� ���

  9. � � Y ou�re not con vinced� �de�ne facto rial �lamb da �n� �cond ��zero� n� �� �else ��� �facto rial �sub� n������� � What is the value of �� � W e reason as follo ws� � �facto rial �� � ��� � �facto rial �� � �� � Ho w do w e �ll in �� to turn �� into ���� � Simple� w e multiply it b y �� � Lucky fo r us� n is �� � What is the value of � � It must b e the identit y of �that is �� � � � The Jo ys of Sc heme� ���

  10. � � F actorial �de�ne facto rial �lamb da �n� �cond ��zero� n� �� �else � � n �facto rial �sub� n������� �facto rial �� � ��� � � The Jo ys of Sc heme� ����

  11. � � Y ou�re still not con vinced� �de�ne p o w er�set �lamb da �set� �cond ��null� set� �� �else ��� �p o w er�set �cdr set������� � What is the value of �� � W e reason as follo ws� � �p o w er�set ��a b c�� � ��a b c� �a b� �a c� �a� �b c� �b� �c� ��� � �p o w er�set ��b c�� � ��b c� �b� �c� ��� � Ho w do w e �ll in �� to turn �little set� into �big set�� � Simple� W e fo rm the union of adding a to each element of the little set and the little set itself� � Lucky fo r us� �ca r set� is a� � What is the value of �� b y de�nition ����� � � The Jo ys of Sc heme� ����

  12. � � P o w er Set �de�ne p o w er�set �lamb da �set� �cond ��null� set� ������ �else �extend �ca r set� �p o w er�set �cdr set������� �de�ne extend �lamb da �item p o w er�set� �app end �map �lamb da �set� �cons item set�� p o w er�set� p o w er�set��� � � The Jo ys of Sc heme� ����

  13. � � Simple Programs �de�ne facto rial�aps �lamb da �n a� �cond ��zero� n� a� �else �facto rial�aps �sub� n� � � n a������ �de�ne facto rial �lamb da �n� �facto rial�aps n ��� �de�ne facto rial�cps �lamb da �n k� �cond ��zero� n� �k ��� �else �facto rial�cps �sub� n� �lamb da �v� �k � � v n�������� �de�ne facto rial �lamb da �n� �facto rial�cps n �lamb da �x� x���� � � The Jo ys of Sc heme� ����

  14. � � F actorial using letrec �de�ne facto rial �letrec ��facto ral�aps �lamb da �n a� �cond ��zero� n� a� �else �facto rial�aps �sub� n� � � n a������� �lamb da �n� �facto rial�aps n ����� �de�ne facto rial �letrec ��facto rial�cps �lamb da �n k� �cond ��zero� n� �k ��� �else �facto rial�cps �sub� n� �lamb da �v� �k � � n v��������� �lamb da �n� �facto rial�cps n �lamb da �v� v����� � � The Jo ys of Sc heme� ����

  15. � � Basic Data T yp es A tomic Data T yp es � Num b ers� �� ����� ��e�� � Characters� � n a � � n newline � Sym b ols� video� cd�pla y er� radio� Comp ound Ob jects � Lists� Constructors� ���� cons� list Accessors�Mutators� ca r� cdr� set�ca r�� set�cdr� Predicates� null�� pair�� list� � � The Jo ys of Sc heme� ����

  16. � � Basic Data T yp es � V ectors� Constructor� vecto r Accessor�Mutator� vecto r�ref� vecto r�set� Predicate� vecto r� � Strings� Constructor� string Accessor�Mutator� string�ref� string�set� Predicate� string� � � The Jo ys of Sc heme� ����

  17. � � Basic Data T yp es Unprin table Data T yp es � Pro cedures Constructor� �lamb da formals b o dy � Accessor� � op er ator op er ands � � � � �Application�� Predicate� p ro cedure� � Con tin uations Constructor� call�cc Accessor� Applic ation Predicate� p ro cedure� � � The Jo ys of Sc heme� ����

  18. � � Basic Con trol Structures � Conditionals� � �if test�exp then�exp else�exp � � �cond � test�exp exp � � � � � � Sequencing� �b egin E � � � E � � n � Lo oping and Iteration� By Recursion� � � The Jo ys of Sc heme� ����

  19. � � An Illustration� Quic ksort Problem� Sort a giv en set� sa y X � of n um b ers in ascend� ing order� F or example� � � � � � � Boundary Condition � If empt y set� sorted v ersion is the empt y sequence� Step � Cho ose a piv ot� n s�t� n � X � � � � � � Step � P artition the list� h A� B i s�t� A � f x � X j x � n g and B � f x � X j x � n g � � � � � Step � Sort partitions and join them� A � � �� n � � � B � � where A � and B � are sorted v ersions of A and B � � � � � � � � The Jo ys of Sc heme� ����

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend