Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Migrating to Madlib from JavaScript

Brekk edited this page Nov 21, 2020 · 1 revision

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.

  1. Types
  2. The Fence
  3. Literals

Types

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.

Global Types

  • String - for use with string values
  • Number - for use with number values
  • Boolean - for use with boolean values
  • List - for use with array

The Fence

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.

Literals

Much of madlib's syntax is identical to JavaScript, but there are a few discrepancies.

Variables

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

Booleans

Just like JavaScript.

yes = true
no = false

Strings

Just like JavaScript.

iAmAString = `yes you are`
iAmDoublyStrung = "weird brag"
strictlyBetter = `obviously`

Numbers

(Eventually) Just like JavaScript. Currently unsupported: floating point numbers, negative numbers (However, these are usable with fencing.)

pies = 1

Regular Expressions

Currently these are not natively supported by madlib. They are achievable with fencing.

Clone this wiki locally