Code Monkey home page Code Monkey logo

object.vim's Introduction

object.vim

               __      _           __
        ____  / /_    (_)__  _____/ /_
       / __ \/ __ \  / / _ \/ ___/ __/
      / /_/ / /_/ / / /  __/ /__/ /_
      \____/_.___/_/ /\___/\___/\__/
                /___/

object.vim is a minimal framework for Python-like programming in VimScript.

Examples

  • Defining classes and creating instances.
let MyClass = object#class('MyClass')
let var = object#new(MyClass)
  • Calling methods of parents and siblings with super().
" MyClass as above.
function! MyClass.__init__()
  call object#super(MyClass, self).__init__()
  let self.data = 1
endfunction
  • Creating Lambdas.
let x = reverse(range(3))
echo sort(x, object#lambda('x y', 'x - y'))
[0, 1, 2]
  • Iterator and for loop construct.
echo object#list(object#zip('abc', range(3)))
[['a', 0], ['b', 1], ['c', 2]]

let dict = {'foo': 1, 'bar': 2}
call object#for('key val', items(dict), 'echo key val')
foo 1
bar 2
  • Open files for reading and writing.
let f = object#open('data.txt', 'r')
echo object#repr(f)
<open file 'data.txt', mode 'r'>

echo f.read()
'All the lines concatenated with newline.'
  • Wrappers for built-in types for inheritance.
let dict = object#dict_()
echo object#repr(dict)
<'dict' type>

let MyDict = object#class('MyDict', dict)
let var = object#new(MyDict, {'foo': 1})
echo var.values()
[['foo', 1]]
  • A bunch of customizable protocol functions.
echo object#len(range(10))
10

echo object#contains('', 'string')
1

let object = object#object_()
echo object#dir(object)
['__name__', '__bases__', '__base__', '__repr__', '__class__', '__init__', '__mro__']
  • Hashing arbitrary objects.
echo object#hash('this is a string')
197650594

echo object#hash(-1234)
2147482414

echo object#hash(function('tr'))
233815837
  • Class-based exceptions.
let except = object#except#builtins()
call object#class('MyException', except.Exception, g:)
call object#raise(MyException)
E605: Exception not caught: MyException:

Features

  • Shallow namespace object#.
  • Multiple inheritances powered by C3 linearization.
  • A complete set of Python-like built-in functions.
  • True lambda with closure and named arguments.
  • True iterator and zip() and enumerate().
  • Hash (nearly) arbitrary object.
  • Read and write files with open().

Installation

This plugin follows the standard runtime path structure, so it can be installed with a variety of plugin managers:

Plugin Manager Command
NeoBundle NeoBundle 'cgsdfc/object.vim'
Vundle Plugin 'cgsdfc/object.vim'
Plug Plug 'cgsdfc/object.vim'
VAM call vam#ActivateAddons(['vim-airline'])
Dein call dein#add('cgsdfc/object.vim')
minpac call minpac#add('cgsdfc/object.vim')

Dependencies

Documentation

Please read the docs or after installation, run :help object to see the full documents.

Citation

If you find our software useful in your research, please consider citing us as follows:

@misc{cong_objectvim_2018,
  title = {object.vim: {A} minimal framework for {Python}-like programming in {VimScript}.},
  shorttitle = {object.vim},
  url = {https://github.com/cgsdfc/object.vim},
  abstract = {object.vim is a minimal framework for Python-like programming in VimScript. It provides some of the core features of the Python programming language in the form of VimScript functions and dictionaries, such as class-based object-oriented programming, lambda functions, iterators, and exceptions. It is also an interesting try to implement features of a high-level language in terms of another lower-level language.},
  author = {Cong, Feng},
  year = {2018},
}

object.vim's People

Contributors

cgsdfc avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.