On Tue, Dec 31, 2013 at 11:28:25AM +0400, Nikolay Pavlov wrote:
> 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.
>
Ah ok ^^ Like this you mean ? :
<--
call function('s:objFuncs.form1')()
-->
E117: Unknown function: <SNR>32_objFuncs.form1
<--
call function('<SNR>' . s:SID() . '_s:objFuncs_form2')()
-->
E725: Calling dict function without Dictionary: <SNR>32_s:objFuns_form2
Ok, this function() bug increased my confusion and form1 is *not*
equivalent to form2. 's:objFuncs.form1' *is* the funcref, and
'function('s:objFuns.form1') is a non-sense (would be the funcref of a
funcref). Thanks for that clarification.
Now : in this particular context of an object constructor function,
are there any "use-case" where form2 should be used rather than form1 ?
Riml guys and you are a million years ahead of me in term of
programing. So, if they use form2 instead of form1, it means there's
something I still fail to understand. ^^ Why use a named dict function
and get a funcref later on (at the cost of verbosity), rather than
directly obtaining this funcref using form1 ?
Best regards, and thanks again for your patience ;)
> >
> > 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.
--
___________________
| $ 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.
No comments:
Post a Comment