h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
311 stars 23 forks source link

Operators Documentation #69

Closed ghost closed 3 years ago

ghost commented 3 years ago

I cannot use operator constructing in min files. Because its behavior is so confusing. May you give more info about operators? For example void returning?

h3rald commented 3 years ago

Alright it is quite a lot to take in... I should release some sample project really to show some real-world usage. I am actually working on a small web-based knowledge base API in min, but it's not quite ready yet to be open sourced.

So... right, I'll explain here then update the docs as well.

When you define your operator signature, the output values are actually already bound to null. The problem is that you are going to get an error if you don't re-bind them unless you specify a type signature which allows a nullable value, like this:

 ( 
  symbol get-or-null
  (quot :list i :item ==> a|null :result)
  (
    (list i in?)
      (i @result)
      (return)
    if
  )
 ) ::

Void returning? Just don't put anything after ==> in the signature:

(
 symbol echo 
 (a :item ==>)
 (item puts)
) ::
ghost commented 3 years ago

Extra thanks 😄 for examples about operator defining. Now...:

This is going to be a Parchment of Questions 💯 (Making a lang like a real lang is not so easy, that i mean. i may be successful at.)

h3rald commented 3 years ago

Improved docs in v0.29.0