Releases: fuseraft/kiwi
Releases 路 fuseraft/kiwi
kiwi version 1.4.2 馃
kiwi version 1.4 馃
Release Notes
I am excited to announce Kiwi version 1.4! 馃
This is a large change. It contains a lot of quality of life features, documentation improvements, and some critical bug fixes.
What's New
New List builtin: .each(lambda)
Iterate a list, performing some action for each item in the list.
# Convert "hello" to a list of unique values, and iterate each.
"hello".chars().unique().each(with (v, i) do
println("${i} = ${v}")
end)
/# Output:
0 = h
1 = e
2 = l
3 = o
#/
# Iterate a range.
[1..3].each(with (v, i) do println("${i}: ${v}") end)
/# Output:
0: 1
1: 2
2: 3
#/
# Iterate a list.
matrix = [[0] * 3] * 3
matrix.each(with (row, row_index) do
println("${row_index}: ${row}")
end)
/# Output:
0: [0, 0, 0]
1: [0, 0, 0]
2: [0, 0, 0]
#/
New core builtin methods: serialize(value)
, deserialize(string)
deserialize(string)
Deserializes a string into a value.
string = "[1, 2, 3]"
list = deserialize(string) # Deserialize a string into a list.
list.push(4) # Push a value to the list.
println(list) # Output: [1, 2, 3, 4]
serialize(value)
Serializes a value into a string.
list = [1, 2, 3]
string = serialize(list) # Serialize a list into a string.
# split the string into a list,
# then print the list of strings in a pretty format.
println(string.chars().pretty())
/# Output:
[
"[",
"1",
",",
" ",
"2",
",",
" ",
"3",
"]"
]
#/
New keyword: when
- Added the
when
keyword, which is used to conditionally execute control flow structures.
Raw Strings
- Added support for raw strings. Use cases are: regular expressions, unformatted strings.
- These strings begin and end with a single-quote.
- Updated docs for new string documentation.
Regular expressions
- Added support for regular expressions.
- Added several builtins for this:
find
,match
,matches
,matches_all
, andscan
. - Updated docs for new builtins.
New builtin .clone()
- Added a
.clone()
builtin. It produces a deep copy of any value it is invoked on.
matrix0 = [[0] * 3] * 3 # initialize a 3x3 matrix of 0s
matrix1 = matrix0.clone() # deep copy matrix0
matrix0[0][0] = 1
println(matrix0) # prints: [[1, 0, 0], [0, 0, 0], [0, 0, 0]]
println(matrix1) # prints: [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
New builtin .pretty()
- Added a
.pretty()
builtin. It produces a pretty serialization of lists and hashes.
New keyword parse
- Added a
parse
keyword. This keyword is similar toeval
in other languages. - Added a CLI flag
-p
/--parse
for invoking this functionality from the command-line. You can pass a string to-p
and it will evaluate it as kiwi. - Updated the docs to reflect this feature.
New standard library module @kiwi/http
- Added
@kiwi/http
. Usingcpp-httplib
to to implement builtins withhttplib::Client
. - Updated the docs to include the module information.
New standard library module @kiwi/log
- Added
@kiwi/log
. This module exposes kiwi logger functionality. - Updated the docs to include the module information.
New DateTime
class.
- Added a
DateTime
class. Import@kiwi/time
. - Updated the docs to include the
DateTime
class.
Bug Fixes
- Fixed an issue with base class resolution in
is_a
builtin - Fixed an issue with deeply nested conditional logic.
- Fixed an issue with multi-dimensional list indexes.
- Fixed an issue with lambdas as method parameters.
- Fixed an issue with the
elsif
branch.
#!/usr/bin/kiwi
abstract class X
abstract def run(x)
end
class A < X
def initialize() end
override def run(x) println("A: ${x}") end
end
class B < X
def initialize() end
override def run(x) println("B: ${x}") end
end
class C < X
def initialize() end
override def run(x) println("C: ${x}") end
end
class D
def initialize() end
def run(x) println("D: ${x}") end
end
class E < X
def initialize() end
override def run(x) println("E: ${x}") end
end
# Testing deeply nested conditions.
[A.new(), B.new(), C.new(), D.new(), E.new()].each(with (o) do
if o.is_a(A)
if !true
println("This will not happen.")
else
o.run("I am a ${o.type()}.")
end
elsif o.is_a(C) || o.is_a(B)
if o.is_a(C)
o.run("I am a ${o.type()}.")
else
if o.is_a(B)
o.run("I am a ${o.type()}.")
else
println("This will not happen.")
end
end
else
if !o.is_a(X)
o.run("I am something else.")
else
o.run("I am a ${o.type()}.")
end
end
end)
/# Output:
A: I am a A.
B: I am a B.
C: I am a C.
D: I am something else.
E: I am a E.
#/
Known Issues
Deeply nested string interpolations
Stuff like this still works.
a = 5, b = 4
println("${"${a}${b}" * (a * b)}") # prints: 5454545454545454545454545454545454545454
Ran into an issue with the following line of code.
println("${str.padend("${t.type}:", 20, " ")} `${t.text}`")
Workaround (and cleaner in my opinion):
println(str.padend("${t.type}:", 20, " ") + "`${t.text}`")
I am excited to see what you can build with Kiwi!
Changelog: v1.3.2...v1.4.1