h3rald / min

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

Seal-ity Control #68

Closed ghost closed 3 years ago

ghost commented 3 years ago

Thanks for adding more methods in Min and i have question: "How can we understand whether variable is sealed?" I tried a hacky method for "line-info" 😃 but this, a method for sealing control, seems more hard to make unusually(And i am unsuccessful at this thing).

Seality is very important for defining modules. Because some things must not be changed by anybody else. In Min lang, variables and functions mean => symbol. And this is normal. However i realized some symbols makes conflicts when importing our written modules which defined as dictionaries("dict:module"). For example in REPL, i can all change num module via running 5 :num. Maybe Min should unseal all symbols and sigils which defined natively. Maybe some functions are needed for sealing/unsealing all symbols in current scope.

ghost commented 3 years ago

I make a try on try.

h3rald commented 3 years ago

I'll definitely add a sealed? symbol... it's something really easy to implement in Nim, but there's no way to do it in pure min, unless of course as you suggested you try with a try symbol to set the symbol.

You are right about the importance of sealing BUT to be honest it is now possible to use the require symbol instead of load + import to essentially load a module from an external file.

I should really write some best practices but I did update the docs recently about this. Essentially, require:

Additionally, it will also check that the external file doesn't pollute the stack by adding extra items to it.

This new symbol, coupled with the new invoke symbol basically lets you use symbols defined in another file easily without having to import them in the current scope...

This makes everything much easier (you basically never have to declare modules explicitly) and safer.

Also... required files are cached automatically and they will be executed only once even if required multiple times, like you would expect in a normal programming languag (loaded files are not).

Speaking of cool new things... make sure to check the new operator symbol in the docs... it's a very powerful and neat way to define symbols and sigils, with automatic checks, signature, automatic variable captures...

Yes I should write a proper article on this new stuff... I added a lot of stuff in the past few weeks!

ghost commented 3 years ago

I understand what you said(except invoke, operator at using phase). I am using load and i am thinking(i am trying) to switch that to require as you say. The problem that operator has, i think, it is a bit like outside of Min language syntax. But i accept it is efficient way to define symbols. Probably i will use it to define symbols.

ghost commented 3 years ago

I completed require implemention in my modules however i didn't understand how can invoke be used?

h3rald commented 3 years ago

Alright typically you wanna use the * sigil to use the invoke symbol, so... say you wanna require you mathutils module and then use the factorial symbol:

 "mathutils" require :mathutils
 5 *mathutils/factorial

Note that the name you give your module when requiring can be whatever you want, and that you can even call symbols within hierarchies of dictionaries using /s within your invoke string.

ghost commented 3 years ago

Thanks! Now i am using './src/utils.min require +utils instead of ("'" . "./src/utils.min") => '"" join eval require +utils. That was very helpful info. 👍 . Quo.: +utils or :utils?

h3rald commented 3 years ago

Well, actually they both work! But require already returns a module so you can simply assign it using : instead of *.

ghost commented 3 years ago

Is understood

h3rald commented 3 years ago

Added sealed? symbol in v0.29.0