On Monday, June 17, 2013 2:34:00 PM UTC-5, Bram Moolenaar wrote:
> 
> I do not like the idea of accessing functions with arbitrary names.
> 
> I would rather also disallow:
> 
>   let dict['/foo'] = function('tr')
> 
> Would that break any plugin?
> 

Hi, Bram! I saw in your recent todo.txt update that you still have a note about 
possibly removing this functionality.

Consider the following use case based on a real need I had once:

A communication protocol has 2-byte IDs for commands. Each command identified 
by this 2-byte ID has potentially different command lengths and meaning of the 
remaining bytes in the message.

I want to parse a capture file containing a hex representation of this 
communication protocol. In real life, I would probably do this using Perl so 
others on my team can use it, but I *could* do it in Vim.

So, I create a Dict in vim with key strings corresponding to the hex value of 
the command IDs, e.g. "12AE". I assign each key a function reference to be used 
to parse the rest of that particular message.

Note that "12AE" is an invalid function name. But I want to be able to call a 
function corresponding to that name in a lookup table anyway.

Now, "12AE" isn't too weird of a name. But the protocol could be based on ASCII 
characters instead of byte values. Perhaps commands look like /command and data 
looks like [data]. Perhaps I want to be able to look up "/command" in the 
lookup table.

I think allowing arbitrary dict keys to point to function references is a very 
useful feature. And it isn't confusing if you remember that you're storing a 
function reference in a Dict, not naming a function with a weird name. I think 
we should definitely keep the ability to assign a function reference to an 
arbitrary dict key. Furthermore, using this syntax:

  function dict['/foo']() 
  endfunction

allows doing this in a way that will not pollute the function namespace with 
extra functions that never get called directly.

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Raspunde prin e-mail lui