Makros is a collection of macros intended to speed up uiua development.
The library itself is NOT experimental (unlike
uiua-math
😏), although certain macros
are. This means you don't need to have # Experimental!
code unless you
really want to.
A goal of Makros is to make niceties for dealing with common patterns found in larger programs.
~ "git: github.com/Marcos-cat/makros" ~ Struct! # Import by name
or
Makros ~ "git: github.com/Marcos-cat/makros" # Import namespace
Struct!
: arrays with named fieldsEnum!
: sets of unique named valuesMatch!
: a more restrictive and intuitive form of pattern matching
- Field accessors for each field
New
function which pops all fields off the stack and into an arrayDefault
function which fills certain fields with a predefined value- Default values must directly follow the field name and enclose the value in
parentheses.
Age( 35 )
is correct, butAge (35)
is not
- Default values must directly follow the field name and enclose the value in
parentheses.
Map
function which converts an instance into a string-accessedmap
Fields
array which is the name of each field as a string- Structs defined with
[]
will not be boxed, and ones defined with{}
will
Example:
---Person
Struct!{FirstName("John") LastName("Smith") Age(35)}
FullName ← $"_ _"⊃FirstName LastName
---
Person~Default
## {"John" "Smith" 35}
Person~New "bobby" "tables" 7
## {"bobby" "tables" 7}
.
Person~FullName
## "bobby tables"
◌
Person~Map
## ╭─
## ⌜FirstName⌟ → ⌜bobby⌟
## ⌜LastName⌟ → ⌜tables⌟
## ⌜Age⌟ → □7
## ╯
If you don't need custom methods on the struct, there is a shorthand to create the module inline.
Struct‼Person{FirstName LastName Age}
The macro
Struct‼
has to be imported separately fromStruct!
, even though they share a name.
- Constants for each variant which are increasing integers from zero
Display
function which converts a variant into a string formVariants
array which is the name of each variant as a string
Example:
---Seasons
Enum![Spring Summer Fall Winter]
Next ← ◿⧻Variants+1
---
Seasons~Summer
## 1
Seasons~Display
## "Summer"
⍜°Seasons~Display Seasons~Next
## "Fall"
⍜°Seasons~Display Seasons~Next
## "Winter"
⍜°Seasons~Display Seasons~Next
## "Spring"
- Requires
# Experimental!
- Arms are can be in the form
pattern => code
orpattern -> code
- The benefit as over a simple
⍣
is that the code section of the branch is wrapped incase
, and thus errors in the arms do not fall though to the next branch causing headaches while debugging
Example:
---Color ~ Temperature
Enum![Red Orange Yellow Green Blue Purple]
Temperature ← Match!(
Red + Orange => "Hot"
| Yellow -> "Warm"
| Green => "Cool"
| Blue + Purple -> "Cold"
)
---
Temperature Color~Red
## "Hot"
Temperature Color~Purple
## "Cold"