Monday, January 3, 2022

Re: Vim9 import [was Vim9 script feature-complete]



On Mon, Jan 3, 2022, 11:23 Lifepillar <lifepillar@lifepillar.me> wrote:
On 2022-01-03, Marvin Renich <mrvn@renich.org> wrote:
> Don't bother with the

>   import MyClass from "myclass.vim"
>   import {someValue, MyClass} from "thatscript.vim"
>
> syntax, and only provide
>
>   import "myclass.vim"
>   import "myclass.vim" as Other
>
> and require use of the namespace prefix:
>
>   Other.MyClass
>
> The first case, without the "as" would default to the file name, with
> leading directories and trailing ".vim" removed

I do not think that using a filename as an identifier is a good idea.
For instance, calling a script 1.vim would automatically make it
non-importable (without "as").

I personally find that using an imported name without a prefix (as it is
currently possible) makes my code terse, and I think that in the limited
scope a plugin that works well. But I understand that Vim9 scripts might
have a broader use, such as generic libraries of functions that can be
used by many scripts. In that context, stricter scoping rules, such as
in Go, are likely a cleaner approach.

How about always requiring a prefix, but allowing explicit namespace
pollution? As in

    import "myclass.vim" as Other
    use Other  # Makes Other.F() available as just F()

Life.

I like this approach. If you don't want explicit prefixes, use the use. :)

Maybe the system could be defaulted to assume the 'use' clause in case of an import without an 'as'?

import 'myclass.vim'

Automatically equivalent to Life's example except that Other.F() isn't allowed, only F().

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CANuxnEdU6Vs2oLNZFkpMN1TDBohuWPMcLV-9kEbShkBWbFY%3DBw%40mail.gmail.com.

No comments: