What s different about Factor?

Size: px
Start display at page:

Download "What s different about Factor?"

Transcription

1 Harshal Lehri

2 What s different about Factor? Factor is a concatenative programming language - A program can be viewed as a series of functions applied on data Factor is a stack oriented program - Data in Factor is stored on a stack - functions pop data from the stack and the output data is pushed on the same stack Factor uses an Image-based persistence model - the program code and data are saved in an image file, similar to core dumps Built in Foreign Function Interface that allows it to talk to declarative programs like C, Objective-C and Fortran

3 A Practical stack oriented language Factor supports popular functional programming concepts like currying and higher order functions( like map, reduce, filter) Factor supports object-oriented programming - via tuples and generic words Factor is dynamically typed and has a type system Factor supports powerful meta programming capabilities using parsing words Garbage collection, optimizing compiler, nice REPL, large standard library and more...

4 Concatenative Programming A program can be written as a chain of functions applied one after another, each modifying data before passing it to the next one Unix pipes are a good example of concatenative programming Unix pipes use a Queue to store intermediate results while Factor uses a Stack

5 Concatenative Programming- An Example Consider a Unix command like cat file1.txt grep filter-text awk {print $1} The program reads contents of file, filters lines containing the word filter-text and prints the word before the first whitespace in the line cat file1.txt File data grep filter-text Filtered Lines awk {print $1}

6 Words and Vocabularies Functions in Factor are encouraged to be small and read from left to right. They are known as words A set of words form a module and are called vocabularies Factor programs are a sequence of words (including ones that generate data into the stack) Words are usually 1-3 lines in length and larger ones can be factored out into smaller words applied after one another Words are separated only by spaces - this makes tokenization simple

7 A simple Factor program - Finding Factorial of 10 Suppose we want to calculate the factorial of 10 in Factor. We can do that as follows push 10 on the data stack push 1 on the stack 10 [1,b] 1 [ * ] reduce Generate a lazy sequence from 1 to number on top of the stack A quotation or a lambda function, here multiplication Apply reduce on the sequence on top of the stack The reduce function that takes a sequence, base number and a function, all present on the stack

8 Factorial of 10 - View from the REPL

9 Factorial of 10 - Key Takeaways Literals like 10, hello, 0.19 are treated as words themselves, they have the effect of adding the data to the stack Words use the postfix notation i.e data is pushed to the stack before the operator. Hence there is no notion of precedence required Words in factor can use any character, number or punctuation - only whitespace is used for tokenization. Hence we can have words like [a,b] [ * ] is an anonymous function or quotation. Note the whitespace in between [ and *. [ is a special word called parsing word

10 Writing a more general Program in Factor The previous program did not look much like a function - it worked for only one input The aim of the next program will be to create a general function as well as introduce the notions of parsing-word, stack-effects and combinators

11 Parsing-Words A parsing word is a special word that is part of the meta-programming of Factor Unlike regular words, parsing-words do not have an immediate effect on the stack - rather they interact with Factors parser to influence how successive words are to be parsed A Parsing-Word is defined using the SYNTAX: ; word (note SYNTAX: itself can be considered a parsing word)

12 Some common Parsing Words [... ] : These parser words are used to define quotations or anonymous functions. For example [ * ] {... } : These are parser words used to define arrays. For example { } H{... } : These are parser words used to define hash maps. For example H{ { A B } { C D } } : ; : These are parser words used to define functions USE: ; : Parser word to import packages TUPLE: ; : Parser word to define a class

13 Defining Functions in Factor A function definition in Factor is as follows Function Name Body of the function Parsing word begin : name ( x1 x2. xn -- y1 y2.ym ) body ; Parsing word end The stack effect of the function

14 Stack Effects Stack effects is an important feature in Factor. They behave like a pre-condition and post-condition for that function The notation ( x1 x2 xn -- y1 y2 ym ) means that the function processes x1 x2 xn items on the stack and output y1 y2.. ym on the stack The variable names themselves don t mean anything, the names are chosen to allow the user to quickly identify the behaviour of the function To use the names x1,x2 xn in the body, the :: parsing-word is used when declaring functions instead of :

15 Stack Effects - Examples dup ( x -- x x ) : Duplicate the top element of the stack drop ( x -- ) : Drop the top element of the stack swap ( x y -- y x ) : Swap the top two elements of the stack nip ( x y -- y ) : Remove second element from top on the stack rot ( x y z -- y z x ) : Rotate left top three elements of the stack -rot ( x y z -- z x y ) : Rotate right top three elements of the stack product ( {x1,...,xn} -- x1*...*xn ) : Product of an array

16 Dataflow Combinators Stack based programs require the user to run a mental stack machine, which becomes trickier when applications shuffle the stack (like swap) Dataflow Combinators simplify this by encapsulating common, easy to understand dataflows cleave combinators like bi, tri that apply multiple functions on a data value, for example the program 10 { [ 3 + ] [ 2 - ] } cleave results in the top of the stack having value 13 8 spread combinators like bi*, tri* takes a series of objects and a equal number of quotations and apply the quotation on the appropriate object napply combinators like bi@, tri@ take a quotation and an integer n and apply the quotation on the top n objects on the stack

17 Dataflow Combinators - Examples 10 [ 3 + ] [ 2 - ] bi results in the data stack having 13 and 8 as its top elements. Equivalent to 10 { [ 3 + ] [ 2 - ] } cleave [3 + ] [ 2 - ] bi* results in the data stack having 13 and 10 as its top elements. Equivalent to { [ 3 + ] [ 2 - ] } spread [ 2 + ] bi@ results in the data stack having 12 and 14 as its top elements. Equivalent to [ 2 + ] 2 napply

18 Currying in Factor Factor allows function currying using the curry word The curry word accepts a 10 [ + ] curry generates a new word on [ 10 + ] by absorbing the top element of the stack into the quotation The curry word requires two arguments an argument and a quotation, and absorbs the argument into the quotation For example if the top of the data stack looks like [ 2 + ] [ 3 + ] [ bi ]. Using the curry word, the new stack looks like [ 2 + ] [ ~quotation~ bi ]. Note that it only absorbed one argument at a time

19 Primality testing program in Factor Quotation of generating numbers from 2 to n A cleave combinator : prime? ( n --? ) [ sqrt [2,b] ] [ [ multiple? ] curry ] bi any? not ; Word name Stack effect for the word, this states that the word takes the top element of the stack and returns a boolean (The symbols themselves don t mean anything) Checks if one number is a multiple of another Negate the final result Checks if there is a number in a sequence that satisfies a given condition

20 Recursion in Factor : fib ( n -- fib(n) ) dup 1 > [ [ 1 - fib ] [ 2 - fib ] bi + ] when ; Factor performs tail-call optimization

21 Object System in Factor Factor is purely object-oriented programming language - every value is an object and basic operations are method calls Unlike traditional object-oriented programs, methods do not belong to a particular object or class, rather a method is defined as a generic word with its implementation being different for different classes

22 Defining new Classes - The Tuple: parsing word A class can be defined using the Tuple: parsing word as TUPLE : class-name field1 field2. ;. For example : TUPLE: circle radius ; TUPLE: rectangle length width ; Each instance variable has an associated getter and setter. For example the circle class has a radius>> getter and >>radius setter. Fields can be made read-only and by defining them like { radius read-only }

23 Creating Objects of a Class An object of the class can be created using the new word like rectangle new 10 >>length 10 >>width. or using the boa(by-order-of-arguments) constructor rectangle boa The boa constructor is common enough to have its own parsing defined as C: <rectangle> rectangle, which can be used as <rectangle>

24 Methods for classes - Generic words The GENERIC: parsing word allows a user to define methods common to different classes. For example an area method for the two defined shapes can be written as GENERIC: area ( shape -- area ) M: circle area radius>> dup * pi * ; M: rectangle area [ length>> ] [ width>> ] bi * ;

25 Derived Classes Primitive classes like Strings, Numbers and words cannot be subclassed Tuple classes offer single inheritance - rooted at a class called tuple More classes can be defined using set operations on Tuple classes like UNION: and INTERSECTION: Mixins are special Union class where some class can be added to a mixin that share a method Protocols consist of a set of generic words used by a Mixin. This is equivalent to an interface in other object oriented languages

26 Unit Tests and Documentation Unit Tests can be written using tools.test vocabulary. For example, [ t ] [ 2 prime? ] unit-test Similar to unit-tests, there are different words like must-fail, must-infer etc The help.markup and help.syntax vocabularies help in documentation

27 Documentation in Factor HELP: prime? { $values { "n" fixnum } { "?" boolean } } { $description "Tests if n is prime. n is assumed to be a positive integer." } ;

28 I/O in Factor Factor uses asynchronous input/output facilities, similar to NIO on the JVM or Node.js I/O system I/O is represented as lazy streams around which words are designed to read or write to a stream : read-lines ( path -- ) utf8 file-lines [ 1 safe-head write nl ] each ; Encoding of file Reads lines of a file as a lazy sequence read 1 element from the sequence and print it Apply quotation on each file line

29 Multithreading Factor is single threaded - so it emulates multithreading using coroutines - cooperative threads that periodically yield the core they are running on Factor allows for spawning of processes on multiple cores that communicate through channels Threads are created using spawn, with stop, suspend, sleep and resume words Channels use to and from similar to Akka s send and receive ( send and receive in Factor is used for marking quotations to be called when receiving or sending a messsage)

30 Other Features Factor allows using local variables using the :: parsing word by binding stack parameters to variables Factor allows using dynamic variables using the SYMBOL: parsing word along with get and set words to manipulate it. These variables can be bound to a particular scope using [ ]with-scope parsing words Factor has a built in HTTP server library Factor provides nice metaprogramming features in terms of macros, parsing words and functors Excellent REPL

31 Current Limitations Factors community is small. It is tricky to find information about Factor on the internet It s not always simple to think in terms of a single stack - many stack manipulating operations are tricky to understand and traditional programs have different implementation Factor is single threaded - so programs must be designed in an event driven manner

32 Some good resources on Factor Factor REPL can be downloaded from Slav Pestov s paper on Factor Andrea Ferreti s excellent tutorial about basics of Factor Concatenative programming websites Wiki on Factor Some good examples on and Slav s Google talk on

Parsing Combinators: Introduction & Tutorial

Parsing Combinators: Introduction & Tutorial Parsing Combinators: Introduction & Tutorial Mayer Goldberg October 21, 2017 Contents 1 Synopsis 1 2 Backus-Naur Form (BNF) 2 3 Parsing Combinators 3 4 Simple constructors 4 5 The parser stack 6 6 Recursive

More information

JVM ByteCode Interpreter

JVM ByteCode Interpreter JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Factor: a dynamic stack-based programming language

Factor: a dynamic stack-based programming language Factor: a dynamic stack-based programming language Slava Pestov Stack Effects LLC slava@factorcode.org Daniel Ehrenberg Carleton College ehrenbed@carleton.edu Joe Groff Durian Software joe@duriansoftware.com

More information

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Index. 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 information

CSCI-GA Scripting Languages

CSCI-GA Scripting Languages CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

More information

Parser Tools: lex and yacc-style Parsing

Parser Tools: lex and yacc-style Parsing Parser Tools: lex and yacc-style Parsing Version 5.0 Scott Owens June 6, 2010 This documentation assumes familiarity with lex and yacc style lexer and parser generators. 1 Contents 1 Lexers 3 1.1 Creating

More information

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Compiler Theory. (Semantic Analysis and Run-Time Environments) Compiler Theory (Semantic Analysis and Run-Time Environments) 005 Semantic Actions A compiler must do more than recognise whether a sentence belongs to the language of a grammar it must do something useful

More information

Programming Paradigms

Programming Paradigms PP 2017/18 Unit 12 Functions and Data Types in Haskell 1/45 Programming Paradigms Unit 12 Functions and Data Types in Haskell J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE

More information

Parser Tools: lex and yacc-style Parsing

Parser Tools: lex and yacc-style Parsing Parser Tools: lex and yacc-style Parsing Version 6.11.0.6 Scott Owens January 6, 2018 This documentation assumes familiarity with lex and yacc style lexer and parser generators. 1 Contents 1 Lexers 3 1.1

More information

EECS 311: Data Structures and Data Management Program 1 Assigned: 10/21/10 Checkpoint: 11/2/10; Due: 11/9/10

EECS 311: Data Structures and Data Management Program 1 Assigned: 10/21/10 Checkpoint: 11/2/10; Due: 11/9/10 EECS 311: Data Structures and Data Management Program 1 Assigned: 10/21/10 Checkpoint: 11/2/10; Due: 11/9/10 1 Project: Scheme Parser. In many respects, the ultimate program is an interpreter. Why? Because

More information

An introduction to Scheme

An introduction to Scheme An introduction to Scheme Introduction A powerful programming language is more than just a means for instructing a computer to perform tasks. The language also serves as a framework within which we organize

More information

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented Table of Contents L01 - Introduction L02 - Strings Some Examples Reserved Characters Operations Immutability Equality Wrappers and Primitives Boxing/Unboxing Boxing Unboxing Formatting L03 - Input and

More information

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17 List of Programs xxv List of Figures xxix List of Tables xxxiii Preface to second version xxxv PART 1 Structured Programming 1 1 Getting started 3 1.1 Programming 3 1.2 Editing source code 5 Source code

More information

Introduction to Programming Using Java (98-388)

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

Ruby: Introduction, Basics

Ruby: Introduction, Basics Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie

More information

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Familiarize yourself with all of Kotlin s features with this in-depth guide Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Copyright 2017 Packt Publishing First

More information

Chapter 1. Fundamentals of Higher Order Programming

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

Scala : an LLVM-targeted Scala compiler

Scala : 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 information

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

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

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

5. Introduction to the Lambda Calculus. Oscar Nierstrasz 5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming

More information

An introduction to functional programming. July 23, 2010

An introduction to functional programming. July 23, 2010 An introduction to functional programming July 23, 2010 About Outline About About What is functional programming? What is? Why functional programming? Why? is novel. is powerful. is fun. About A brief

More information

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011 Lecture 5: Declarative Programming. The Declarative Kernel Language Machine September 12th, 2011 1 Lecture Outline Declarative Programming contd Dataflow Variables contd Expressions and Statements Functions

More information

CS 360: Programming Languages Lecture 12: More Haskell

CS 360: Programming Languages Lecture 12: More Haskell CS 360: Programming Languages Lecture 12: More Haskell Geoffrey Mainland Drexel University Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia Administrivia Homework 5 due

More information

Programming Paradigms

Programming Paradigms PP 2017/18 Unit 11 Functional Programming with Haskell 1/37 Programming Paradigms Unit 11 Functional Programming with Haskell J. Gamper Free University of Bozen-Bolzano Faculty of Computer Science IDSE

More information

CS 360: Programming Languages Lecture 10: Introduction to Haskell

CS 360: Programming Languages Lecture 10: Introduction to Haskell CS 360: Programming Languages Lecture 10: Introduction to Haskell Geoffrey Mainland Drexel University Thursday, February 5, 2015 Adapted from Brent Yorgey s course Introduction to Haskell. Section 1 Administrivia

More information

CS 360 Programming Languages Interpreters

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

Functional Programming Language Haskell

Functional Programming Language Haskell Functional Programming Language Haskell Mohammed Aslam CIS 24 Prof. Kopec Presentation: 03 Date: 05/05/2003 Haskell is a general purpose, purely functional programming language named after the logician

More information

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Introduction to Typed Racket The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples Getting started Find a machine with DrRacket installed (e.g. the

More information

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang Chapter 1 Glossary For Introduction to Programming Using Python By Y. Daniel Liang.py Python script file extension name. assembler A software used to translate assemblylanguage programs into machine code.

More information

CHPSIM. Version 2.0. A Simulator and Debugger for the CHP Language. User Manual. Written by Marcel van der Goot and Chris Moore

CHPSIM. Version 2.0. A Simulator and Debugger for the CHP Language. User Manual. Written by Marcel van der Goot and Chris Moore CHPSIM Version 2.0 A Simulator and Debugger for the CHP Language User Manual Written by Marcel van der Goot and Chris Moore Copyright c 2010 Caltech All rights reserved. 1 2 Contents 1 Getting Started

More information

5/23/2015. Core Java Syllabus. VikRam ShaRma

5/23/2015. Core Java Syllabus. VikRam ShaRma 5/23/2015 Core Java Syllabus VikRam ShaRma Basic Concepts of Core Java 1 Introduction to Java 1.1 Need of java i.e. History 1.2 What is java? 1.3 Java Buzzwords 1.4 JDK JRE JVM JIT - Java Compiler 1.5

More information

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

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

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP)

Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Principles of Programming Languages COMP251: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

More information

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8 Epic Test Review 1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4 Write a line of code that outputs the phase Hello World to the console without creating a new line character. System.out.print(

More information

Introduction to Functional Programming and Haskell. Aden Seaman

Introduction to Functional Programming and Haskell. Aden Seaman Introduction to Functional Programming and Haskell Aden Seaman Functional Programming Functional Programming First Class Functions Expressions (No Assignment) (Ideally) No Side Effects Different Approach

More information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

Programming Language Pragmatics

Programming Language Pragmatics Chapter 10 :: Functional Languages Programming Language Pragmatics Michael L. Scott Historical Origins The imperative and functional models grew out of work undertaken Alan Turing, Alonzo Church, Stephen

More information

An Introduction to Object Orientation

An Introduction to Object Orientation An Introduction to Object Orientation Rushikesh K Joshi Indian Institute of Technology Bombay rkj@cse.iitb.ac.in A talk given at Islampur Abstractions in Programming Control Abstractions Functions, function

More information

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline :: Module Title Duration : Intro to JAVA SE7 and Programming using JAVA SE7 : 9 days Course Description The Java SE 7 Fundamentals course was designed to enable students with little or no programming experience

More information

Lecture #24: Programming Languages and Programs

Lecture #24: Programming Languages and Programs Lecture #24: Programming Languages and Programs A programming language is a notation for describing computations or processes. These range from low-level notations, such as machine language or simple hardware

More information

Continuations provide a novel way to suspend and reexecute

Continuations provide a novel way to suspend and reexecute Continuations provide a novel way to suspend and reexecute computations. 2. ML ( Meta Language ) Strong, compile-time type checking. Types are determined by inference rather than declaration. Naturally

More information

Haskell An Introduction

Haskell An Introduction Haskell An Introduction What is Haskell? General purpose Purely functional No function can have side-effects IO is done using special types Lazy Strongly typed Polymorphic types Concise and elegant A First

More information

Using Scala for building DSL s

Using Scala for building DSL s Using Scala for building DSL s Abhijit Sharma Innovation Lab, BMC Software 1 What is a DSL? Domain Specific Language Appropriate abstraction level for domain - uses precise concepts and semantics of domain

More information

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization. Where We Are Source Code Lexical Analysis Syntax Analysis Semantic Analysis IR Generation IR Optimization Code Generation Optimization Machine Code Where We Are Source Code Lexical Analysis Syntax Analysis

More information

Functional programming in LISP

Functional programming in LISP Programming Languages Week 4 Functional programming in LISP College of Information Science and Engineering Ritsumeikan University review of part 3 enumeration of dictionaries you receive a sequence of

More information

KLiC C++ Programming. (KLiC Certificate in C++ Programming)

KLiC C++ Programming. (KLiC Certificate in C++ Programming) KLiC C++ Programming (KLiC Certificate in C++ Programming) Turbo C Skills: Pre-requisite Knowledge and Skills, Inspire with C Programming, Checklist for Installation, The Programming Languages, The main

More information

Final Examination May 5, 2005

Final Examination May 5, 2005 CS 4352 Compilers and Interpreters Final Examination May 5, 2005 Name Closed Book. If you need more space ask for an extra sheet. 1. [4 points] Pick the appropriate data structure for each purpose: storage

More information

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen COP4020 Programming Languages Functional Programming Prof. Robert van Engelen Overview What is functional programming? Historical origins of functional programming Functional programming today Concepts

More information

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

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

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. IR Generation Announcements My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM. This is a hard deadline and no late submissions will be

More information

Chapter 6 Control Flow. June 9, 2015

Chapter 6 Control Flow. June 9, 2015 Chapter 6 Control Flow June 9, 2015 Expression evaluation It s common in programming languages to use the idea of an expression, which might be a simple object function invocation over some number of arguments

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. 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 information

CS 11 Haskell track: lecture 1

CS 11 Haskell track: lecture 1 CS 11 Haskell track: lecture 1 This week: Introduction/motivation/pep talk Basics of Haskell Prerequisite Knowledge of basic functional programming e.g. Scheme, Ocaml, Erlang CS 1, CS 4 "permission of

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

A LISP Interpreter in ML

A LISP Interpreter in ML UNIVERSITY OF OSLO Department of Informatics A LISP Interpreter in ML Mandatory Assignment 1 INF3110 September 21, 2009 Contents 1 1 Introduction The purpose of this assignment is to write an interpreter,

More information

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP)

Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Fundamentals of Artificial Intelligence COMP221: Functional Programming in Scheme (and LISP) Prof. Dekai Wu Department of Computer Science and Engineering The Hong Kong University of Science and Technology

More information

6.001 Notes: Section 6.1

6.001 Notes: Section 6.1 6.001 Notes: Section 6.1 Slide 6.1.1 When we first starting talking about Scheme expressions, you may recall we said that (almost) every Scheme expression had three components, a syntax (legal ways of

More information

KLiC C Programming. (KLiC Certificate in C Programming)

KLiC C Programming. (KLiC Certificate in C Programming) KLiC C Programming (KLiC Certificate in C Programming) Turbo C Skills: The C Character Set, Constants, Variables and Keywords, Types of C Constants, Types of C Variables, C Keywords, Receiving Input, Integer

More information

LECTURE 16. Functional Programming

LECTURE 16. Functional Programming LECTURE 16 Functional Programming WHAT IS FUNCTIONAL PROGRAMMING? Functional programming defines the outputs of a program as a mathematical function of the inputs. Functional programming is a declarative

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

More information

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

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

Introduction to Erlang. Franck Petit / Sebastien Tixeuil

Introduction to Erlang. Franck Petit / Sebastien Tixeuil Introduction to Erlang Franck Petit / Sebastien Tixeuil Firstname.Lastname@lip6.fr Hello World % starts a comment. ends a declaration Every function must be in a module one module per source file source

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Haskell Programming About the Tutorial Haskell is a widely used purely functional language. Functional programming is based on mathematical functions. Besides Haskell, some of the other popular languages that follow Functional

More information

Functional Programming

Functional Programming Functional Programming CS331 Chapter 14 Functional Programming Original functional language is LISP LISt Processing The list is the fundamental data structure Developed by John McCarthy in the 60 s Used

More information

Advance Mobile& Web Application development using Angular and Native Script

Advance Mobile& Web Application development using Angular and Native Script Advance Mobile& Web Application development using Angular and Native Script Objective:- As the popularity of Node.js continues to grow each day, it is highly likely that you will use it when you are building

More information

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives CS 6A Scheme Fall 207 Discussion 7: October 25, 207 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write

More information

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell

Haske k ll An introduction to Functional functional programming using Haskell Purely Lazy Example: QuickSort in Java Example: QuickSort in Haskell Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dk The most popular purely functional, lazy programming language Functional programming language : a program

More information

Programming Languages (PL)

Programming Languages (PL) 1 2 3 4 5 6 7 8 9 10 11 Programming Languages (PL) Programming languages are the medium through which programmers precisely describe concepts, formulate algorithms, and reason about solutions. In the course

More information

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7 Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions

More information

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1 A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

More information

Functional Programming. Big Picture. Design of Programming Languages

Functional Programming. Big Picture. Design of Programming Languages Functional Programming Big Picture What we ve learned so far: Imperative Programming Languages Variables, binding, scoping, reference environment, etc What s next: Functional Programming Languages Semantics

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

Concepts of programming languages

Concepts of programming languages Concepts of programming languages Lecture 7 Wouter Swierstra 1 Last time Relating evaluation and types How to handle variable binding in embedded languages? 2 DSLs: approaches A stand-alone DSL typically

More information

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers) Comp 104:Operating Systems Concepts Revision Lectures (separate questions and answers) Today Here are a sample of questions that could appear in the exam Please LET ME KNOW if there are particular subjects

More information

Web Application Development

Web Application Development Web Application Development Produced by David Drohan (ddrohan@wit.ie) Department of Computing & Mathematics Waterford Institute of Technology http://www.wit.ie JavaScript JAVASCRIPT FUNDAMENTALS Agenda

More information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

CS 231 Data Structures and Algorithms, Fall 2016

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

An introduction introduction to functional functional programming programming using usin Haskell

An introduction introduction to functional functional programming programming using usin Haskell An introduction to functional programming using Haskell Anders Møller amoeller@cs.au.dkau Haskell The most popular p purely functional, lazy programming g language Functional programming language : a program

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction Semantic Analysis David Sinclair Semantic Actions A compiler has to do more than just recognise if a sequence of characters forms a valid sentence in the language. It must

More information

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens Syntactic Analysis CS45H: Programming Languages Lecture : Lexical Analysis Thomas Dillig Main Question: How to give structure to strings Analogy: Understanding an English sentence First, we separate a

More information

Get Unique study materials from

Get Unique study materials from Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code

More information

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers)

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers) Comp 204: Computer Systems and Their Implementation Lecture 25a: Revision Lectures (separate questions and answers) 1 Today Here are a sample of questions that could appear in the exam Please LET ME KNOW

More information

Writing an Interpreter Thoughts on Assignment 6

Writing an Interpreter Thoughts on Assignment 6 Writing an Interpreter Thoughts on Assignment 6 CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, March 27, 2017 Glenn G. Chappell Department of Computer Science

More information

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA.

R13 SET Discuss how producer-consumer problem and Dining philosopher s problem are solved using concurrency in ADA. R13 SET - 1 III B. Tech I Semester Regular Examinations, November - 2015 1 a) What constitutes a programming environment? [3M] b) What mixed-mode assignments are allowed in C and Java? [4M] c) What is

More information

Overview of the Ruby Language. By Ron Haley

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

Final-Term Papers Solved MCQS with Reference

Final-Term Papers Solved MCQS with Reference Solved MCQ(S) From FinalTerm Papers BY Arslan Jan 14, 2018 V-U For Updated Files Visit Our Site : Www.VirtualUstaad.blogspot.com Updated. Final-Term Papers Solved MCQS with Reference 1. The syntax of PHP

More information

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input. More often than not, though, you ll want to use flex to generate a scanner that divides

More information

The Structure of a Syntax-Directed Compiler

The Structure of a Syntax-Directed Compiler Source Program (Character Stream) Scanner Tokens Parser Abstract Syntax Tree Type Checker (AST) Decorated AST Translator Intermediate Representation Symbol Tables Optimizer (IR) IR Code Generator Target

More information

Combined Object-Lambda Architectures

Combined Object-Lambda Architectures www.jquigley.com jquigley#jquigley.com Chicago Lisp April 2008 Research Goals System Goals Conventional Systems Unconventional Systems Research Goals Question: How to make with Pepsi and Coke? The Goal:

More information

Practical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction.

Practical Haskell. An introduction to functional programming. July 21, Practical Haskell. Juan Pedro Villa-Isaza. Introduction. Practical Practical An introduction to functional programming July 21, 2011 Contents Practical Practical is fun, and that s what it s all about! Even if seems strange to you at first, don t give up. Learning

More information

String Computation Program

String Computation Program String Computation Program Reference Manual Scott Pender scp2135@columbia.edu COMS4115 Fall 2012 10/31/2012 1 Lexical Conventions There are four kinds of tokens: identifiers, keywords, expression operators,

More information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

arxiv: v1 [cs.pl] 15 Dec 2009

arxiv: v1 [cs.pl] 15 Dec 2009 JSC : A JavaScript Object System Artur Ventura artur.ventura@ist.utl.pt January 0, 018 arxiv:091.861v1 [cs.pl] 15 Dec 009 Abstract The JSC language is a superset of JavaScript designed to ease the development

More information

Programming Languages 2nd edition Tucker and Noonan"

Programming Languages 2nd edition Tucker and Noonan Programming Languages 2nd edition Tucker and Noonan" " Chapter 1" Overview" " A good programming language is a conceptual universe for thinking about programming. " " " " " " " " " " " " "A. Perlis" "

More information

SRFIs: Libraries. Version August 10, 2015

SRFIs: Libraries. Version August 10, 2015 SRFIs: Libraries Version 6.2.1 August 10, 2015 The Scheme Requests for Implementation (a.k.a. SRFI) process allows individual members of the Scheme community to propose libraries and extensions to be supported

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

Programming in Scala Second Edition

Programming in Scala Second Edition Programming in Scala Second Edition Martin Odersky, Lex Spoon, Bill Venners artima ARTIMA PRESS WALNUT CREEK, CALIFORNIA Contents Contents List of Figures List of Tables List of Listings Foreword Foreword

More information

CSCI337 Organisation of Programming Languages LISP

CSCI337 Organisation of Programming Languages LISP Organisation of Programming Languages LISP Getting Started Starting Common Lisp $ clisp i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo

More information