Date post: | 22-May-2015 |
Category: |
Technology |
Upload: | memeapps |
View: | 1,961 times |
Download: | 2 times |
102 - MemeScript Prerequisites
101 - Hello Meme IDE
introduction to
Contents
1
2 MemeScript Example3 Meme IDE Function Editor4 Primitive Types5 Declaring Integer Variables6 Declaring Decimal Variables7 Declaring Boolean Variables8 Declaring Strings9 Default Initializations10 Pre-defined Complex Types11 IF 12 IF/ELSE13 IF/ELSEIF/ELSE14 WHILE15 FOR16 Arithmetic17 Logical Operations18 Dataspace19 Defining a ‘Person’ Record20 Adding Attributes to the ‘Person’ Record
21 Naming Conventions22 Defining an Address Record23 Adding List of Addresses to Person24 Creating a Person Record25 ‘Dot’ Notation26 String Concatenation27 String Comparison28 String Utilities29 Collections30 INSERT31 Collections and {}32 Removing from a Collection33 Date and Time Types34 Date and Time Arithmetics35 Date and Time Utilities36 Date Formatting37 Time Formatting38 Other Free Tutorials
MemeScript Example var x = 10;
var y = 20;
var z : Integer;
z = x + y;
notify(z);
2
Meme IDE Function Editor
3
Primitive Types•Integer 10, -234
•Decimal 1.23
•String “ABC”
•Boolean true, false
4
Declaring Integer VariablesLocal variables within functions
var x : Integer;
var x2 = 1;
5
Declaring Decimal Variablesvar d : Decimal(2);
var d2 = 1.23;
6
Declaring Boolean Variablesvar b : Boolean;
var b2 = true;
7
Declaring Stringsvar s : String;
var s = “abc”;
8
Default Initializations•String - empty string “”
•Integer and Decimal – 0
•Boolean – false
9
Pre-defined Complex Types• Date – day, month, year
• Time – hour, minute, second
• Duration – hour, minute, second
• Timestamp
10
IFvar a = 15;if (a > 10){ notify(“A is big”);}
11
IF / ELSEvar a = 15;if (a > 10){ notify(“A is big”);}else{ notify(“A is small”);}
12
IF / ELSEIF / ELSEvar a = 15;if (a > 10){ notify(“A is big”);}elseif (a > 5){ notify(“A is medium sized”);}else{ notify(“A is small”);}
13
WHILEvar x = 0;while (x < 10){ x++; // do other things}
14
FORvar names : String[];append(names, “Simon”);append(names, “Graham”);append(names, “Joe”);for (name in names){ notify(name);}
15
Arithmeticvar c = 20;f = c * (9.0 / 5.0) + 32;notify(f);
16
Logical Operatorsvar x = 10;if ((x > 10) and not (x > 20)){ notify(“x is middle sized”);}
17
18
Dataspace
19
Defining a ‘Person’ Record
20
Adding Attributes to the ‘Person’ Record
Naming ConventionsRecord Type Names• bumpy case with initial uppercase, e.g. Person or EmployeeDetails
Attribute names in records• bumpy case with initial lowercase e.g. name or firstName
21
22
Defining an Address Record
23
Adding List of Addresses to Person
Creating a Person Recordvar p : Person;var a : Address;a.line1 = “12 High St”;a.zip = “PA 12345”;p.name = “Simon”;p.tel = “1234567”;append(p.addresses, a);
24
‘Dot’ Notationnotify(p.addresses[0].line1);
p.addresses[0].line1 = “13 High St”
25
String Concatenation
var s1 = “The Start”var s2 = “The Middle”var s3 = “The End”var result = s1 + “, “ + s2 + “, “ + s3 + “. “ + 3 + “ parts.”;
The Start, The Middle, The End. 3 parts.
26
String Comparisonvar s1 = “String 1”;var s2 = “String ONE”;if (s1 == s2){ notify(“Yes”);}
27
String Utilities• Boolean startsWith(sourceString, matchString)
• Boolean endsWith(sourceString, matchString)
• String subString(sourceString, startPos, length)
• Integer size(sourceString)
• String toLower(sourceString)
• String toUpper(sourceString)
• String trim(sourceString)
• String replaceAll(sourceString, matchString, replacementString)
• String replaceFirst(sourceString, matchString, replacementString)
• String replaceLast(sourceString, matchString, replacementString)
28
Collectionsvar people : Person[];var names : String[];append(names, “Simon”);append(names, “Graham”);
29
INSERTvar people : Person[];var names : String[];append(names, “Simon”);append(names, “Graham”);insert(names, “Joe”, 0);
30
Collections and []var people : Person[];var fred : Person;simon.name = “Simon”;simon.tel = “12345”;people.append(simon);var graham : Person;graham.name = “Simon”;graham.tel = “12345”;people.append(graham);
people.remove(simon);
31
Removing from a Collectionvar people : Person[];var simon : Person;simon.name = “Simon”;simon.tel = “12345”;people.append(simon);var graham : Person;graham.name = “Simon”;graham.tel = “12345”;people.append(graham);
notify(people[1].name);
32
Date and Time Types• Date - day, month, year• Time - hour, minute, second• Duration - hour, minute, second• Timestamp
33
Date and Time Arithmeticvar t : Time;t = timeNow();
var dt : Duration;dt.hour = 1;t = addTime(t, dt);
34
Date and Time Utilities• dateNow()• timeNow()• setDate(Date, year, month, day)• setTime(Time, hour, min, sec)• addDays(Date, days)• dayOfWeek(Date)• monthOfYear(Date)• formatDate(Date, formatString)• formatTime(Time, formatString)• formatTimestamp(Timestamp, String)
35
Date Formatting
36
var today : Date;today = dateNow();formatDate(today, “mmm d, yyyy”);
“January 1, 2011”
d Day of the month without leading zero “1”dd Day of the month with leading zero “01”ddd The localised name for the day of the week “Sunday”m Month of the yearwithout leading zero “1”mm Month of the year with leading zero “01”mmm The localised short (3 letter) name for the month “Jan”mmmm The localised full name for the month “January”yy The year as two digits “10”yyyy The year as four digits “2010”
Code Description Result
Time Formatting
var t : Time;t = timeNow();formatTime(t, “HH:MM:SS PP”);
“12:34:10 am”
HHH Hour in 24 hour format with leading zero 19HH Hour in 24 hour format with leading zero 08H Hour in 12 hour format without leading zeros 8MM Minute with leading zero 05M Minute without leading zero 5SS Seconds with leading zero 09S Seconds without leading zero 9PP am/pm indicator am
Code Description Example Result
37
Please check www.memeapps.com for more free tutorials in the developers center
Level one:
101 - Hello World Hello Meme IDE
102 - Introduction to MemeScript Language103 - Meme IDE Fundamentals
201 - Records and Record Types202 - Designing Business Apps203 - Advanced MemeScript
301 - MemeApps and Communications302 - MemeApps advanced User Interfaces303 - MemeApps and Persistence
38