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.
1# This is a single line comment in LDPL.
2# LDPL doesn't have multi-line comments.
3
4# LDPL is a case-insensitive language: dIsPlaY and DISPLAY are the same
5# statement, and foo and FOO name the same variable.
6
7# An LDPL source file is divided in two sections, the DATA section and
8# the PROCEDURE section.
9
10DATA:
11# Within the DATA section, variables are declared.
12
13myNumber is number # Defines a real number.
14myString is text # Defines a string.
15myList is number list # Defines a list of numbers.
16myMap is number map # Defines a map of numbers.
17
18# LDPL understands four data types: two scalar types (NUMBER, TEXT)
19# and two container types (LISTs and MAPs).
20# LISTs can be TEXT LISTs or NUMBER LISTs, while MAPs can be
21# TEXT MAPs and NUMBER MAPs. You can also chain many containers
22# to create larger data types:
23textListList is text list list
24myMulticontainer is number list list map
25# Defines a map of lists of lists of numbers.
26
27PROCEDURE:
28# Within the PROCEDURE section, your code is written.
29
30store -19.2 in myNumber # Use the STORE statement to assign values
31store "Hi there" in myString # to variables.
32push 890 to myList # Use PUSH - TO to append values to lists.
33push 100 to myList
34push 500 to myList
35store 45 in myMap:"someIndex" # Use the : operator to index containers.
36
37push list to textListList # Push an empty list into a list of lists.
38push "LDPL is nice!" to textListList:0 #Push text to the pushed list.
39
40display "Hello World!" # Use the DISPLAY statement to print values.
41# The display statement can receive multiple values separated by spaces.
42display crlf "How are you today?" myNumber myString crlf
43# CRLF is the standard line break value in LDPL.
44display textListList:0:0 " Isn't it?" crlf
45
46# IF statements in LDPL are extremely verbose:
47if myNumber is equal to -19.2 and myList:0 is less than 900 then
48 display "Yes!" crlf
49else if myMap:"someIndex" is not equal to 45 then
50 display "This is an else if!" crlf
51else
52 display "Else!" crlf
53end if
54# Valid LDPL comparison operators are
55# - IS EQUAL TO
56# - IS NOT EQUAL TO
57# - IS LESS THAN
58# - IS GREATER THAN
59# - IS LESS THAN OR EQUAL TO
60# - IS GREATER THAN OR EQUAL TO
61if "Hi there!" is not equal to "Bye bye!" then
62 display "Yep, those weren't equal." crlf
63end if
64# LDPL normally doesn't understand inline expressions, so you
65# cannot do stuff like:
66# if myNumber - 9 * 2 is equal to 10 then
67# LDPL will set your computer on fire and burst your screen if you do so.
68
69# WHILE loops follow the same rules
70store 0 in myNumber
71while myNumber is less than 10 do
72 display "Loop number " myNumber "..." crlf
73 in myNumber solve myNumber + 1 # You can do math like this.
74repeat
75# You can use 'break' and 'continue' inside loops just like any other language.
76
77# LDPL also has FOR loops and FOR EACH loops
78for myNumber from 0 to 100 step 2 do
79 display myNumber crlf
80repeat
81
82for each myNumber in myList do
83 display myNumber
84repeat
85
86display "Enter your name: "
87accept myString # Use ACCEPT to let the user input values.
88display "Hi there, " myString crlf
89display "How old are you?: "
90accept myNumber
91if myNumber is greater than 200 then
92 display "Woah, you are so old!" crlf
93end if
94
95wait 1000 milliseconds # Pause the program for a whole second.
96
97# Let's do some math
98store 1.2 in myNumber
99in myNumber solve myNumber * (10 / 7.2) # Operators are separated by spaces.
100floor myNumber
101display myNumber crlf
102get random in myNumber # get a random number between 0 and 1
103 # and store it in myNumber
104
105# Functions in LDPL are called sub-procedures. Sub-procedures, like source
106# files, are divided in sections. The sections found in sub-procedures are
107# the PARAMETERS section, the LOCAL DATA section and the PROCEDURE section.
108# All sections except the PROCEDURE section can be skipped if they aren't
109# used. If no PARAMETERS nor LOCAL DATA sections are used, the PROCEDURE
110# keyword may be omitted.
111sub myFunction
112 parameters:
113 a is number # LDPL is pass by reference
114 b is number
115 result is number # Thus you can return values through a parameter.
116 local data:
117 c is number
118 procedure:
119 get random in c
120 in result solve a + b * c
121end sub
122
123sub sayHello
124 display "Hi there!" crlf
125 return
126 display "This won't be displayed :("
127end sub
128
129call myFunction with 1 2 myNumber
130display myNumber crlf
131call sayHello
132call sayBye # sub-procedures may be called before they are declared
133
134sub sayBye
135 display "Bye!"
136end sub
137
138# One of the greatest features of LDPL is the ability to create your
139# own statements.
140
141create statement "say hi" executing sayHello
142say hi
143
144create statement "random add $ and $ in $" executing myFunction
145random add 1 and 2 in myNumber
146display myNumber crlf
147
148exit