Friday, January 6, 2017

Re: perl vs python bindings for vim and tab page object access

On 01/06/2017 07:20 AM, LCD 47 wrote:

> On a side note: if_perl doesn't allow variable bindings the way
> if_pyth does. For this reason passing non-trivial data structures
> back and forth between Vim and Perl is often more complicated than the
> rest of the code combined. A while ago I looked into backporting that
> feature from if_pyth, and I quickly realised that the main problem in
> doing it is the explicit difference Perl makes between lists, arrays,
> and references to said objects, which has no equivalent in Vim.

I'm still reading through the perl documentation for XS files and the
perl API in order to get a better understanding of if_perl.xs. But,
based on what I've read in the code so far, both buffer and window
objects appear to have the provision to return values in either the
scalar or list context.

That is, the use newBUFrv and newWINrv respectively to push the object
onto the stack for the return value.

The function definitions for newBUFrv and newWINrv appear to be nearly
identical and they make use of macros defined in globals.h for looping
through buffers or windows. There are macros for looping through tab
pages as well.

Given that, could the approach used for accessing buffer or window
objects be re-used for tab page objects?

I most likely am missing something in terms of how a tab page object
differs from a buffer object and a window object in terms of being able
to translate it and pass it to perl from Vim though.

> And
> even when no references are involved, the semantic is still somewhat
> different. For example, in Perl you can do things like this:
>
> $ perl -MData::Dumper -e '@a = ((1, 2), (3, 4)); print Dumper(\@a)'
> $VAR1 = [
> 1,
> 2,
> 3,
> 4
> ];
>
> which, among many other things, allows map() to change the number of
> elements of its input:
>
> $ perl -MData::Dumper -e '@a = map { (0, $_) } (1, 2); print Dumper(\@a)'
> $VAR1 = [
> 0,
> 1,
> 0,
> 2
> ];
>
> Doing the same in Vim is a lot more convoluted. Just FWIW.

Granted, though I don't think doing something like this is supported for
the existing buffer and window bindings that exist in the VIM perl package.

--
--
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.
For more options, visit https://groups.google.com/d/optout.

No comments: