1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
---
language: LDPL
filename: learnLDPL.ldpl
contributors:
- ["Martín del Río", "https://github.com/lartu"]
---
**LDPL** is a powerful, C++ transpiled, open-source programming language designed
from the ground up to be excessively expressive, readable, fast and easy to learn.
It mimics plain English, in the likeness of older programming languages like COBOL,
with the desire that it can be understood by anybody. It's very portable and runs on a
plethora of different architectures and operating systems and it even supports UTF-8
out of the box.
[Read more here.](https://github.com/lartu/ldpl)
```coffeescript
# This is a single line comment in LDPL.
# LDPL doesn't have multi-line comments.
# LDPL is a case-insensitive language: dIsPlaY and DISPLAY are the same
# statement, and foo and FOO name the same variable.
# An LDPL source file is divided in two sections, the DATA section and
# the PROCEDURE section.
DATA:
# Within the DATA section, variables are declared.
myNumber is number # Defines a real number.
myString is text # Defines a string.
myList is number list # Defines a list of numbers.
myMap is number map # Defines a map of numbers.
# LDPL understands four data types: two scalar types (NUMBER, TEXT)
# and two container types (LISTs and MAPs).
# LISTs can be TEXT LISTs or NUMBER LISTs, while MAPs can be
# TEXT MAPs and NUMBER MAPs. You can also chain many containers
# to create larger data types:
textListList is text list list
myMulticontainer is number list list map
# Defines a map of lists of lists of numbers.
PROCEDURE:
# Within the PROCEDURE section, your code is written.
store -19.2 in myNumber # Use the STORE statement to assign values
store "Hi there" in myString # to variables.
push 890 to myList # Use PUSH - TO to append values to lists.
push 100 to myList
push 500 to myList
store 45 in myMap:"someIndex" # Use the : operator to index containers.
push list to textListList # Push an empty list into a list of lists.
push "LDPL is nice!" to textListList:0 #Push text to the pushed list.
display "Hello World!" # Use the DISPLAY statement to print values.
# The display statement can receive multiple values separated by spaces.
display crlf "How are you today?" myNumber myString crlf
# CRLF is the standard line break value in LDPL.
display textListList:0:0 " Isn't it?" crlf
# IF statements in LDPL are extremely verbose:
if myNumber is equal to -19.2 and myList:0 is less than 900 then
display "Yes!" crlf
else if myMap:"someIndex" is not equal to 45 then
display "This is an else if!" crlf
else
display "Else!" crlf
end if
# Valid LDPL comparisson operators are
# - IS EQUAL TO
# - IS NOT EQUAL TO
# - IS LESS THAN
# - IS GREATER THAN
# - IS LESS THAN OR EQUAL TO
# - IS GREATER THAN OR EQUAL TO
if "Hi there!" is not equal to "Bye bye!" then
display "Yep, those weren't equal." crlf
end if
# LDPL normally doesn't understand inline expressions, so you
# cannot do stuff like:
# if myNumber - 9 * 2 is equal to 10 then
# LDPL will set your computer on fire and burst your screen if you do so.
# WHILE loops follow the same rules
store 0 in myNumber
while myNumber is less than 10 do
display "Loop number " myNumber "..." crlf
in myNumber solve myNumber + 1 # You can do math like this.
repeat
# You can use 'break' and 'continue' inside loops just like any other language.
# LDPL also has FOR loops and FOR EACH loops
for myNumber from 0 to 100 step 2 do
display myNumber crlf
repeat
for each myNumber in myList do
display myNumber
repeat
display "Enter your name: "
accept myString # Use ACCEPT to let the user input values.
display "Hi there, " myString crlf
display "How old are you?: "
accept myNumber
if myNumber is greater than 200 then
display "Woah, you are so old!" crlf
end if
wait 1000 milliseconds # Pause the program for a whole second.
# Let's do some math
store 1.2 in myNumber
in myNumber solve myNumber * (10 / 7.2) # Operators are separated by spaces.
floor myNumber
display myNumber crlf
get random in myNumber # get a random number between 0 and 1
# and store it in myNumber
# Functions in LDPL are called sub-procedures. Sub-procedures, like source
# files, are divided in sections. The sections found in sub-procedures are
# the PARAMETERS section, the LOCAL DATA section and the PROCEDURE section.
# All sections except the PROCEDURE section can be skipped if they aren't
# used. If no PARAMTERS nor LOCAL DATA sections are used, the PROCEDURE
# keyword may be omited.
sub myFunction
parameters:
a is number # LDPL is pass by reference
b is number
result is number # Thus you can return values through a parameter.
local data:
c is number
procedure:
get random in c
in result solve a + b * c
end sub
sub sayHello
display "Hi there!" crlf
return
display "This won't be displayed :("
end sub
call myFunction with 1 2 myNumber
display myNumber crlf
call sayHello
call sayBye # sub-procedures may be called before they are declared
sub sayBye
display "Bye!"
end sub
# One of the greatest features of LDPL is the ability to create your
# own statements.
create statement "say hi" executing sayHello
say hi
create statement "random add $ and $ in $" executing myFunction
random add 1 and 2 in myNumber
display myNumber crlf
exit
```
## Topics Not Covered
* [Command line arguments](https://docs.ldpl-lang.org/variables-in-ldpl/command-line-arguments)
* [Error variables](https://docs.ldpl-lang.org/variables-in-ldpl/errorcode-and-errortext)
* [Import other files](https://docs.ldpl-lang.org/structure-of-ldpl-source-code/importing-other-sources)
* [Identifier naming schemes](https://docs.ldpl-lang.org/naming-rules)
* [Text Statements](https://docs.ldpl-lang.org/text-statements/join-and-in)
* [List Statements](https://docs.ldpl-lang.org/list-statements/push-to)
* [Map Statements](https://docs.ldpl-lang.org/vector-statements/clear)
* [File loading / writing](https://docs.ldpl-lang.org/i-o-statements/load-file-in)
* [Executing commands](https://docs.ldpl-lang.org/i-o-statements/execute)
* [Extending LDPL with C++](https://docs.ldpl-lang.org/extensions/c++-extensions)
## Further Reading
* [LDPL Docs](https://docs.ldpl-lang.org)
|