Giter Site home page Giter Site logo

los's Introduction

LFE Object System Build Status

Introduction

LOS is inspired by CLOS. It may or may not provide macros for more than one object system. We shall see.

When referring to the plural form, we recommend the Spanish "los LOS". In the singular form, "el LOS", "the LOS" or just "LOS" are all acceptable. LFE LOS may have been named after the definite article, or the town in Sweden, or the crater on Mars.

Feel free to also make "loss" puns. These will be quite amusing for all, and apropos.

More seriously, the initial implementation will be taken from Peter Norvig's PAIP, Chapter 13 as well as ideas implemented in Clojure.

Why OOP?

Blame it on cadar; he made me do it. But before that, there was this, so I guess it can't all be laid at his feet.

Peter Norvig said it best (especially when we take it out of context):

"Object-oriented programming turns the world of computing on its side..."

And now that we've got a doubly-functional programming language (Lisp + Erlang), we're going to turn it over on its other side.

The reason this project is blamed on cadar is that he made a very good argument that 1) there are definitely valid use cases for OOP (or AOP), and 2) we should offer people that flexibility.

Features

Development Plan

First, we're going to start with a simple knock-off of CLOS as developed by Peter Norvig in PAIP, Chapter 13. This will be done using classic lambda closures. Next, we'll look at using processes instead of lambdas for closures. This is defnitely the more Erlang-y way to do it, but it may be more inefficient for many uses. Then, we may look at Clojure's protocols and add support for that. After this, the sky's the limit. Or maybe not. Who knows?

lambda Closures

  • defclass -

Dependencies

This project assumes that you have rebar and lfetool installed somewhere in your $PATH.

Installation

Just add it to your rebar.config deps:

    {deps, [
        ...
        {los, ".*", {git, "[email protected]:lfex/los.git", "master"}}
      ]}.

And then do the usual for your lfetool-created project:

    $ rebar compile

This will automatically download the project deps and compile them before also compiling LOS.

Usage

To be done ...

References

los's People

Contributors

oubiwann avatar

Stargazers

Józef Piątkiewicz avatar paling avatar Leonardo Rossi avatar Eric Bailey avatar Mats W avatar  avatar Kyle Isom avatar

Watchers

Robert Virding avatar Kyle Isom avatar paling avatar James Cloos avatar  avatar

Forkers

longde123

los's Issues

Create defclass macro

This should be based on the example from Chapter 13, Section 4 of Peter Norvig's PAIP.

Discussion on polymorphism idioms in LFE

There was a blog post written about this topic here:

Code for exploring polymorphism continues to grow/adapt here:

This issue was opened in particular due to a tantalizing comment made by @rvirding on the LFE mail list -- he may have some nice ideas for better LFE idioms:

Add implementation for Clojure-like multi-methods

Usage should be something like this:

> (include-lib "los/include/multi-methods.lfe")
> (defmulti area 'type)
> (defmethod area 'rectangle
       ((`(#(length ,l) #(width ,w)))
         (* l w)))
> (area '(#(type triangle) #(base 2) #(height 4)))
  4.0

A non-macro version of this could be done in the following manner:

(defmodule polymorph
  (export all))

(defun area
  ((`(,type . ,rest))
   (dispatch 'area type rest)))

(defun dispatch
  ((fname `#(type ,type) args)
   (call (MODULE) (list_to_atom (++ (atom_to_list fname)
                                    "-"
                                    (atom_to_list type))) args)))

(defun area-triangle
  ((`(#(base ,b) #(height ,h)))
   (* b h (/ 1 2))))

(defun area-rectangle
  ((`(#(length ,l) #(width ,w)))
   (* l w)))

These could then be used in the following manner:

(c "examples/no-macros/polymorph.lfe")
#(module polymorph)
(slurp "examples/no-macros/polymorph.lfe")
#(module polymorph)
> (area '(#(type triangle) #(base 2) #(height 4)))
4.0
> (area '(#(type rectangle) #(length 2) #(width 4)))
8

Additional implementations could be added with ease:

(defun area-square
  ((`(#(side ,s)))
   (* s s)))

(defun area-circle
  ((`(#(radius ,r)))
   (* (math:pi) r r)))

Then use them:

> (area '(#(type square) #(side 2)))
  4
> (area '(#(type circle) #(radius 2)))
  12.566370614359172

See the following:

Copy OOP Examples from LFE to LOS

There should be 3 files in lfe/examples that we should move here.

As progress is made on LOS, those examples will be updated to utilize LOS and its growing features.

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.