-
Notifications
You must be signed in to change notification settings - Fork 0
Migrating to Madlib from JavaScript
Common Pitfalls & Delights
madlib is a constructed language which is intended to make the syntax and semantics of JavaScript more palatable and expressive, while restricting certain constructs.
- Types
- The Fence
-
Literals
- Variables
- Booleans
- Strings
- Numbers
- Regular Expressions - not currently supported without fencing
One of the essential utilities of madlib is its type inference system. Where possible you should use its types in order to provide correctness and allow for some powerful features which only work with types defined.
-
String
- for use with string values -
Number
- for use with number values -
Boolean
- for use with boolean values -
List
- for use with array
In the case that you want to do something in madlib which is not yet expressible in the current native madlib syntax, simply wrap a valid JS expression with either the single-line #- "JAVASCRIPT" -#
or a multiline:
#- {
"JAVASCRIPT"
} -#
There is a downside to doing this however, as content within the fence is opaque to madlib's type inference.
Much of madlib's syntax is identical to JavaScript, but there are a few discrepancies.
Instead of letting / forcing (depending on your perspective) you to choose the different semantics of var
/ let
/ const
, madlib simply has an assignment operator.
a = 1 // Number
b = `cool` // String
c = true // Boolean
Just like JavaScript.
yes = true
no = false
Just like JavaScript.
iAmAString = `yes you are`
iAmDoublyStrung = "weird brag"
strictlyBetter = `obviously`
(Eventually) Just like JavaScript. Currently unsupported: floating point numbers, negative numbers (However, these are usable with fencing.)
pies = 1
Currently these are not natively supported by madlib. They are achievable with fencing.