Skip to content

Latest commit

 

History

History
123 lines (85 loc) · 2.8 KB

additions.md

File metadata and controls

123 lines (85 loc) · 2.8 KB

Additions



Lists

List declaration:

const list = [1, 2, 3, "hi!"];

print list;	// [ 1, 2, 3, hi! ]

Chars

Basically, a char type.

Syntax:

const a_char = 'a';

It's sole purpose is to aid in string modification:

const letters = expand("luxya 🤢");

letters[6] = '✨';

print from_chars(letters);	// luxya ✨

Read more about expand here, here, and about from_chars here.

Square bracket accessor

Accessing lists:

const list = ['a', 'b', 'c', 'd'];

print list[2];	// c

Accessing strings:

const name = "Ola";

print name[0];	// O

You may think that accessing strings is not reliable, coz what if we have a multibyte char? Let's try it.

const emoji = "🥺";

print emoji[0];	// â

â is not what we expected, but that's the desired behaviour. Luxya deals with accessing chars by using their byte representation, so that you can expect an O(1) operation on every access.

But what if we want to access the emoji as a char? We use the expand function!

const name = "luxya ✨";

const expanded = expand(name);

print expanded;	// [ l, u, x, y, a,  , ✨ ]

print expanded[6];	// ✨

Neat! What we get is a list of chars that we can now safely and reliably access!

Object notation

Luxya supports a full object notation!

Declare an empty object:

const object = {};

Declare objects with key value pairs:

const some_value = 1;

const object = {
	name: "luxya ✨",
	"arbitrary key": "value!",	// you can use strings as keys!
	some_value,	// shorthand key-value notation
};

print object;	// { name: luxya ✨, arbitrary key: value!, some_value: 1 }

As you can see, the last key doesn't have a value. That's because luxya supports a shorthand key-value notation - it will automatically bind the value if the value of the same name is declared in scope!

Grouping accessor

By using the grouping accessor, you can get and set properties on objects with any arbitrary key, that you couldn't do with just a dot notation (object.key).

const object = {};

const key = "1 2 3 4 key with spaces";

object.(key) = "value!";

print object.(key);	// value!

By combining this accessor with expand, has and unset functions, you can use objects as hashmaps.

const map = {};

map.("arbitrary key") = "value!";

print has(map, "arbitrary key");	// true

unset(map, "arbitrary key");
print has(map, "arbitrary key");	// false