Monday, December 30, 2013

Re: funcrefs forms


On Dec 31, 2013 11:24 AM, "Alexandre Hoïde" <alexandre.hoide@gmail.com> wrote:
>
> On Mon, Dec 30, 2013 at 10:18:21PM +0400, Nikolay Pavlov wrote:
> > On Dec 30, 2013 5:58 PM, "Alexandre Hoïde" <alexandre.hoide@gmail.com>
> > wrote:
> > >
> > > On Mon, Dec 30, 2013 at 08:55:17AM +0100, Alexandre Hoïde wrote:
> > > > .vim <--
> > > > function! s:SID()
> > > >   return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
> > > > endfunction
> > > >
> > > > function! s:objectConstructor(name)
> > > >   let obj = {}
> > > >   let obj.name = a:name
> > > >   let obj.form1 = s:objFuncs.form1
> > > >   let obj.form2 = function('<SNR>' . s:SID() . '_s:objFuncs_form2')
> > > >   return obj
> > > > endfunction
> > > >
> > > > let s:objFuncs = {}
> > > >
> > > > function! s:objFuncs.form1()
> > > >   echo self.name
> > > > endfunction
> > > >
> > > > function! <SID>s:objFuncs_form2() dict
> > > >   echo self.name
> > > > endfunction
> > > >
> > > > let otst = s:objectConstructor('test')
> > > > call otst.form1()
> > > > call otst.form2()
> > > > -->
> > >
> > >   … to be more specific, on the sample code above, the following :
> > > <--
> > > echo function('s:objFuncs.form1')
> >
> > Now please try calling this (i.e. just append ()). *function() is not a
> > replacement for eval*. You have found function() bug, nothing more. To get
> > *real* results *echo actual funcref*. As I said if you define function
> > inside a dictionary *you already get funcref*. Thus what you need is just
> > echo s:objFuncs.form1.
> >
>   Hi and thanks again for taking some time to help. Although I allready
> knew how to get the *real* result… thanks to your answer to my first
> thread.
>
>   Here, I did not put this "echo function('s:objFuncs.form1/2)" to get
> the real result, but just to illustrate the fact that, to me, form1 and
> form2 seems to be equivalent :
> > > <SNR>36_objFuncs.form1
> > > <SNR>36_s:objFuncs_form2

Again, ***try calling funcref in the first form***. Funcrefs are not for echoing, they are for calling. First form **does not exist**. It is a function() bug and nothing else.

>
>   So I (still) wonder why some real developpers would use form2 (the non
> anonymous version) rather than form1 ? I hope this claryfies my question
> and that I understood your answer correctly. ^^
>
>   Best regards.
>
> > > echo function('<SNR>' . s:SID() . '_s:objFuncs_form2')
> > > --> Gives <--
> > > <SNR>36_objFuncs.form1
> > > <SNR>36_s:objFuncs_form2
> > > -->
> > >
> > >   Except form1 being {anonymous,numbered}-function and form2 beeing
> > > just a dictionary-function, I don't see much difference between the 2
> > > forms.
> > >
> > >   The 1st form being more concise, I was wondering
> > >   a) why would someone use form2 (which I came accross on riml¹ README).
> > >   b) what makes the anonymous form1 preferable (besides conciseness)
> > >
> > > ¹ https://github.com/luke-gru/riml
> > >
>
> --
>  ___________________
> | $ post_tenebras ↲ |       waouh !
> | GNU        \ /    |      /
> |          -- * --  |     o
> | $ who ↲    / \    |_-- ~_|
> | Alexandre Hoïde   |  _/| |
>  -------------------
>
> --
> --
> 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/groups/opt_out.

--
--
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/groups/opt_out.

No comments: