Friday, January 20, 2023

Re: Using Vim9 for a function

On Fri, Jan 20, 2023 at 1:48 AM andalou <cesar.romani@gmail.com> wrote:
>
>
> I'm using vim 9.1221 on Windows 10. I tried to create a function using
> Vim9, as in:
>
> def! Foo(a: float, b: float): float
> return a + b
> enddef
>
> If I call Foo(1.2, 5.0) I get the answer 6.2
>
> but if I call Foo(1.2, 5) I get:
>
> E1013: Argument 2:type mismatch, expected float but got number
>
> How can I modify the function to make it possible to call Foo(1.2, 5)
> and get a result.
>
> Many thanks in advance,
>
> --
> Cesar

IIUC, allowing a Number to be used where a Float is expected is
permitted in Vim pre-9 but forbidden in Vim 9.

Solution 1: Use "function" instead of "def". This will make your
function a "legacy function" and it won't need strict-typed arguments:

:function Foo(a, b)
:return a + b
:endfunction

Solution 2: call Foo(1.2, 5.0) instead.

Best regards,
Tony.

--
--
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/CAJkCKXvFR7fTBp%2BvKKsKt4c9HDJP0H04OJ5kvBJe_C7S9mh0KA%40mail.gmail.com.

No comments: