Thursday, August 19, 2021

Re: [vim9script] Why is a forward declaration needed?

> Hi, I have tried to port this TypeScript script:
>
> https://github.com/sigma-engineering/blog-combinators/blob/master/index.ts
>
> to Vim9 script (please find the full code at the end of this message).
> It appears to work, but to make it work I had to add a "forward
> declaration" of the Call() function:
>
> var Call: func(dict<any>): dict<any>
>
> If I comment out the above line, I get a "E1001: Variable not found:
> Call" error, pointing at this line:
>
> const TrailingArg = Map(Sequence([Str(","), Expr]), (args) => args[1])
>
> What baffles me is that Vim doesn't complain in the same way about
> NumberLiteral. Does anyone have an explanation for this behaviour?

You are using "Call" in Expr(), and Expr is used in an expression
to set "TrailingArg". To be able to check the type there, Expr() is
compiled, which requires "Call" to exist.

NumberLiteral is defined just before setting "TrailingArg".

What is tricky here that in principle a variable needs to be defined
before used, and when used in a function it should be defined before
that function. But since compilation is done only when needed, it can
be defined after the function, so long as it's before compiling it.

--
What do you get when you cross a joke with a rehtorical question?

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
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/202108191909.17JJ941V654208%40masaka.moolenaar.net.

No comments: