Ruby: Introduction, Basics
|
|
- David Rodgers
- 6 years ago
- Views:
Transcription
1 Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3
2 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie objects) Inheritance Strongly typed Classes determine valid operations Some familiar operators Arithmetic, bitwise, comparison, logical Some familiar keywords if, then, else, while, for, class, new
3 But Ruby Looks Different Punctuation Omit: ;'s and ()'s on function calls Include: Function names ending in? and! New keywords and operators def, do..end, yield, unless ** (exp), =~ (match), <=> (spaceship) Rich core libraries Collections: Hashes, Arrays Strings and regular expressions Enumerators for iteration
4 Deeper Differences As Well Interpreted (typically) Run a program directly, without compiling Dynamically typed Objects have types, variables don't Everything is an object C.f. primitives in Java Code can be passed in to a function as a parameter Added to Java in version 8 ("lambdas")
5 Compiling Programs Program = Text file Contains easy-to-understand statements like "print", "if", "while", etc. But a computer can only execute machine instructions Instruction set architecture of the CPU A compiler translates the program (source code) into an executable (machine code) Recall "Bugs World" from CSE 2231 Examples: C, C++, Objective-C, Ada
6 Interpreting Programs An interpreter reads a program and executes it directly Advantages Platform independence Read-eval-print loop (aka REPL) Reflection Disadvantages Speed Later error detection (i.e., at run time) Examples: JavaScript, Python, Ruby
7 Combination of Both A language is not inherently compiled or interpreted A property of its implementation Sometimes a combination is used: Compile source code into an intermediate representation (byte code) Interpret the byte code Examples of combination: Java, C#
8 Ruby is (Usually) Interpretted REPL with Ruby interpreter, irb $ irb >> => 7 >> puts "hello world" hello world => nil >> def square(x) x**2 end => :square >> square -4 => 16
9 Literals Numbers (FixNum, Float, Rational, Complex) 83, 0123, 0x53, 0b , 0b101_ , e2, 12345E-2 2/3r, 4+3i Strings Delimeters " " and ' ' Interpolation of #{ } occurs (only) inside " " "Sum 6+3 is #{6+3}" is "Sum 6+3 is 9" Custom delimeter with %Q$ $ or %q$ $ Ranges 0..4 includes start and end value (0,1,2,3,4) "cab"..."cat" does not include end value Arrays and hashes (later)
10 Comments and Statements Single-line comments start with # Don't confuse it with string interpolation! Multi-line comments bracketed by =begin =end Must appear at beginning of line All statements have a value result Convention: => to indicate result "Hi #{name}" + "!" #=> "Hi Liam!"
11 Operators Arithmetic: + - * / % ** / is either or div, depending on operands Integer / (div) rounds towards -, not 0 % is modulus, not remainder 1 / 3.0 #=> / 3 #=> 0 (same as Java) -1 / 3 #=> -1 (not 0 as in Java) -1 % 3 #=> 2 (not -1 as in Java) Bitwise: ~ & ^ << >> 5 2 #=> 7 (ie 0b101 0b10) 13 ^ 6 #=> 11 (ie 0b1101 ^ 0b0110) 5 << 2 #=> 20 (ie 0b101 << 2)
12 Operators (Continued) Comparison: < > <= >= <=> Last is so-called "spaceship operator" Returns -1/0/1 iff LHS is smaller/equal/ larger than RHS "cab" <=> "da" #=> -1 "cab" <=> "ba" #=> 1 Logical: &&! and or not Words have low precedence (below =) "do_this or die" idiom needs low-binding x = crazy or raise "problem"
13 Pseudo Variables Objects self, the receiver of the current method (recall this) nil, nothingness (recall null) Booleans true, false nil also evaluates to false 0 is not false, it is true just like 1 or -4! Specials FILE, the current source file name LINE, the current line number
14 Significance in Names A variable's name affects semantics! Variable name determines its scope Local: start with lowercase letter (or _) Global: start with $ Many pre-defined global variables exist, e.g.: $/ is the input record separator (newline) $; is the default field separator (space) Instance: start Class: start Variable name determines mutability Constant: start with uppercase, eg Size but idiom is all upper case, eg SIZE
15 Basic Statements: Conditionals Classic structure if (boolean_condition) [then]... else... end But usually omit ( )'s and "then" keyword if x < 10 puts "small" end "If" keyword also a statement modifier x = x + 1 if x < LIMIT Good for single-line body Good when statement execution is common case Good for positive conditions
16 Variations on Conditionals Unless: equivalent to "if not " unless size >= 10 puts "small" end Can also be a statement modifier x = x + 1 unless x >= LIMIT Same idiom: single-line body, execution is common case, and positive condition Do not use "else" with "unless" Do not use negation in condition Do not use else with statement modifiers
17 Pitfalls with Conditionals Keyword "elsif" instead of "else if" if x < 10 puts "small" elsif x < 20 puts "medium" else puts "large" end If's do not create nested lexical scope if x < 10 y = x end puts y #y is defined, but could be nil puts z #NameError: undefined local var z
18 Case Statements are General [variable = ] case expression when nil statements execute if the expr was nil when value # e.g. 0, 'start' statements execute if expr equals value when type # e.g. String statements execute if expr resulted in Type when /regexp/ # e.g. /[aeiou]/ statements execute if expr matches regexp when min..max statements execute if the expr is in range else statements end
19 Basic Iteration: While and Until Classic structure while boolean_condition [do] end Can also be used as a statement modifier work while awake Until: equivalent to "while not " until i > count end Can also be a used as a statement modifier Pitfall: Modified block executes at least once sleep while dark #may not sleep at all begin i = i + 1 end while i < MAX #always increments i at least once
20 Functions Definition: keyword def def foo (x, y) x + y end Notice: no types in signature No types for parameters No types for return value All functions return something Value of last statement implicitly returned Convention: Omit explicit return statement def foo(x, y) x + y # last statement executed end
21 Functions Dot notation for method call Math::PI.rationalize() #rec vr Math::PI Convention: Omit () s in definition of functions with no parameters def launch() def launch end #bad end #good Parens can be omitted in calls too! Math::PI.rationalize puts Hello World Convention: omit for keyword-like calls attr_reader :name, :age Note: needed when chaining foo(13).equal? value
22 Summary Ruby is a general-purpose, imperative, object-oriented language Ruby is (usually) interpreted REPL Familiar flow-of-control and syntax Some new constructs (e.g., unless, until) Terse (e.g., optional parentheses, optional semicolons, statement modifiers)
23 Primitive vs Reference Types Recall Java type dichotomy: Primitive: int, float, double, boolean, Reference: String, Set, NaturalNumber, A variable is a "slot" in memory Primitive: the slot holds the value itself Reference: the slot holds a pointer to the value (an object) a 34 d width: 12 height: 15 color: "blue"
24 Object Value vs Reference Value Variable of reference type has both: Reference value: value of the slot itself Object value: value of object it points to (corresponding to its mathematical value) Variable of primitive type has just one Value of the slot itself, corresponding to its mathematical value a 34 d width: 12 height: 15 color: "blue"
25 Two Kinds of Equality Question: "Is x equal to y?" A question about the mathematical value of the variables x and y In Java, depending on the type of x and y we either need to: Compare the values of the slots x == y // for primitive types Compare the values of the objects x.equals(y) // for non-primitive types
26 Ruby: "Everything is an Object" In Ruby, every variable maps to an object Integers, floats, strings, sets, arrays, Benefit: A more consistent mental model References are everywhere Every variable has both a reference value and an object value Equality of mathematical value always means comparing object values Ruby terminology: Reference value is called the "object id" The 4- or 8-byte number stored in the slot Unique identifier for corresponding object msg = "hi" msg.object_id #=>
27 Everything is an Object a 34 d width: 12 height: 15 color: "blue" done msg true "shark" list <1,2,8,2>
28 Operational Detail: Immediates For small integers, the mathematical value is encoded in the reference value! LSB of reference value is 1 Remaining bits encode value, 2's complement x = 0 x.object_id #=> 1 (0b ) y = 6 y.object_id #=> 13 (0b ) Benefit: Performance No change to model (everything is an object) Known as an "immediate" value Other immediates: true, false, nil, symbols
29 Objects Have Methods Familiar "." operator to invoke (instance) methods list = [6, 15, 3, -2] list.size #=> 4 Since numbers are objects, they have methods too! 3.to_s #=> "3" 3.odd? #=> true 3.lcm 5 #=> #=> 8 3.class #=> FixNum 3.methods #=> [:to_s, :inspect, :+, ]
30 Pitfall: Equality Operator Reference value is still useful sometimes "Do these variables refer to the same object?" So we still need 2 methods: x == y x.equal? y Ruby semantics are the opposite of Java! == is object value equality.equal? is reference value equality Example s1, s2 = "hi", "hi" s1 == s2 #=> true (obj values equal) s1.equal? s2 #=> false (ref vals differ)
31 Assignment (Just Like Java) Assignment copies the reference value Result: Both variables point to the same object (ie an "alias") Parameter passing works this way too a b <5, 1> <3, 4>
32 Assignment (Just Like Java) Assignment copies the reference value Result: Both variables point to the same object (ie an "alias") Parameter passing works this way too a b a b a = b; <5, 1> <3, 4> <5, 1> <3, 4>
33 Assignment (Just Like Java) Assignment copies the reference value Result: Both variables point to the same object (ie an "alias") Parameter passing works this way too a b a b a = b; <5, 1> <3, 4> <5, 1> <3, 4>
34 Aliasing Mutable Objects When aliases exist, a statement can change a variable's object value without mentioning that variable x = [3, 4] y = x # x and y are aliases y[0] = 13 # changes x as well! Question: What about numbers? i = 34 j = i # i and j are aliases j = j + 1 # does this increment i too?
35 Immutability Recall in Java strings are immutable No method changes the value of a string A method like concat returns a new instance Benefit: Aliasing immutable objects is safe Immutability is used in Ruby too Numbers, true, false, nil, symbols list = [3, 4] list[0] = 13 # changes list's object value # list points to same object n = 34 n = n + 1 # changes n's reference value # n points to different object Pitfall: Unlike Java, strings in Ruby are mutable
36 Assignment Operators Arithmetic contraction += -= *= /= %= **= Pitfall: no ++ or -- operators (use += 1) Logical contraction = &&= Idiom: = for initializing potentially nil variables Pitfall (minor): x = y not quite equivalent to x = x y Better to think of it as x x = y Usually amounts to the same thing Parallel assignment x, y, z = y, 10, radius
37 Declared vs Dynamic Types In Java, types are associated with both Variables ("declared" / "static" type), and Objects ("dynamic" / "run-time" type) Queue line = new Queue1L(); Recall: Programming to the interface Compiler uses declared type for checks line.inc(); //error no such method line = new Set1L(); //error wrong type boolean isempty (Set s) { } if isempty(line) //error arg type
38 Statically Typed Language line Queue <1, 2, 8, 2> Queue1L msg String d Shape "hello" String width: 12 height: 15 color: "blue" Rectangle
39 Dynamically Typed Language line <1, 2, 8, 2> Queue1L msg "hello" String d width: 12 height: 15 color: "blue" Rectangle
40 Dynamically Typed Language Equivalent definitions: No static types Dynamic types only Variables do not have type, objects do
41 Function Signatures Statically typed String parse(char[] s, int i) { return e;} out = parse(t, x); Parameter types (i.e. s and i) are declared Return type (i.e. of parse) is declared The compiler checks conformance of (Declared) types of arguments (t, x) (Declared) type of return expression (e) (Declared) type of expression using parse (out) Dynamically typed def parse(s, i) end out = parse t, x You are on your own!
42 Type Can Change at Run-time Statically Typed //a is undeclared String a; //a is null string a = "hi; //compile-time err a = "hi"; a = 3; //compile-time err a.push(); //compile-time err Dynamically Typed //a is undefined a = a //a is nil a = "hi //load-time error a = "hi" a = 3 //a is now a number a.crazy //run-time error
43 Changing Dynamic Type line <1, 2, 8, 2> Queue1L msg "hello" String
44 Changing Dynamic Type msg, line = line, msg line <1, 2, 8, 2> Queue1L msg "hello" String
45 Changing Dynamic Type msg, line = line, msg line line <1, 2, 8, 2> Queue1L <1, 2, 8, 2> Queue1L msg msg "hello" String "hello" String
Ruby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationRuby: Objects and Dynamic Types
Ruby: Objects and Dynamic Types Computer Science and Engineering College of Engineering The Ohio State University Lecture 5 Primitive vs Reference Types Recall Java type dichotomy: Primitive: int, float,
More informationJavaScript: Introduction, Types
JavaScript: Introduction, Types Computer Science and Engineering College of Engineering The Ohio State University Lecture 19 History Developed by Netscape "LiveScript", then renamed "JavaScript" Nothing
More informationCS 5142 Scripting Languages
CS 5142 Scripting Languages 10/25/2012 Ruby 1 Outline Ruby Martin Hirzel 2 About Ruby Invented 1995 by Yokihiro Matz Matsumoto Influenced by SmallTalk Everything is an object (even e.g., integers) Blocks
More informationCSE 341, Autumn 2015, Ruby Introduction Summary
CSE 341, Autumn 2015, Ruby Introduction Summary Disclaimer: This lecture summary is not necessarily a complete substitute for atting class, reading the associated code, etc. It is designed to be a useful
More informationJAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 2 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) AGENDA
More informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationCMSC 330: Organization of Programming Languages. OCaml Imperative Programming
CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Spring 2018 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory
More informationCS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find
CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS
More informationThe Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.
The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationCMPT 125: Lecture 3 Data and Expressions
CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,
More informationCSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013
CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Winter 2013 Ruby logistics Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage
More informationCS 360 Programming Languages Interpreters
CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like
More informationCMSC 330: Organization of Programming Languages. OCaml Imperative Programming
CMSC 330: Organization of Programming Languages OCaml Imperative Programming CMSC330 Fall 2017 1 So Far, Only Functional Programming We haven t given you any way so far to change something in memory All
More informationRuby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework
Ruby logistics CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP Dan Grossman Autumn 2018 Next two sections use the Ruby language http://www.ruby-lang.org/ Installation / basic usage
More informationFRAC: Language Reference Manual
FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer
More informationThe PCAT Programming Language Reference Manual
The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language
More informationCS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016
CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 In this course you will start by building a compiler for a language called Xi. This is an imperative,
More informationCS 231 Data Structures and Algorithms, Fall 2016
CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard
More informationVENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals
VENTURE COMS 4115 - Language Reference Manual Zach Adler (zpa2001), Ben Carlin (bc2620), Naina Sahrawat (ns3001), James Sands (js4597) Section 1. Lexical Elements 1.1 Identifiers An identifier in VENTURE
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationYour First Ruby Script
Learn Ruby in 50 pages Your First Ruby Script Step-By-Step Martin Miliauskas @mmiliauskas 1 Your First Ruby Script, Step-By-Step By Martin Miliauskas Published in 2013 by Martin Miliauskas On the web:
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationScala : an LLVM-targeted Scala compiler
Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................
More informationThe SPL Programming Language Reference Manual
The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationClient-Side Web Technologies. JavaScript Part I
Client-Side Web Technologies JavaScript Part I JavaScript First appeared in 1996 in Netscape Navigator Main purpose was to handle input validation that was currently being done server-side Now a powerful
More informationChapter 3 Syntax, Errors, and Debugging. Fundamentals of Java
Chapter 3 Syntax, Errors, and Debugging Objectives Construct and use numeric and string literals. Name and use variables and constants. Create arithmetic expressions. Understand the precedence of different
More informationTopics Covered Thus Far CMSC 330: Organization of Programming Languages
Topics Covered Thus Far CMSC 330: Organization of Programming Languages Names & Binding, Type Systems Programming languages Ruby Ocaml Lambda calculus Syntax specification Regular expressions Context free
More informationComputational Expression
Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name
More informationCS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)
CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going
More informationPrinciples of Programming Languages
Principles of Programming Languages www.cs.bgu.ac.il/~ppl172 Collaboration and Management Dana Fisman Lesson 2 - Types with TypeScript 1 Types What are types in programming languages? What types are you
More informationOCaml Data CMSC 330: Organization of Programming Languages. User Defined Types. Variation: Shapes in Java
OCaml Data : Organization of Programming Languages OCaml 4 Data Types & Modules So far, we ve seen the following kinds of data Basic types (int, float, char, string) Lists Ø One kind of data structure
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationAdvanced Algorithms and Computational Models (module A)
Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value
More informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationCSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking
CSE450 Translation of Programming Languages Lecture 11: Semantic Analysis: Types & Type Checking Structure Project 1 - of a Project 2 - Compiler Today! Project 3 - Source Language Lexical Analyzer Syntax
More information9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement
Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationIntroduction CMSC 330: Organization of Programming Languages. Books on Ruby. Applications of Scripting Languages
Introduction CMSC 330: Organization of Programming Languages Ruby is an object-oriented, imperative scripting language I wanted a scripting language that was more powerful than Perl, and more object-oriented
More informationCOP4020 Programming Assignment 1 - Spring 2011
COP4020 Programming Assignment 1 - Spring 2011 In this programming assignment we design and implement a small imperative programming language Micro-PL. To execute Mirco-PL code we translate the code to
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationIC Language Specification
CS 301 Spring 2016 IC Language Specification The IC Language For the implementation project, you will build a compiler for an object-oriented language called IC (for Irish Coffee 1 ), which is essentially
More informationNOTE: Answer ANY FOUR of the following 6 sections:
A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationSPARK-PL: Introduction
Alexey Solovyev Abstract All basic elements of SPARK-PL are introduced. Table of Contents 1. Introduction to SPARK-PL... 1 2. Alphabet of SPARK-PL... 3 3. Types and variables... 3 4. SPARK-PL basic commands...
More informationIntroduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language
Chapter 1 Getting Started Introduction To Java Most people are familiar with Java as a language for Internet applications We will study Java as a general purpose programming language The syntax of expressions
More informationLecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.
Lecture 09: Data Abstraction ++ Parsing Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree. program text Parser AST Processor Compilers (and some interpreters)
More informationOutline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring
Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,
More information4. Inputting data or messages to a function is called passing data to the function.
Test Bank for A First Book of ANSI C 4th Edition by Bronson Link full download test bank: http://testbankcollection.com/download/test-bank-for-a-first-book-of-ansi-c-4th-edition -by-bronson/ Link full
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationCPS122 Lecture: From Python to Java last revised January 4, Objectives:
Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.
More informationChapter 17. Fundamental Concepts Expressed in JavaScript
Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries
More informationThese are reserved words of the C language. For example int, float, if, else, for, while etc.
Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.
More informationLecture 16: Static Semantics Overview 1
Lecture 16: Static Semantics Overview 1 Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing Produces trees Detects & eliminates ill-formed parse trees Static semantic analysis
More informationNotes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)
Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) David Haraburda January 30, 2013 1 Introduction Scala is a multi-paradigm language that runs on the JVM (is totally
More informationThe Typed Racket Guide
The Typed Racket Guide Version 5.3.6 Sam Tobin-Hochstadt and Vincent St-Amour August 9, 2013 Typed Racket is a family of languages, each of which enforce
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions
More informationTypescript on LLVM Language Reference Manual
Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String
More informationFunctional Programming Languages (FPL)
Functional Programming Languages (FPL) 1. Definitions... 2 2. Applications... 2 3. Examples... 3 4. FPL Characteristics:... 3 5. Lambda calculus (LC)... 4 6. Functions in FPLs... 7 7. Modern functional
More informationRuby: Blocks, Hashes, and Symbols
Ruby: Blocks, Hashes, and Symbols Computer Science and Engineering College of Engineering The Ohio State University Lecture 7 Blocks A block is a statement(s) passed in as an argument to a function 5.times
More informationChapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics
Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional
More informationComputer System and programming in C
1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign
More informationChapter 1. Fundamentals of Higher Order Programming
Chapter 1 Fundamentals of Higher Order Programming 1 The Elements of Programming Any powerful language features: so does Scheme primitive data procedures combinations abstraction We will see that Scheme
More informationThe Warhol Language Reference Manual
The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming
More informationIndex. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309
A Arithmetic operation floating-point arithmetic, 11 12 integer numbers, 9 11 Arrays, 97 copying, 59 60 creation, 48 elements, 48 empty arrays and vectors, 57 58 executable program, 49 expressions, 48
More informationCPS122 Lecture: From Python to Java
Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationLECTURE 17. Expressions and Assignment
LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)
More informationENGR 101 Engineering Design Workshop
ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as
More informationPython The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT
Python The way of a program Srinidhi H Asst Professor Dept of CSE, MSRIT 1 Problem Solving Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution
More informationSummer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define
CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationSimple Java Reference
Simple Java Reference This document provides a reference to all the Java syntax used in the Computational Methods course. 1 Compiling and running... 2 2 The main() method... 3 3 Primitive variable types...
More informationOverview of the Ruby Language. By Ron Haley
Overview of the Ruby Language By Ron Haley Outline Ruby About Ruby Installation Basics Ruby Conventions Arrays and Hashes Symbols Control Structures Regular Expressions Class vs. Module Blocks, Procs,
More informationCOMP322 - Introduction to C++ Lecture 02 - Basics of C++
COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.
More informationFull file at
Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional
More informationegrapher Language Reference Manual
egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction
More informationSpring 2018 Discussion 7: March 21, Introduction. 2 Primitives
CS 61A Scheme Spring 2018 Discussion 7: March 21, 2018 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Type Systems, Names and Binding CMSC 330 - Spring 2013 1 Topics Covered Thus Far! Programming languages Ruby OCaml! Syntax specification Regular expressions
More informationCompilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam
Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:
More informationDaMPL. Language Reference Manual. Henrique Grando
DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4
More informationScheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax
Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is
More informationContents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual
Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9
More informationCSCE 120: Learning To Code
CSCE 120: Learning To Code Manipulating Data I Introduction This module is designed to get you started working with data by understanding and using variables and data types in JavaScript. It will also
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More information15.1 Origins and Uses of Ruby
15.1 Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in 1996 - Use spread rapidly in Japan - Use is now growing in part because of its use in Rails - A pure object-oriented purely interpreted
More informationCGS 3066: Spring 2015 JavaScript Reference
CGS 3066: Spring 2015 JavaScript Reference Can also be used as a study guide. Only covers topics discussed in class. 1 Introduction JavaScript is a scripting language produced by Netscape for use within
More informationLanguage Reference Manual
ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More information