DOC PREVIEW
UMD CMSC 330 - Organization of Programming Languages

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

11CMSC 330: Organization of Programming LanguagesRuby2Reminders and Announcements• If you’re not on the list, you’re not in the class (I have the list)• Project 1 was posted on Sep. 3– It is due on Sep. 24– Start immediately• Check glue access• Use the class forum• Read complete syllabus online• Leave 24 hours for email responses3Review• Why study programming languages?• What makes a good programming language?• Compilers vs. Interpreters• What kind of language is…–C–Java–Ruby–OCaml4Introduction• Ruby is an object-oriented, imperative scripting language– “I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language.”– “I believe people want to express themselves when they program. They don't want to fight with the language. Programming languages must feel natural to programmers. I tried to make people enjoy programming and concentrate on the fun and creative part of programming when they use Ruby.”– Yukihiro Matsumoto (“Matz”)5Applications of Scripting Languages• Scripting languages have many uses– Automating system administration– Automating user tasks– Quick-and-dirty development• Major application:Text processing6Output from Command-Line Tool%wc*271 674 5323 AST.c100 392 3219 AST.h117 1459 238788 AST.o1874 5428 47461 AST_defs.c1375 6307 53667 AST_defs.h371 884 9483 AST_parent.c810 2328 24589 AST_print.c640 3070 33530 AST_types.h285 846 7081 AST_utils.c59 274 2154 AST_utils.h50 400 28756 AST_utils.o866 2757 25873 Makefile270 725 5578 Makefile.am866 2743 27320 Makefile.in38 175 1154 alloca.c2035 4516 47721 aloctypes.c86 350 3286 aloctypes.h104 1051 66848 aloctypes.o...27Climate Data for IAD in August, 2005================================================================================123456A6B 7 89101112131415161718AVG MX 2MINDY MAX MIN AVG DEP HDD CDD WTR SNW DPTH SPD SPD DIR MIN PSBL S-S WX SPD DR================================================================================1 87 66 77 1 0 12 0.00 0.0 0 2.5 9 200 M M 7 18 12 2102 92 67 80 4 0 15 0.00 0.0 0 3.5 10 10 M M 3 18 17 3203 93 69 81 5 0 16 0.00 0.0 0 4.1 13 360 M M 2 18 17 3604 95 69 82 6 0 17 0.00 0.0 0 3.6 9 310 M M 3 18 12 2905 94 73 84 8 0 19 0.00 0.0 0 5.9 18 10 M M 3 18 25 3606 89 70 80 4 0 15 0.02 0.0 0 5.3 20 200 M M 6 138 23 2107 89 69 79 3 0 14 0.00 0.0 0 3.6 14 200 M M 7 1 16 2108 86 70 78 3 0 13 0.74 0.0 0 4.4 17 150 M M 10 18 23 1509 76 70 73 -2 0 8 0.19 0.0 0 4.1 9 90 M M 9 18 13 9010 87 71 79 4 0 14 0.00 0.0 0 2.3 8 260 M M 8 1 10 210...8Raw Census 2000 Data for DCu108_S,DC,000,01,0000001,572059,72264,572059,12.6,572059,572059,572059,0,0,0,0,572059,175306,343213,2006,14762,383,21728,14661,572059,527044,158617,340061,1560,14605,291,1638,10272,45015,16689,3152,446,157,92,20090,4389,572059,268827,3362,3048,3170,3241,3504,3286,3270,3475,3939,3647,3525,3044,2928,2913,2769,2752,2933,2703,4056,5501,5217,4969,13555,24995,24216,23726,20721,18802,16523,12318,4345,5810,3423,4690,7105,5739,3260,2347,303232,3329,3057,2935,3429,3326,3456,3257,3754,3192,3523,3336,3276,2989,2838,2824,2624,2807,2871,4941,6588,5625,5563,17177,27475,24377,22818,21319,20851,19117,15260,5066,6708,4257,6117,10741,9427,6807,6175,572059,536373,370675,115963,55603,60360,57949,129440,122518,3754,3168,22448,9967,4638,14110,16160,165698,61049,47694,13355,71578,60875,10703,33071,35686,7573,28113,248590,108569,47694,60875,140021,115963,58050,21654,36396,57913,10355,4065,6290,47558,25229,22329,24058,13355,10703,70088,65737,37112,21742,12267,9475,9723,2573,2314,760,28625,8207,7469,738,19185,18172,1013,1233,4351,3610,741,248590,199456,94221,46274,21443,24831,47947,8705,3979,4726,39242,25175,14067,105235,82928,22307,49134,21742,11776,211,11565,9966,1650,86,1564,8316,54,8262,27392,25641,1751,248590,115963,4999,22466,26165,24062,16529,12409,7594,1739,132627,11670,32445,23225,21661,16234,12795,10563,4034,248590,115963,48738,28914,19259,10312,4748,3992,132627,108569,19284,2713,1209,509,218,125...9A Simple Example• Let’s start with a simple Ruby program# This is a ruby programx=37y=x+5print(y)print("\n")ruby1.rb:% ruby -w ruby1.rb42%10Language Basics# This is a ruby programx=37y=x+5print(y)print("\n")comments begin with #, go to end of linevariables need notbe declaredline break separatesexpressions(can also use “;”to be safe)no special main()function ormethod11Run Ruby, Run• There are three ways to run a Ruby program–ruby -w filename – execute script in filename• tip: the -w will cause Ruby to print a bit more if something bad happens–irb– launch interactive Ruby shell• can type in Ruby programs one line at a time, and watch as each line is executedirb(main):001:0> 3+4=> 7irb(main):002:0> print("hello\n")hello=> nil12Run Ruby, Run (cont’d)• Suppose you want to run a Ruby script as if it were an executable• ./filename # run program– The first line tells the system where to find the program to interpret this text file–Must chmod u+x filename first•Or chmod a+x filename so everyone has exec permission– Warning: Not very portable• Depends on location /usr/local/bin/ruby#!/usr/local/bin/ruby -wprint("Hello, world!\n")313Explicit vs. Implicit Declarations• Java and C/C++ use explicit variable declarations– variables are named and typed before they are used• int x, y; x = 37; y = x + 5;• In Ruby, variables are implicitly declared– first use of a variable declares it and determines type• x = 37; y = x + 5;–x, y exist, will be integers14Tradeoffs?Figures out types of variables automaticallyForces programmer to document typesEasy to mistype variable nameHelps prevent typosOverhead?Overhead?Implicit DeclarationsExplicit Declarations15Methods in Rubydef sayN(message, n)i=0while i < nputs messagei=i+1endreturn iendx = sayN("hello", 3)puts(x)List parametersat definitionInvoke methodMay omit parenson callMethods are declared with def...end(Methods must begin with lowercase letter and be defined before they are called)16Method (and Function) Terminology• Formal parameters – The parameters used in the body of the method– message, n in our example• Actual parameters – The arguments passed in to the method at a call– "hello", 3 in our example17More Control Statements in Ruby•A control statement is one that affects which instruction is executed next– We’ve seen two so far in Ruby•whileand function call• Ruby also has conditionalsif grade >= 90


View Full Document

UMD CMSC 330 - Organization of Programming Languages

Documents in this Course
Exam #1

Exam #1

6 pages

Quiz #1

Quiz #1

2 pages

Midterm 2

Midterm 2

12 pages

Exam #2

Exam #2

7 pages

Ocaml

Ocaml

7 pages

Parsing

Parsing

38 pages

Threads

Threads

12 pages

Ruby

Ruby

7 pages

Quiz #3

Quiz #3

2 pages

Threads

Threads

7 pages

Quiz #4

Quiz #4

2 pages

Exam #2

Exam #2

6 pages

Exam #1

Exam #1

6 pages

Threads

Threads

34 pages

Quiz #4

Quiz #4

2 pages

Threads

Threads

26 pages

Exam #2

Exam #2

9 pages

Exam #2

Exam #2

6 pages

Load more
Download Organization of Programming Languages
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Organization of Programming Languages and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Organization of Programming Languages 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?