Getting Started with DynLex
DynLex lets you write code in clear words. You write your program in a .dl file, build
it, and then run it.
This page shows the smallest steps first. It uses the same words you will see in the rest of the
documentation, such as pattern,
parameter, and
section.
Step 1
Write your first DynLex file
Make a file named hello.dl. Start by
importing the standard library:
import lib/std.dl
print "Hello, world!" as line
The line print "Hello, world!" as line matches a
pattern from the standard library.
Try yourself
Change the text and run the file again. Try your name, a question, or a full sentence.
Step 2
Build and run your file
Build the file into a program and run it:
dynlex hello.dl -o hello
./hello
If you are on Windows, your output file may be named hello.exe.
Step 3
Store values in variables
A variable lets you keep a value and use it again later:
import lib/std.dl
set apples to 3
set oranges to 2
set total to apples + oranges
print total as line
Here, set ... to ... and ... + ... are both
standard DynLex patterns.
Try yourself
Change the numbers. Then add one more line that prints total + 10.
Step 4
Write your first function
A function gives a name to a piece of
behavior. The words on the first line are its
pattern.
import lib/std.dl
function square value:
execute:
return value * value
print square 5 as line
In this example, value is a
parameter. When you write
square 5, the number 5 is the
argument.
DynLex also detects plain-word parameters by usage: if a plain word from a function pattern is used
in the body, that word is treated as a parameter.
The execute: line opens a
section. The code inside that section is
indented one level deeper.
Try yourself
Change square into double. Then make it return value + value.
Step 5
Use a loop
A loop lets you repeat a block of code. The loop body is another
section.
import lib/std.dl
set count to 1
loop while count <= 3:
print count as line
increment count
This prints the numbers 1, 2, and 3. The line under loop while runs again and again
until the condition becomes false.
Try yourself
Change 3 to 5. Then change the start value from 1 to 2.
Step 6
Stay with the standard library at first
You may notice @intrinsic(...) in some library code. That is an
intrinsic.
For normal DynLex programs, use standard library patterns first. They read better, and they are
the usual way to write DynLex code.
Next
What to read after this
If a word feels unclear, open the terms page.
After that, the next useful step is to read more examples and build small functions of your own.