Coder Social home page Coder Social logo

zepto-classes's Introduction

bach

Classes for zepto*!

They're really minimal. But inheritance is supported!

* sort of.

Installation

zeps install hellerve/bach

Usage

There are two macros you can make use of, class and inherits.

A class could look like so:

(load "bach/bach")

(class Person
  (properties
    :name
    (:age :default 0))

  (functions
    (->string (lambda (self) (++ (Person:get-name self) ", age " (->string (Person:get-age self)))))))

This will generate the following functions:

(define joe (Person :name "Joe" :age 24))
(Person:get-name joe) ; => "Joe"
(Person:get-age joe) ; => 24
(Person:->string joe) ; => "Joe, age 24"
(Person:->string (Person:set-name joe "Tina")) ; => "Tina, age 24"
(Person:->string (Person:set-age joe 30)) ; => "Joe, age 30"
(Person? joe) ; => true
(Person:get-properties) ; => [:name, :age]

You can also inherit methods (but not properties!) from other classes:

(class Employee
  (properties
    :name
    (:age :default 0)
    (:job :default "Programming Grunt"))

  (functions
    (->string-with-job (lambda (self) (++ (Employee:->string self) " (" (Employee:get-job self) ")")))))

(inherits Employee Person)

(define my-grunt (Employee :name "Alyssa" :age 35))
(Employee:->string-with-job my-grunt) ; => "Alyssa, age 35 (Programming Grunt)"

And that's about it. Check out the examples!

Advanced Information

Inheritance resolution

The inheritance is resolved on a "first statement wins" basis, which means that if Duck and Bird both implement a method called fly and Ostrich inherits first from Duck, then from Bird, the fly method as implemented in Duck will be used, whether it was inherited or not.

Typing Information

Under the hood, all the classes are hashmaps. No fancy magic involved. They do not carry their functions around, so they're not classes, but rather prototype-ish.

FAQ

Q: Is this a serious project?

A: Not really, no. I have none of those.

Q: Is this ready for production?

A: Is zepto? If you answer that with yes, then sure, go ahead and use this library. YMMV.

Q: Why bach?

A: Because (1) I like to listen to the music the family Bach composed and, (2) they are the epitome of classical music. Geddit? As if programming did not have enough terrible puns yet.


Have fun!

zepto-classes's People

Contributors

hellerve 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.