Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Introduction to Gura Programming Language
www.gura-lang.org
Copyright © 2014 ypsitau@nifty.com
LL Diver on Aug 23, 2014
Copyright (C) 2014 ypsitau 2/49
Author
Name Yutaka Saito
Experience Embedded Firmware to GUI
Job History Electric-app make...
Copyright (C) 2014 ypsitau 3/49
Extension Module
Iterator Operation
Basic Specification
What's Gura?
Agenda
What's Gura?
Copyright (C) 2014 ypsitau 4/49
What's Gura?
Repeat processes appear in programs so often.
for (i = 0; i < 10; i++) {
}
pe...
Copyright (C) 2014 ypsitau 5/49
Case Study (1)
Here's a number sequence: -3, -2, -1, 0, 1, 2, 3.
Make a list of squared va...
Copyright (C) 2014 ypsitau 6/49
Gura's Program (1)
x = [-3, -2, -1, 0, 1, 2, 3]
y = x * x
Copyright (C) 2014 ypsitau 7/49
Gura's Program (1)
x = [-3, -2, -1, 0, 1, 2, 3]
y = x * x
Multiplying iterator is generate...
Copyright (C) 2014 ypsitau 8/49
Case Study (2)
Create a program that reads a text file and prints
its content along with l...
Copyright (C) 2014 ypsitau 9/49
Gura's Program (2)
printf('%d: %s',
1.., readlines('hello.c'))
Copyright (C) 2014 ypsitau 10/49
Gura's Program (2)
printf('%d: %s',
1.., readlines('hello.c'))
Iterator that executes pri...
Copyright (C) 2014 ypsitau 11/49
After All, Gura is ..
A language that can generate iterators
from iterators and evaluate ...
Copyright (C) 2014 ypsitau 12/49
Expected Benefits
Simplifies codes of repeat process.
Facilitates parallel computing, may...
Copyright (C) 2014 ypsitau 13/49
Idea for Parallel Computing
Elements in iterator generated last
Iterator generation
requi...
Copyright (C) 2014 ypsitau 14/49
Extension Module
Iterator Operation
Basic Specification
What's Gura?
Agenda
Basic Specifi...
Copyright (C) 2014 ypsitau 15/49
Basic Specification
Function
Control Sequence
OOP
Collection
Scope Management
Copyright (C) 2014 ypsitau 16/49
Basic Spec (1) Function
x = f(a => 3, b => 4)
f(a:number, b:number) = {
a * a + b * b
}
x...
Copyright (C) 2014 ypsitau 17/49
Basic Spec(1) Function
f(3) // a=3, b=[]
f(3, 1) // a=3, b=[1]
f(3, 1, 4, 1) // a=3, b=[1...
Copyright (C) 2014 ypsitau 18/49
Basic Spec(1) Function
my_loop(n) {block} = {
while (n > 0) {
block()
n -= 1
}
}
my_loop(...
Copyright (C) 2014 ypsitau 19/49
Basic Spec(2) Control Sequence
if (…) {
} elsif (…) {
} elsif (…) {
} else {
}
try {
} ca...
Copyright (C) 2014 ypsitau 20/49
Basic Spec(3) OOP
Fruit = class {
__init__(name:string, price:number) = {
this.name = nam...
Copyright (C) 2014 ypsitau 21/49
Basic Spec(3) OOP
A = class {
__init__(x, y) = {
// any jobs
}
}
B = class(A) {
__init__(...
Copyright (C) 2014 ypsitau 22/49
Basic Spec(4) Collection
a = [3, 1, 4, 1, 5, 9]
b = ['zero', 'one', 2, 3, 'four', 5]
c = ...
Copyright (C) 2014 ypsitau 23/49
Basic Spec(5) Scope Management
create_counter(n:number) = {
function {
n -= 1
}
}
c = cre...
Copyright (C) 2014 ypsitau 24/49
Extension Module
Iterator Operation
Basic Specification
What's Gura?
Agenda
Iterator Oper...
Copyright (C) 2014 ypsitau 25/49
Iterator Operation
Implicit Mapping
Member Mapping
Function
Repeat Control
Mapping
Genera...
Copyright (C) 2014 ypsitau 26/49
Gura's List and Iterator
List
Iterator
['apple', 'orange', 'grape']
('apple', 'orange', '...
Copyright (C) 2014 ypsitau 27/49
Gura's List and Iterator
Iterator
List Evaluation
Generation
Copyright (C) 2014 ypsitau 28/49
Iterator Operation(1) Implicit Mapping
Generates iterator embedding function or operator
...
Copyright (C) 2014 ypsitau 29/49
Iterator Operation(1) Implicit Mapping
f(a:number, b:number) = {
a * b
}
Usual Function
f...
Copyright (C) 2014 ypsitau 30/49
Iterator Operation(1) Implicit Mapping
f(3, 4)Number
f([2, 3, 4], [3, 4, 5])List
f((2, 3,...
Copyright (C) 2014 ypsitau 31/49
Iterator Operation(1) Implicit Mapping
List
Scalar
Iterator
List
Others
Mapping process d...
Copyright (C) 2014 ypsitau 32/49
Iterator Operation(1) Implicit Mapping
Generates an iterator
if at least one iterator exi...
Copyright (C) 2014 ypsitau 33/49
Iterator Operation(1) Implicit Mapping
Generates a list if there's no iterator and
at lea...
Copyright (C) 2014 ypsitau 34/49
Iterator Operation(1) Implicit Mapping
Generates a scalar
if only scalars exist in argume...
Copyright (C) 2014 ypsitau 35/49
Iterator Operation(2) Member Mapping
Member Mapping
fruits[0] fruits[1] fruits[2]
name na...
Copyright (C) 2014 ypsitau 36/49
Iterator Operation(2) Member Mapping
Member Mapping
fruits[0] fruits[1] fruits[2]
name na...
Copyright (C) 2014 ypsitau 37/49
Iterator Operation(2) Member Mapping
sum = 0
for (fruit in fruits) {
sum += fruit.price
}...
Copyright (C) 2014 ypsitau 38/49
Iterator Operation(3) Function
Function A function should return data sequence
by an iter...
Copyright (C) 2014 ypsitau 39/49
Iterator Operation(3) Function
rtn = readlines('hello.c'):list
rtn = range(10):list
List ...
Copyright (C) 2014 ypsitau 40/49
Iterator Operation(4) Repeat Control
Generate an iterator
from repeat control
Repeat Cont...
Copyright (C) 2014 ypsitau 41/49
Iterator Operation(4) Repeat Control
n = 0
x = for (i in 0..5):iter {
n += i
}
Nothing ha...
Copyright (C) 2014 ypsitau 42/49
Iterator Operation(4) Repeat Control
prime() = {
p = []
for (n in 2..):xiter {
if (!(n % ...
Copyright (C) 2014 ypsitau 43/49
Extension Module
Iterator Operation
Basic Specification
What's Gura?
Agenda
Extension Mod...
Copyright (C) 2014 ypsitau 44/49
Extension Module
Design Policy
Gura Interpreter itself should have as little dependency
o...
Copyright (C) 2014 ypsitau 45/49
Bundled Modules
GUI
wxWidgets Tk SDL
Graphic Drawing
Cairo OpenGL FreeType
Image Data
JPE...
Copyright (C) 2014 ypsitau 46/49
Cooperation between Modules
Gura Interpreter
JPEG PNG GIF BMP ICO XPM PPM TIFF
Cairo Open...
Copyright (C) 2014 ypsitau 47/49
Application Example
[ ID Photo Made at Home - Gura Shot ]
Creates ID photos by extracted ...
Copyright (C) 2014 ypsitau 48/49
Thank you
www.gura-lang.org
Upcoming SlideShare
Loading in …5
×

Introduction to Gura Programming Language

1,297 views

Published on

Introduction to Gura Programming Language.
This has been translated from a material written in Japanese for LL Diver event on Aug 23, 2014.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Introduction to Gura Programming Language

  1. 1. Introduction to Gura Programming Language www.gura-lang.org Copyright © 2014 ypsitau@nifty.com LL Diver on Aug 23, 2014
  2. 2. Copyright (C) 2014 ypsitau 2/49 Author Name Yutaka Saito Experience Embedded Firmware to GUI Job History Electric-app maker, chip maker, venture Current Job Free, unemployed rather Favorite Lang C++, Gura devoted to Gura
  3. 3. Copyright (C) 2014 ypsitau 3/49 Extension Module Iterator Operation Basic Specification What's Gura? Agenda What's Gura?
  4. 4. Copyright (C) 2014 ypsitau 4/49 What's Gura? Repeat processes appear in programs so often. for (i = 0; i < 10; i++) { } people.each do |person| end for x in range(10): hoge Can I deal them without verbose control sequence?
  5. 5. Copyright (C) 2014 ypsitau 5/49 Case Study (1) Here's a number sequence: -3, -2, -1, 0, 1, 2, 3. Make a list of squared values of them. Think it with your favorite language ... x y
  6. 6. Copyright (C) 2014 ypsitau 6/49 Gura's Program (1) x = [-3, -2, -1, 0, 1, 2, 3] y = x * x
  7. 7. Copyright (C) 2014 ypsitau 7/49 Gura's Program (1) x = [-3, -2, -1, 0, 1, 2, 3] y = x * x Multiplying iterator is generated. Its evaluation creates list. Iterator Lists generate iterators.1 2 3Evaluation List List Iterator Iterator List
  8. 8. Copyright (C) 2014 ypsitau 8/49 Case Study (2) Create a program that reads a text file and prints its content along with line numbers. Think it with your favorite language … 1: #include <std 2: int main() 3: { 4: printf(“H 5: }
  9. 9. Copyright (C) 2014 ypsitau 9/49 Gura's Program (2) printf('%d: %s', 1.., readlines('hello.c'))
  10. 10. Copyright (C) 2014 ypsitau 10/49 Gura's Program (2) printf('%d: %s', 1.., readlines('hello.c')) Iterator that executes printf for each item is generated. It's destroyed after evaluated. 1 2 Iterator Iterator Iterator Evaluation
  11. 11. Copyright (C) 2014 ypsitau 11/49 After All, Gura is .. A language that can generate iterators from iterators and evaluate them. Gura calls this operation “Mapping”. Iterator Iterator Iterator Iterator Iterator Iterator Iterator Evaluation
  12. 12. Copyright (C) 2014 ypsitau 12/49 Expected Benefits Simplifies codes of repeat process. Facilitates parallel computing, maybe. 1 2
  13. 13. Copyright (C) 2014 ypsitau 13/49 Idea for Parallel Computing Elements in iterator generated last Iterator generation requires less load. Evaluation stage needs much load. Distributes elements to processors for evaluation. Eval Iterator Iterator Iterator Iterator Iterator Iterator Iterator Evaluation Eval Eval
  14. 14. Copyright (C) 2014 ypsitau 14/49 Extension Module Iterator Operation Basic Specification What's Gura? Agenda Basic Specification
  15. 15. Copyright (C) 2014 ypsitau 15/49 Basic Specification Function Control Sequence OOP Collection Scope Management
  16. 16. Copyright (C) 2014 ypsitau 16/49 Basic Spec (1) Function x = f(a => 3, b => 4) f(a:number, b:number) = { a * a + b * b } x = f(3, 4) Definition (1) Call Type can be specified Named arguments
  17. 17. Copyright (C) 2014 ypsitau 17/49 Basic Spec(1) Function f(3) // a=3, b=[] f(3, 1) // a=3, b=[1] f(3, 1, 4, 1) // a=3, b=[1,4,1] f(a, b*) = { // any job } Call Definition (2) Variable-length argument that takes more than 0 value. b+ takes more than 1 value.
  18. 18. Copyright (C) 2014 ypsitau 18/49 Basic Spec(1) Function my_loop(n) {block} = { while (n > 0) { block() n -= 1 } } my_loop(3) { println('hello') } Definition (3) Call Takes block expression as function object. {block?} means an optional block.
  19. 19. Copyright (C) 2014 ypsitau 19/49 Basic Spec(2) Control Sequence if (…) { } elsif (…) { } elsif (…) { } else { } try { } catch (…) { } catch (…) { } for (…) { } repeat (…) { } while (…) { } Repeat Branch Exception cross (…) { }
  20. 20. Copyright (C) 2014 ypsitau 20/49 Basic Spec(3) OOP Fruit = class { __init__(name:string, price:number) = { this.name = name this.price = price } Print() = { printf('%s %dn', this.name, this.price) } } fruit = Fruit('Orange', 90) fruit.Print() Class Definition Instantiation and Method Call Constructor
  21. 21. Copyright (C) 2014 ypsitau 21/49 Basic Spec(3) OOP A = class { __init__(x, y) = { // any jobs } } B = class(A) { __init__(x, y, z) = {|x, y| // any jobs } } Inheritance Arguments for base class constructor
  22. 22. Copyright (C) 2014 ypsitau 22/49 Basic Spec(4) Collection a = [3, 1, 4, 1, 5, 9] b = ['zero', 'one', 2, 3, 'four', 5] c = %{ `a => 3, `b => 1, `c => 4 } d = %{ 'いぬ' => 'dog', 'ねこ' => 'cat' } List Dictionary
  23. 23. Copyright (C) 2014 ypsitau 23/49 Basic Spec(5) Scope Management create_counter(n:number) = { function { n -= 1 } } c = create_counter(4) c() // returns 3 c() // returns 2 c() // returns 1 Closure Each function has lexical scope.
  24. 24. Copyright (C) 2014 ypsitau 24/49 Extension Module Iterator Operation Basic Specification What's Gura? Agenda Iterator Operation
  25. 25. Copyright (C) 2014 ypsitau 25/49 Iterator Operation Implicit Mapping Member Mapping Function Repeat Control Mapping Generation Iterator Operation: Mapping and Generation Iterator Iterator Iterator Iterator Iterator
  26. 26. Copyright (C) 2014 ypsitau 26/49 Gura's List and Iterator List Iterator ['apple', 'orange', 'grape'] ('apple', 'orange', 'grape') All the elements are stored in memory. Each element would be generated. Capable of random access Only evaluation could make next element available
  27. 27. Copyright (C) 2014 ypsitau 27/49 Gura's List and Iterator Iterator List Evaluation Generation
  28. 28. Copyright (C) 2014 ypsitau 28/49 Iterator Operation(1) Implicit Mapping Generates iterator embedding function or operator Function or Operator argument values returned value Implicit Mapping Iterator Iterator Iterator Iterator
  29. 29. Copyright (C) 2014 ypsitau 29/49 Iterator Operation(1) Implicit Mapping f(a:number, b:number) = { a * b } Usual Function f(a:number, b:number):map = { a * b } Mappable Function Specifies attribute :map
  30. 30. Copyright (C) 2014 ypsitau 30/49 Iterator Operation(1) Implicit Mapping f(3, 4)Number f([2, 3, 4], [3, 4, 5])List f((2, 3, 4), (3, 4, 5))Iterator f(5, (3, 4, 5))Number and Iterator Answer: 12 Answer: [6, 12, 20] Answer: (6, 12, 20) Answer: (15, 20, 25)
  31. 31. Copyright (C) 2014 ypsitau 31/49 Iterator Operation(1) Implicit Mapping List Scalar Iterator List Others Mapping process depends arguments' data type Iterator Categorize data types Three rules to apply mapping
  32. 32. Copyright (C) 2014 ypsitau 32/49 Iterator Operation(1) Implicit Mapping Generates an iterator if at least one iterator exists in arguments. Rule 1 Iterator Iterator Iterator List Iterator Scalar Iterator Iterator Iterator
  33. 33. Copyright (C) 2014 ypsitau 33/49 Iterator Operation(1) Implicit Mapping Generates a list if there's no iterator and at least one list exists in arguments. Rule 2 List List List Scalar List List
  34. 34. Copyright (C) 2014 ypsitau 34/49 Iterator Operation(1) Implicit Mapping Generates a scalar if only scalars exist in arguments. Rule 3 Scalar Scalar Scalar
  35. 35. Copyright (C) 2014 ypsitau 35/49 Iterator Operation(2) Member Mapping Member Mapping fruits[0] fruits[1] fruits[2] name name name Print() Print() Print() price price price List of instances Generates an iterator to access instance members.
  36. 36. Copyright (C) 2014 ypsitau 36/49 Iterator Operation(2) Member Mapping Member Mapping fruits[0] fruits[1] fruits[2] name name name Print() Print() Print() price price price Iterator Generates an iterator to access instance members. fruits:*name fruits:*price fruits:*Print() List of instances
  37. 37. Copyright (C) 2014 ypsitau 37/49 Iterator Operation(2) Member Mapping sum = 0 for (fruit in fruits) { sum += fruit.price } println(sum) println(fruits:*price.sum()) Prints summation of Fruit instance's member price.Task Solution1 Using repeat control Using Member MappingSolution2
  38. 38. Copyright (C) 2014 ypsitau 38/49 Iterator Operation(3) Function Function A function should return data sequence by an iterator, not a list. rtn = readlines('hello.c') rtn = range(10) Iterator to generate strings of each line Iterator to generate numbers from 0 to 9 Design Policy Iterator
  39. 39. Copyright (C) 2014 ypsitau 39/49 Iterator Operation(3) Function rtn = readlines('hello.c'):list rtn = range(10):list List containing strings of each line List containing numbers from 0 to 9 List Call with attribute :list in order to get a listFunction Iterator
  40. 40. Copyright (C) 2014 ypsitau 40/49 Iterator Operation(4) Repeat Control Generate an iterator from repeat control Repeat Control values repeating job x = for (…):iter { } Evaluation result of repeating job comes to be the iterator's element Specify attribute :iter for repeat while cross Iterator
  41. 41. Copyright (C) 2014 ypsitau 41/49 Iterator Operation(4) Repeat Control n = 0 x = for (i in 0..5):iter { n += i } Nothing happens at this time println(x) Prints result: 0 1 3 6 10 15 Example of repeat control iterator
  42. 42. Copyright (C) 2014 ypsitau 42/49 Iterator Operation(4) Repeat Control prime() = { p = [] for (n in 2..):xiter { if (!(n % p.each() == 0).or()) { p.add(n) n } } } primes = prime() Iterator to generate numbers (2, 3, 5, 7..) Iterator to generate prime numbers
  43. 43. Copyright (C) 2014 ypsitau 43/49 Extension Module Iterator Operation Basic Specification What's Gura? Agenda Extension Module
  44. 44. Copyright (C) 2014 ypsitau 44/49 Extension Module Design Policy Gura Interpreter itself should have as little dependency on OS-specific functions and libraries as possible. It should extend capabilities by importing modules. Gura Interpreter Module ModuleModule Module Module Module
  45. 45. Copyright (C) 2014 ypsitau 45/49 Bundled Modules GUI wxWidgets Tk SDL Graphic Drawing Cairo OpenGL FreeType Image Data JPEG PNG GIF BMP ICO XPM PPM TIFF Network cURL Server Text Processing Regular Exp yamlXMLCSV markdown Archive and Compression TAR ZIP GZIP BZIP
  46. 46. Copyright (C) 2014 ypsitau 46/49 Cooperation between Modules Gura Interpreter JPEG PNG GIF BMP ICO XPM PPM TIFF Cairo OpenGL FreeType wxWidgets Tk SDL image Graphic Drawing Display Output Read/Write of Image Data
  47. 47. Copyright (C) 2014 ypsitau 47/49 Application Example [ ID Photo Made at Home - Gura Shot ] Creates ID photos by extracted face image from a file of digital camera. Outputs results in PDF and JPEG. JPEG image Cairo image JPEG wxWidgets Reading File Composing Image Writing File Output to Display
  48. 48. Copyright (C) 2014 ypsitau 48/49 Thank you www.gura-lang.org

×