r/ProgrammingLanguages • • 20h ago

Kiki Lang - query, markup, coding

I have been working on this for a while, and would like to share and get some feedback.

It started as a query language, then grows to add markup features, to be useful for building interactive data apps.

Below is a sample Kiki program. The idea of mixing markup and coding, is in the same category of LaTex or Typst, but Kiki focus more on data/query, and uses a different syntax design.

# Kiki Lang

Kiki is literal, meaning that the program is a prose. Lines start with "> " or inline \(12 + 34) are code blocks.

The two \(bold ~ core ideas) are:
- Lisp like syntax, which is nice across query, markup and coding.
- Algebric effect, which is used for errors, I/O, optionals, and state.

Here are the collections: list, record, and table.

> names = ["alice" "bob"]
> alice = {name = "alice" age = 20}
> users = |name  age|
           alice 20
           bob   30

"=>" is a form of inline unit test:

> type-of names => :[string]
> type-of alice => :{name = string age = int}
> type-of users => :|name = string age = int|

Query is an important part of the language:

> users |> filter age >= 18 
        |> select name

Here is a function with pattern matching:

> fib = fn 0 -> 1
        fn 1 -> 1 
        fn n -> fib (n - 1) + fib (n - 2)

And it can be called inline as \(fib 10).
10 Upvotes

18 comments sorted by

View all comments

2

u/titaniumalt 20h ago
> users = |name  age|
           alice 20
           bob   30

confusing table syntax

i love the simplicity and functional design, but it feels a bit redundant to have both tables and records

4

u/terryio 20h ago

Well table is the most important part of kiki since it is to handle spreadsheet like data. Record is less important and only useful for writing certain functions. That syntax is layout (indent) aware. Any better idea for table syntax?

3

u/sphen_lee 19h ago

A table is logically equivalent to a list of records with the same fields? I assume you can store it more efficiently (maybe columnar?)

In terms of syntax, it probably needs separators between columns. Like || for the column names and then | between each column. Otherwise it could get hard to read if the values are not literals.

(It's also nice to include a non-indentation variant. Like JSON? Some people prefer it, but it's also easier for code generators)

2

u/terryio 19h ago

> A table is logically equivalent to a list of records with the same fields? I assume you can store it more efficiently (maybe columnar?)

Both are yes. The compiler uses some columnar encoding in memory.

> needs separators between columns

Fair point. My plan was to rely on editor and/or formatter to keep the table aligned nice. Though adding an optional column/field divider could be useful I think.

1

u/mamcx 19m ago

Take a look at how I done at https://tablam.org/syntax

-- A 2d vector. Normal people call it a table
[city:Str, country:Str; 
  "miami", "USA"; 
  "bogota", "Colombia"] 

1

u/evincarofautumn 19h ago

Would you mind elaborating on what you mean by “confusing”? Are you saying it’s hard to tell what this code does, or easy to misread it as doing something different than it actually does, or something else?

1

u/titaniumalt 19h ago

Like, i can't see how the table is parsed (why do the pipes only surround the first element) and for longer tables you might get confused if you can't see the first line of definition.