Skip to content

Releases: fuseraft/kiwi

kiwi version 1.4.2 馃

09 May 13:50
Compare
Choose a tag to compare

What's Changed

Full Changelog: v1.4.1...v1.4.2

kiwi version 1.4 馃

29 Apr 23:40
8e4da52
Compare
Choose a tag to compare

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

  1. Added the when keyword, which is used to conditionally execute control flow structures.

Raw Strings

  1. Added support for raw strings. Use cases are: regular expressions, unformatted strings.
  2. These strings begin and end with a single-quote.
  3. Updated docs for new string documentation.

Regular expressions

  1. Added support for regular expressions.
  2. Added several builtins for this: find, match, matches, matches_all, and scan.
  3. Updated docs for new builtins.

New builtin .clone()

  1. 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()

  1. Added a .pretty() builtin. It produces a pretty serialization of lists and hashes.

New keyword parse

  1. Added a parse keyword. This keyword is similar to eval in other languages.
  2. 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.
  3. Updated the docs to reflect this feature.

New standard library module @kiwi/http

  1. Added @kiwi/http. Using cpp-httplib to to implement builtins with httplib::Client.
  2. Updated the docs to include the module information.

New standard library module @kiwi/log

  1. Added @kiwi/log. This module exposes kiwi logger functionality.
  2. Updated the docs to include the module information.

New DateTime class.

  1. Added a DateTime class. Import @kiwi/time.
  2. Updated the docs to include the DateTime class.

Bug Fixes

  1. Fixed an issue with base class resolution in is_a builtin
  2. Fixed an issue with deeply nested conditional logic.
  3. Fixed an issue with multi-dimensional list indexes.
  4. Fixed an issue with lambdas as method parameters.
  5. 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