Introdução a Linguagem de Modelagem TerraML

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Intermediate Code Generation
Programming Languages and Paradigms The C Programming Language.
References: 1. “Programming in LUA, 2 nd ed.”, Roberto Lerusalmschy Chapters (primarily) 2. “Lua Reference Manual” (included in Lua installation.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Lua By: Michael Coffman Peter Sussman. History Lua means ‘moon’ in Portuguese First appeared in 1993 Created by Roberto Ierusalimschy, Luiz Henrique de.
Roberto Ierusalimschy PUC-Rio, Brazil
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Guide To UNIX Using Linux Third Edition
Lua Matthew Spain | Kerry Zhao. Agenda Overview of Lua Language Details Application Areas Demo Conclusion.
Spatial Dynamical Modeling with TerraME Tiago Carneiro Gilberto Câmara.
Spatial Dynamical Modeling with TerraME Tiago Carneiro Gilberto Câmara Pedro Andrade Licence: Creative Commons ̶̶̶̶ By Attribution ̶̶̶̶ Non Commercial.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Spatial Dynamical Modeling with TerraME (part 2) Gilberto Câmara.
INTERNET APPLICATION DEVELOPMENT For More visit:
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Lua: The Programming Language. Some Things that Need to be Said Because of increasing demand for customizable applications, the trend nowadays is to split.
Games Development 2 Lua Scripting CO3301 Week 6. Contents Introducing Lua –Comparison with Python Lua Language Overview Interfacing Lua with C++
Engineering Computing I Chapter 4 Functions and Program Structure.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Variables, Environments and Closures. Overview Touch on the notions of variable extent and scope Introduce the notions of lexical scope and dynamic.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
Getting ready. Why C? Design Features – Efficiency (C programs tend to be compact and to run quickly.) – Portability (C programs written on one system.
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Spatial Dynamical Modeling with TerraME Tiago Carneiro Gilberto Câmara Pedro Andrade Licence: Creative Commons ̶̶̶̶ By Attribution ̶̶̶̶ Non Commercial.
Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade Tiago G. S. Carneiro Gilberto Câmara Münster, 2014.
Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade Münster, 2013.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Introdução a Linguagem de Modelagem TerraML Dr. Tiago Garcia de Senna Carneiro TerraLAB - Laboratório INPE/UFOP para Simulação e Modelagem dos Sistemas.
Lua for TerraME: A Short Introduction Pedro Ribeiro de Andrade São José dos Campos, 2011.
Web Database Programming Using PHP
Functional Programming
The language focusses on ease of use
Lecture 1b- Introduction
The need for Programming Languages
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Ruby Getting started & Ruby.New Presented by Mario Tayah
Scripting Languages Info derived largely from Programming Language Pragmatics, by Michael Scott.
Scope History of Ruby. Where can you use Ruby? General Features.
Web Database Programming Using PHP
XML QUESTIONS AND ANSWERS
Variables, Environments and Closures
Programming Languages and Paradigms
Spatial Dynamical Modeling with TerraME
بسم الله الرحمن الرحیم.
Programming Paradigms
Lua for TerraME: A Short Introduction
Implementing Chares in a High-Level Scripting Language
Programming Language Concepts (CIS 635)
PHP Introduction.
User-Defined Functions
Tutorial C#.
Chapter 8: Introduction to High-Level Language Programming
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Variables, Environments and Closures
Pointers, Dynamic Data, and Reference Types
PHP.
Python Primer 1: Types and Operators
Java Programming Language
Course Overview PART I: overview material PART II: inside a compiler
PHP an introduction.
Programming Languages and Paradigms
The Lua Chunk Vault, an enhancement to epics base
Procedure Linkages Standard procedure linkage Procedure has
Presentation transcript:

Introdução a Linguagem de Modelagem TerraML Dr. Tiago Garcia de Senna Carneiro TerraLAB - Laboratório INPE/UFOP para Simulação e Modelagem dos Sistemas Terrestres Fevereiro de 2010

Roberto Ierusalimschy PUC-Rio, Brazil Lua Roberto Ierusalimschy PUC-Rio, Brazil PUC-Rio is the Catholic University of Rio de Janeiro. Our Computer Science Department ("Departamento de Informatica") is considered the best one in Brazil. I am an associate professor there. Lua is the work of Waldemar Celes, Luiz H. Figueiredo and me, in no particular order. CGILua is the work of Renato Borges, Anna Hester and me; Anna and Renato are graduate students of mine... QUASE TODA ESSA APRESENTAÇÃO ESTAVA PRONTA NA WEB!!!

What is Lua? Yet Another Scripting Language an “extension” language implemented as a library in ANSI C Host Program Lua Interpreter -- a Lua script color = RED b = button { label = ‘OK’, x = 10, y = 20} Lua lives in a niche close to Tcl, Perl and Python. From its kind of use, Tcl is the closer; both Tcl and Lua were created as an embedded language (in opposition to Perl and Python). Both are small and "slim". Lua seems to be more appropriate than Tcl for real programs, and then gets as an alternative to Python and Perl. (In fact, I don't know whether Python is really a scripting language; it seems a very nice language, but a little "heavy" for real "quick-and-dirty" programming.) Lua is much smaller than Perl, on the other hand it has a much smaller library. I would say Perl is more appropriate for systems administration (standard Lua has no Posix facilities, only ANSI C), but is really for hackers.

Why Lua? Simple and flexible Small Efficient Portable “Simple things simple, complex things possible” Small Efficient Portable Whole library written in ANSI C, compiles the same source code in all platforms Typical uses: MS-DOS, Windows (3.1, 95, NT), Unix (Linux, Solaris, IRIX, AIX, ULTRIX), Next, OS/2, Mac Lua is smaller, faster and more portable than Tcl, Perl and Python. Simplicity and flexibility are more arguable qualities...

Where is Lua? Inside Brazil Outside Brazil Petrobras, the Brazilian Oil Company Embratel (the main telecommunication company in Brazil) many other companies Outside Brazil Lua is used in hundreds of projects, both commercial and academic CGILua still in restricted use until recently all documentation was in Portuguese CGILua is also spread, but mainly in Brazil. CGILua has got a commercial impact much bigger than Lua, and that created some pressure for documentation in Portuguese. Only recently we found the time to translate it to English... Lua and the Web

How is Lua? function fat (n) if n == 0 then return 1 else Pascal-like Syntax. Interpreter executes sequence of statements. function definitions are also statements (see later) Six types: numbers, tables, functions, strings, userdata, nil function fat (n) if n == 0 then return 1 else return n*fat(n-1) end

My first Lua program C = 2; -- rain/t K = 0.4; -- flow coefficient q = 0; -- RULES for time = 0, 20, 1 do -- soil water q = q + C - K*q; end print(“q = "..q);

Types

Type nil Different from everything else Default variable type Also acts as false (boolean)

Type boolean Comparison value if (rain == true) then ....

Unique native type for numbers Type number Unique native type for numbers double (by default) a = 3 b = 3.5 c = 4.5e-8

No size limit (read large files as strings) Type string Immutable No size limit (read large files as strings) No termination value (‘\0’) Powerful Pattern-matching in standard library myname = “Ciclano da Silva Sauro”;

Tables Implement associative arrays: any value (including functions and other tables) can be used both for indices and values t = {} -- creates an empty table t[1] = "hello" t.x = print -- t.x is sugar for t[‘x’] t.x(t[1]) -- prints ‘hello’ t.next = t -- circular list The first line creates an empty table, and stores a reference to it in “t”. Then the string “hello” is associated with index 1, and the function print is associated with index “x”.

Constructors Expressions to create and initialize tables Record style point={x=10,y=20} print(point.y) --> 20 List style days={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"} print(days[3]) --> Tue Mixed style points={{x=0,y=0}, point, n=2} print(points[points.n].y) --> 20 Constructors were inspired by some “declarative” languages, such as BibTex and IDL (a language for describing interfaces in Motif). Note in the last example a use of nested constructors: because a constructor is an expression, it can be used wherever a value is expected.

Table loc = { cover = "forest", distRoad = 0.3, distUrban = 2 }; loc.cover = “cerrado”; loc[“cover”] = “soja”; if (loc.distUrban > 1.5) then

Tables in Lua loc = { cover = "forest", distRoad = 0.3, distUrban = 2 }; loc.desfPot = loc.distRoad + loc.distUrban;

Tables em Lua : functions loc = { cover = "forest", distRoad = 0.3, distUrban = 2 }; ... loc.reset = function( self ) self.cover = ""; self.distRoad = 0.0; self.distUrban = 0.0; end

Constructors article{ author="F.P.Brooks", calls function “article” article( { author =…, tilte = …, year = ….} ) article{ author="F.P.Brooks", title="The Mythical Man-Month", year=1975, } The syntax “foo{...}” is only syntactic sugar for “foo({...})”, that is, a table is created by the constructor and then passed as argument to the function “foo”. Typically, such a function can check if the fields are correct, supply default values to some fields, and register the table in same global place. Many people write those kind of declarations in an application (a typical example is for describing a GU interface), and don’t even know they are “programming” in Lua...

Functions in Lua function fat (n) if n == 0 then return 1 else return n*fat(n-1) end

Functions in Lua First class values Example: cloning a table t function inc (x) return x+1 end inc = function (x) sugar Example: cloning a table t In the last example, “foreach” is a predefined function that applies a given function over all elements of a given table. For each element, the function is called with two arguments, the index and the value. Functions as first class values is a key mechanism in Lua; albeit few people do functional programming in Lua, this facility is used for Object-oriented programming in Lua, for redefining functions, and many other goods things. We will see some of them later. clone = {} ForEachCell(t, function (i,e) clone[i]=e end)

Upvalues Mechanism to allow functions to access non-local variables An upvalue is a variable expression whose value is computed when the enclosing function is instantiated (and not when the function is executed) function add (x) return function (y) return y+%x end add1 = add(1) print(add1(10)) --> 11 Upvalues give to Lua the full power of Lambda-Calculus. For programmers that do functional programming, this is a must. Like functions as first-class values, this is the kind of mechanism that most people do not understand how useful it can be. Nevertheless, even those people take great advantage of upvalues. The next slides show a somewhat unexpected use of upvalues that plays a key role in CGILua architecture. upvalue

Functions and Tables w = { redraw = function () ... end, pick = function (x,y) ... end, } if w.pick(x,y) then w.redraw() end In the last example, “foreach” is a predefined function that applies a given function over all elements of a given table. For each element, the function is called with two arguments, the index and the value. Functions as first class values is a key mechanism in Lua; albeit few people do functional programming in Lua, this facility is used for Object-oriented programming in Lua, for redefining functions, and many other goods things. We will see some of them later.

Tables x Objects Tables are dynamically created objects. in the sense of Hoare list = {value=v, next=list} list old list ... This is a big difference between tables in Lua and associative arrays in other languages, such as AWK and Tcl. Tables in Lua are “objects”, in the sense of Hoare, that is, dynamically allocated “things” manipulated through pointers to them. Tables in Lua can directly represent dynamic structures such as trees and graphs, even cyclic structures. Moreover, tables allow an Object-Oriented style of programming in Lua; see later. value - v next -

Objects First-class functions+ tables = almost OO Tables can have functions as fields Sugar for method definition and call Implicit parameter self This is only to illustrate how OO can be done in Lua. There is much more to say about that, but CGILua does not use those facilities, so this is not our focus here. Specifically, in the above scheme we miss inheritance. Lua does not provide inheritance, but it is very easy to implement delegation. With delegation, we can do a “prototype-base” OO programming. a.foo(a,x) a:foo(x) a.foo = function (self,x) ... end function a:foo (x) sugar

My second Lua program C = 2; -- rain/t K = 0.4; -- flow coefficient q = 0; -- function rain (t) if (t < 10) then return 4 – 4*math.cos(math.pi*t/10); else return 4 – 4*math.cos(math.pi*(t-10)/10); end -- for time = 0, 20, 1 do -- soil water q = q + rain(time) - K*q; -- report print(“q = "..q);

Standard libraries Basic String Table Math IO OS Debug Coroutine

Basic Basic functions print type setmetatable pairs

String String manipulation pattern matching string.find string.gsub

Table Function for table manipulation table.insert table.remove table.sort

Perguntas? Mais informações em: www.terralab.ufop.br www.terrame.org Obrigado… Perguntas? Mais informações em: www.terralab.ufop.br www.terrame.org