On 8/3/19 4:29 PM, Bram Moolenaar wrote:
I wrote:
Patch 8.1.1803
Problem: All builtin functions are global.
Solution: Add the method call operator ->. Implemented for a limited number
of functions.
Files: runtime/doc/eval.txt, src/eval.c, src/structs.h, src/userfunc.c,
src/globals.h, src/evalfunc.c, src/proto/evalfunc.pro,
src/testdir/test_method.vim, src/testdir/Make_all.mak
For now this makes a few existing functions available as methods, e.g.
mylist->filter(filterexpr)->map(mapexpr)->sort()->join()
It's a lot easier to read than:
join(sort(map(filter(mylist, filterexpr), mapexpr)))
When we add new methods for List, Dict, etc. we can now make them local
to those objects, instead of adding them globally.
I decided to use "->" because of the similarity with C pointer usage.
It would be nice to use ".", but I'm quite sure that won't be backwards
compatible, especially when using a Dict.
I agree, backwards compatibility should not be broken.
But I wonder if "." is fine with scriptversion 2. If the dict has a
field named
"len" then it will be used as before, otherwise the len() function will
be called.
This means users can also override the methods if they choose, but no
existing
scripts would be broken.
Comments are welcome!
--
--
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/e9cef5bd-08d6-1cda-04fb-5180392eb5aa%40gmail.com.