Kopi, the short, short version

11 views
Skip to first unread message

Mike Austin

unread,
Aug 16, 2023, 2:38:09 PM8/16/23
to PiLuD
I am kind of a minimalist, and one thing I'm trying to do is define a cheat sheet for basic syntax and types of Kopi. Given that a person knows JS and the basics of Haskell/ML, would you understand how to write a small program in Kopi with this?

Syntax

1 + 2 * 3 Basic math (== 7)
s = "Hello" Basic assignment
[a, b] = "ab" Pattern matching
f (x) = x * x Function definition
(x) => x * x Anonymous function
print "Hello" Function application
5 | toFixed 2 Invoking a method
'(toFixed 2) 5 Alternate invocation
(1, 2).0 Tuple index access
(x: 1, y: 2).x Tuple field access
array.(3) Array index access
array.(1..5) Array slice access
"ab" ++ "cd" Concatenation operator
x < 0 ? -x : x Conditional expression
{ Multiple statements
  x = 5
  print x + 1
}


Some of these are not currently supported in the newest Kopi, but will be soon (array access, conditional, array pattern).

Types

1  -2.5  3.14 Number + – * / % == != < > <= >= succ
"Hello, world" String ++ == != < > <= >= .() size  succ
true  false Boolean   == != !
'ident  '(+ 1) ASTree    apply
(x) => x * x Function  apply
1..5  "a".."z" Range .from .to .by toArray apply
(1, '2, "abc") Tuple .N map
(x: 1, y: 2) Record .field map
[1, 2, 3, 4] Array .(N) ++ size


Elements can also be separated by newline, and tuples/record syntax mixed. "ASTree" is not my favorite type name, but it is an "expression tree" in C# parlance.

Functions

let (n = 5) => { Looping
  print n
  loop (n - 1)
}
match n (
Matching
  0 => 1
  n => n * n
)

Other things to write about:

Pattern matching in depth
Method pipelining
100% Asynchronous
Operator precedence
Dictionary type
More Examples

My previous version based on the previous version of Kopi:


Sébastien Pierre

unread,
Aug 22, 2023, 4:22:59 AM8/22/23
to pi...@googlegroups.com
That's pretty cool -- it reminds me of Hundred Rabbit's UXN talk https://www.youtube.com/watch?v=9TJuOwy4aGA, about defining a set of primitives for their VM that would fit on a piece of paper. One thing I don't see is invocation with more than one argument?

The examples on the wiki do a good job at showing the pipeline-abilty of the language.

Sebastien

--
You received this message because you are subscribed to the Google Groups "PiLuD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pilud+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pilud/92a87d3f-0752-4b99-bfc1-4060ede968aan%40googlegroups.com.

Mike Austin

unread,
Aug 22, 2023, 7:29:21 PM8/22/23
to PiLuD
I can feel it's almost finished :) I haven't had a chance to watch to video to completion yet, hopefully tomorrow. It does look interesting, and I like the spirit of "using old computer" to make software fast :)

Oh, function invocation or method invocation is just like Haskell or ML family, only one argument, but arguments can be passed via currying (f a b) or passed as a tuple/record "foo (2, 3)". It depends on the style you want, for example with "match" the currying really makes the syntax clean. If there are many arguments or you want "named arguments", you pass a tuple/record.

I realize there's missing context in many places (I'd be talking more in depth if I was presenting). Maybe I can add notes.
Reply all
Reply to author
Forward
0 new messages