Functions Tutorial

Click here to return to the Advanced Ludwig table of contents.

One of Ludwig‘s advanced features is the support of functions. You do not need to use functions in order to write a composition, but they do provide features in compositions that range from convenience to new kinds of usage. For example, functions enable code reuse and modularity – you can call a function again instead of writing the same chunk of code repeatedly. You can even make an entire infrastructure pattern repeatable with functions.

Ludwig’s functions look a lot like functions in other languages where the types of arguments and return values are explicit (such as C, Java, or Python with type hints), so we hope you’ll find them familiar and easy to learn.

This six-part tutorial covers simple functions, case statements, pattern matching, local variables, list comprehensions, and user-defined types. Each part of the tutorial features an exercise where you fix an error in a function in order to make a module compile with lwc, the Ludwig compiler. All code may be found in our public Github repo.