You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Hogget is a sheep between one and two years of age. Inspired by Ramda, we also like sheep.
It's a unique and rememberable name, a short one, it's not yet taken, easily pronounceable, and there's
not too many languages that start with an H yet.
All hogget programs are started by calling the main function, which must be implemented by the user. Example:
let main = => {
log('the answer is' add(12 30) '\n');
exit(0);
}
Expressions & Statements
Expressions are language constructs that evaluate into a value and can be nested. Statements are language constructs that don't evaluate into a value and must stand on their own, they are separated with ;.
Comments
// single line comment
let myVar = 42; // inline comment
/* multi
line
comment */
Variables
All variables are immutable. Declare a variable with the let statement, which receives an expression or value.
let myVar = 42;
let myResults = getResults();
Numbers
The rule is simple: if there's a . involved in a number, it's a dec, otherwise it's an int. Whether it's positive or negative doesn't matter.
let answer = 42;
let pi = 3.14;
let cold = -3;
Strings
Strings are delimited with a single quote ('), and are interpolated with ${varName}. Example:
let question = 'What is the answer to everything?';
let answer = 'The answer is ${toStr(42)}';
Enums
let PaymentCardType = enum { MasterCard Maestro Visa };
let myPayment1 = enum(PaymentCardType Visa); // functional access
let myPayment0 = PaymentCardType.Maestro; // operator access
Lists
let constants = [1.41 2.71 3.14];
Objects
Comma's (,) are fully optional, though they may increase readability when using single line syntax. The formatter will put objects on a single line wih comma's if the line does not exeed 80 characters.
All functions are expressions and must have an return value (null is valid).
Functions can be defined as one-liners without curly brackets, or as multi line with curly brackets. The last line is the return statement. Specifying arguments is optional.
let myAdd0 = => 12 30;
let myAdd1 = (a b) => add(a b);
let myAdd2 = (a b) => {
let result = add(a b);
result;
};
All functions are curried, enabling this kind of programming:
log(* ...) -> null - Output a string to the terminal or console. Calls the toStr() function if given anything but a string. Multiple strings are added together, newlines are not automatically inserted.
exit(int) -> null: Immediately exits the program, with an exit code.
Logic & Conditionals
not(bool) -> bool: Returns the not of it's argument.
and(bool bool) -> bool
or(bool bool) -> bool
xor(bool bool) -> bool
if(func func func) -> *: Will call and return either the second or third argument depending on the result of the first.
identity(*) -> *: Returns the given argument.
eq(* *) -> bool
identical(* *) -> bool: Returns true of both arguments are strictly equal.
lt() and lte()
gt() and gte()
Types
type(*) -> string
isNull(*) -> bool
isBool(*) -> bool
isInt(*) -> bool
isDec(*) -> bool
isStr(*) -> bool
isEnum(*) -> bool
isOfEnum(enum *) -> bool
isList(*) -> bool
isObj(*) -> bool
isFunc(*) -> bool
Type conversions
toBool(*) -> bool
toStr(*) -> str
toInt(*) -> int
toDec(*) -> dec
Numbers
All the arithmetic functions work with either int values or dec values, and will then return the same type.
num is used to denote either int or dec.
add(num num) -> num
subtract(num num) -> num
multiply(num num) -> num
divide(num num) -> num
modulo(num num) -> num: Returns the remainder of the division.