YASL Enhancements
This repo keeps track of potential and planned features for YASL, to avoid cluttering the main repo.
Possible future features:
Strings:
make strings iterable (iterating over each 'character').(added in v0.3.0)add(added in v0.3.4)string.count
method.- add
string.reverse
method. - add string metatable.
- other types of string literals somehow:
"AB CD EF 00 11"x
for string from hex,"0011 0011"b
for string from binary,"你好"u
for unicode, etc. add quick opcodes for builtin method names to reduce bytecode size and speed up interpreting.(added)- implement string interning with all literals.
s[a:b]
notation for slice.- rename
string.repeat
tostring.rep
. [BREAKING]
Numbers:
- allow underscores in numeric literals (these are simply ignored). Not allowed at start of number or directly after decimal place. e.g. (10_000, 0x_10)
- Add exponential notation for floats. e.g. 1e100
- Move
inf
andnan
tomath
library. [BREAKING]
Lists:
method to sort lists in-place(added in v0.3.4)method to join list elements into a single string.(added in v0.3.1)(added in v0.3.1)tostr
and printing should show contents instead of memory address.- list concat with
+
(so that string concat always concatenates). - list metatable.
(added in v0.3.1)list.clear
method.l[a:b]
notation for slice.
Tables:
(added in v0.3.1)tostr
and printing should show contents instead of memory address.'- metatables, to allow lookups in a second table if first look-up fails.
(added in v0.3.1)table.clear
method.
Userdata:
- metatables
Modules:
require 'path'
should import the contents ofpath
and put them into a table. (Tables can be used instead of another module system.)
in
operator:
- check list and table containment. complement is
!in
.
For loops:
- allow iterating over two values instead of just 1.
for let i, v <- [2, 3, 5, 7] {}
would havei
iterate over the keys, (0, 1, 2, 3) andv
iterate over the values (2, 3, 5, 7).
Operator overloading:
Libraries:
math library ((added in v0.3.4)math
), including things likeexp
,sin
,sqrt
, etc.- UTF8 library (
utf8
), including string functions on utf8 strings. - I/O library (
io
), including file I/O and stdin, stdout, stderr. - coroutine library (
coroutine
), for concurrency. - collections library (
collection
), including collections such asset
,multiset
, and typed arrays. - regex library (
re
). Something like PCRE is likely too big for usage in the standard library.
Functions:
- Implement full lexical closures.
- allow unnamed functions using
fn(a, b) { return a + b }
. (added in v0.3.2)const
functions.(added in v0.3.2)const
function parameters.- allow
fn f.name(a, b, c) { .... }
style declarations (for tables).
Sequences:
- "sequences" should be added to YASL. sequences live only on the stack. Trying to use a sequence in an expression will shrink or expand the sequence to the appropriate size. e.g. if
f()
returns1, 2
,x, y = f()
will use both values.x = f()
will shrink1, 2
to fit the context it is used in, to1
in this case.x, y, z = f()
would expand1, 2
to the context it is used in, filling withundef
, sox
would get a value of 1,y
a value of 2, andz
a value ofundef
.
Comprehensions:
- comprehensions should be more general, returning a sequence. This would allow stuff like
max(x for x <- ls if x > 0)
, andset(x for x <- ls)
. - If iterating over multiple values is allowed, comprehensions should also support this.
Loops:
- Optional
else
clause, executed if the main loop doesn'tbreak
out.
Variables:
- Allow multiple assignments of the form
x, y, z := 1, 2, 3
. Allowconst x, y, z := 1, 2, 3
as well, which makes all of themconst
.
Generators:
fn* gen(a) { /* body */ }
to declare a generator (compare with notation for function declarations).-x for* x <- ls
to declare a generator from an existing iterable (compare with notation for comprehensions).