Monday, December 30, 2013

Re: funcrefs forms

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')
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.

No comments: