Code Monkey home page Code Monkey logo

doodler's Introduction

clojerl

Build Hex.pm

Clojure implemented on the Erlang VM.

Building

Building clojerl requires Erlang/OTP 21+ and rebar3.

git clone https://github.com/clojerl/clojerl
cd clojerl
make

On Windows:

git clone https://github.com/clojerl/clojerl
cd clojerl
rebar3 clojerl compile

Getting Started

Documentation and Resources

There is more information regarding Clojerl in clojerl.org, where you can find what features does Clojerl include and how it differs from Clojure.

Online REPL

To try it out and get a sense of what you can do, you can visit Try Clojerl.

Docker REPL

To quickly try out clojerl via docker you can make use of the docker image like so:

docker pull clojerl/clojerl
docker run -it clojerl/clojerl

Then you should be able to see the prompt:

Clojure 0.6.0
clje.user=>

Local REPL

Running make repl (on Windows first run rebar3 clojerl compile and then bin/clje.bat) will start the REPL and show its prompt:

Clojure 0.6.0
clje.user=>

From the REPL it's possible to start evaluating Clojure expressions:

clje.user=> (map inc (range 10))
(1 2 3 4 5 6 7 8 9 10)
clje.user=> (doc map)
-------------------------
clojure.core/map
([f] [f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])
  Returns a lazy sequence consisting of the result of applying f to
  the set of first items of each coll, followed by applying f to the
  set of second items in each coll, until any one of the colls is
  exhausted.  Any remaining items in other colls are ignored. Function
  f should accept number-of-colls arguments. Returns a transducer when
  no collection is provided.
nil
clje.user=> (doc inc)
-------------------------
clojure.core/inc
([x])
  Returns a number one greater than num.
nil
clje.user=>

Code Examples

There are some very basic examples in the scripts/examples directory. These are meant to be references on how special forms in Clojure on the BEAM are used and how they sometimes differ from Clojure JVM.

Web Application Example

For a very basic example of a web project please check the example-web-app repository.

Building Your Own App

The build tool for Clojerl is the rebar3_clojerl plugin. rebar3 is the official build tool in the Erlang community.

The plugin provides helpful commands to:

  • Build a basic directory scaffolding for a new project
  • Compile
  • Run tests
  • Start a REPL

For more information on how to use this plugin please check the documentation in rebar3_clojerl.

Rationale

Erlang is a great language for building safe, reliable and scalable systems. It provides immutable, persistent data structures out of the box and its concurrency semantics are unequalled by any other language.

Clojure is a Lisp and as such comes with all the goodies Lisps provide. Apart from these Clojure also introduces powerful abstractions such as protocols, multimethods and seqs, to name a few.

Clojure was built to simplify the development of concurrent programs and some of its concurrency abstractions could be adapted to Erlang. It is fair to say that combining the power of the Erlang VM with the expressiveness of Clojure could provide an interesting, useful result to make the lives of many programmers simpler and make the world a happier place.

Goals

  • Interoperability as smooth as possible, just like Clojure proper and ClojureScript do.
  • Provide most Clojure abstractions.
  • Provide all Erlang abstractions and toolset.
  • Include a default OTP library in Clojerl.

Personal Goal

Learn more about Erlang (and its VM), Clojure and language implementation.

This project is an experiment that I hope others will find useful. Regardless of whether it becomes a fully functional implementation of Clojure or not, I will have learned a lot along the way.

QAs

What is Clojerl?

Clojerl is an experimental implementation of Clojure on the Erlang VM. Its goal is to leverage the features and abstractions of Clojure that we love (macros, collections, seq, protocols, multimethods, metadata, etc.), with the robustness the Erlang VM provides for building (distributed) systems.

Have you heard about LFE and Joxa?

Yes. LFE and Joxa were each created with very specific and different goals in mind. LFE was born to provide a LISP syntax for Erlang. Joxa was mainly created as a platform for creating DSLs that could take advantage of the Erlang VM. Its syntax was inspired by Clojure but the creators weren't interested in implementing all of Clojure's features.

Aren't the language constructs for concurrency very different between Clojure and Erlang?

Yes, they are. On one hand Clojure provides tools to handle mutable state in a sane way, while making a clear distinction between identity and state through reference types. On the other, concurrency in the Erlang VM is implemented through processes and message passing. The idea in Clojerl is to encourage the Erlang/OTP concurrency model, but support as many Clojure constructs as possible and as far as they make sense in the Erlang VM.

But... but... Rich Hickey lists here some of the reasons why he chose not to use the actor model in Clojure.

That is not a question, but I see what you mean :). The points he makes are of course very good. For example, when no state is shared between processes there is some communication overhead, but this isolation is also an advantage under a lot of circumstances. He also mentions here that building for the distributed case (a.k.a processes and message passing) is more complex and not always necessary, so he decided to optimise for the non-distributed case and add distribution to the parts of the system that need it. Rich Hickey calls Erlang "quite impressive", so my interpretation of these writings is that they are more about exposing the rationale behind the decisions and the trade-offs he made when designing Clojure (on the JVM), than about disregarding the actor model.

Will Clojerl support every single Clojure feature?

No. Some of Clojure's features are implemented by relying on the underlying mutability of the JVM and its object system. The Erlang VM provides very few mutability constructs and no support for defining new types. This makes it very hard or nearly impossible to port some features into Clojerl's implementation.

Can I reuse existing Clojure(Script) libraries?

Yes, but they will need to be ported, just like for ClojureScript. In fact, most of Clojure's core namespaces were ported from the original .clj files in the Clojure JVM repository.

Discussion

Join the conversation in the Clojerl mailing list or in the #clojerl Slack channel!

You can also find news and updates through @clojerl. Or if you have any questions you can find me @jfacorro or lurking on Clojure's and Erlang's mailing lists.

Any feedback, comment and/or suggestion is welcome!

doodler's People

Contributors

jfacorro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

arpunk stjordanis

doodler's Issues

Text related core functions

  • available-fonts - "A sequence of strings representing the fonts on this system available for use"
  • create-font - "Dynamically converts a font to the format used by Processing (a PFont) from either a font name that's installed on the computer, or from a "
  • font-available? - "Returns true if font (specified as a string) is available on this system, false otherwise"
  • horizontal-alignment-modes
  • load-font - "Loads a font into a variable of type PFont"
  • text - "Draws text to the screen in the position specified by the x and y parameters and the optional z parameter"
  • text-align - "Sets the current alignment for drawing text"
  • text-ascent - "Returns the ascent of the current font at its current size"
  • text-char - "Draws a char to the screen in the specified position"
  • text-descent - "Returns descent of the current font at its current size"
  • text-font - "Sets the current font that will be drawn with the text function"
  • text-leading - "Sets the spacing between lines of text in units of pixels"
  • text-mode - "Sets the way text draws to the screen - available modes are :model and :shape In the default configuration (the :model mode), it's possible to rotate, scale, and place letters in two and three dimensional space"
  • text-num - "Draws a number to the screen in the specified position"
  • text-size - "Sets the current font size"
  • text-width - "Calculates and returns the width of any text string"
  • vertical-alignment-modes

Safe funs

Don't crash when one of the callback function generates an error.

Transformation related core functions

  • apply-matrix - "Multiplies the current matrix by the one specified through the parameters"
  • pop-matrix - "Pops the current transformation matrix off the matrix stack"
  • print-matrix - "Prints the current matrix to std out"
  • push-matrix - "Pushes the current transformation matrix onto the matrix stack"
  • reset-matrix - "Replaces the current matrix with the identity matrix"
  • rotate - "Rotates a shape the amount specified by the angle parameter"
  • rotate-x - "Rotates a shape around the x-axis the amount specified by the angle parameter"
  • rotate-y - "Rotates a shape around the y-axis the amount specified by the angle parameter"
  • rotate-z - "Rotates a shape around the z-axis the amount specified by the angle parameter"
  • scale - "Increases or decreases the size of a shape by expanding and contracting vertices"
  • shear-x - "Shears a shape around the x-axis the amount specified by the angle parameter"
  • shear-y - "Shears a shape around the y-axis the amount specified by the angle parameter"
  • translate - "Specifies an amount to displace objects within the display window"
  • with-rotation - "Performs body with rotation, restores current transformation on exit"
  • with-translation - "Performs body with translation, restores current transformation on exit"

Shape related core functions

  • begin-contour - "Use the begin-contour and end-contour function to create negative shapes within shapes" ๐ŸŸฅ
  • begin-shape - "Enables the creation of complex forms"
  • end-contour - "Use the begin-contour and end-contour function to create negative shapes within shapes" ๐ŸŸฅ
  • end-shape - "May only be called after begin-shape"
  • load-shape - "Load a geometry from a file as a PShape"
  • shape - "Displays shapes to the screen"
  • shape-mode - "Modifies the location from which shapes draw"
  • shape-modes
  • vertex - "All shapes are constructed by connecting a series of vertices"

Generate ticks instead of a constant timer

The current usage of timer/send_interval causes a built up of messages, which interferes with the event handling and make the frame unresponsive. A better approach would probably be sending a single tick with erlang/send_after which will interleave event messages and tick messages.

Data conversion related code functions

  • binary - "Returns a string representing the binary value of an int, char or byte"
  • hex - "Converts a byte, char, int, or color to a String containing the equivalent hexadecimal notation"
  • unhex - "Converts a String representation of a hexadecimal number to its equivalent integer value"
  • unbinary - "Unpack a binary string to an integer"

Actual frame rate always lower than target

The calculation of the delay for the next refresh doesn't take into account the interval betweem the call to wxWindow/refresh and the actual paint event being handled.

Missing core functions

  • DEG-TO-RAD
  • HALF-PI
  • PI
  • QUARTER-PI
  • RAD-TO-DEG
  • THIRD-PI
  • TWO-PI
  • abs - "Calculates the absolute value (magnitude) of a number"
  • acos - "The inverse of cos, returns the arc cosine of a value"
  • arc - "Draws an arc in the display window"
  • asin - "The inverse of sin, returns the arc sine of a value"
  • atan - "The inverse of tan, returns the arc tangent of a value"
  • atan2 - "Calculates the angle (in radians) from a specified point to the coordinate origin as measured from the positive x-axis"
  • begin-raw - "Enables the creation of vectors from 3D data"
  • box - "Creates an extruded rectangle"
  • camera - "Sets the position of the camera through setting the eye position, the center of the scene, and which axis is facing upward"
  • ceil - "Calculates the closest int value that is greater than or equal to the value of the parameter"
  • clip - "Limits the rendering to the boundaries of a rectangle defined by the parameters"
  • constrain - "Constrains a value to not exceed a maximum and minimum value"
  • cos - "Calculates the cosine of an angle"
  • current-fill - "Return the current fill color"
  • current-frame-rate - "Returns the current framerate"
  • current-stroke - "Return the current stroke color"
  • day - "Get the current day of the month (1 through 31)"
  • debug - "Prints msg and then sleeps the current thread for delay-ms"
  • defsketch - "Define and start a sketch and bind it to a var with the symbol app-name"
  • degrees - "Converts a radian measurement to its corresponding value in degrees"
  • display-density - "This function returns the number 2 if the screen is a high-density screen (called a Retina display on OS X or high-dpi on Windows and Linux) and a 1 if not"
  • dist - "Calculates the distance between two points"
  • do-record - "Macro for drawing on graphics which saves result in the file at the end"
  • ellipse - "Draws an ellipse (oval) in the display window"
  • ellipse-mode - "Modifies the origin of the ellispse according to the specified mode: :center - specifies the location of the ellipse as the center of the shape"
  • end-raw - "Complement to begin-raw; they must always be used together"
  • exp - "Returns Euler's number e (2"
  • fill - "Sets the color used to fill shapes"
  • floor - "Calculates the closest int value that is less than or equal to the value of the parameter"
  • focused - "Returns a boolean value representing whether the applet has focus"
  • frame-count - "The system variable frameCount contains the number of frames displayed since the program started"
  • frame-rate - "Specifies a new target framerate (number of frames to be displayed every second)"
  • frustum - "Sets a perspective matrix defined through the parameters"
  • green - "Extracts the green value from a color, scaled to match current color-mode"
  • height - "Height of the display window"
  • hint - "Set various hints and hacks for the renderer"
  • hint-options
  • hour - "Returns the current hour as a value from 0 - 23"
  • hue - "Extracts the hue value from a color"
  • key-as-keyword - "Returns a keyword representing the currently pressed key"
  • key-code - "The variable keyCode is used to detect special keys such as the UP, DOWN, LEFT, RIGHT arrow keys and ALT, CONTROL, SHIFT"
  • key-coded? - "Returns true if char c is a 'coded' char i"
  • key-modifiers - "Set of key modifiers that were pressed when event happened"
  • key-pressed? - "true if any key is currently pressed, false otherwise"
  • lerp - "Calculates a number between two numbers at a specific increment"
  • lerp-color - "Calculates a color or colors between two color at a specific increment"
  • line - "Draws a line (a direct path between two points) to the screen"
  • log - "Calculates the natural logarithm (the base-e logarithm) of a number"
  • looping? - "Returns whether the sketch is looping"
  • mag - "Calculates the magnitude (or length) of a vector"
  • map-range - "Re-maps a number from one range to another"
  • millis - "Returns the number of milliseconds (thousandths of a second) since starting the sketch"
  • minute - "Returns the current minute as a value from 0 - 59"
  • month - "Returns the current month as a value from 1 - 12"
  • mouse-button - "The value of the system variable mouseButton is either :left, :right, or :center depending on which button is pressed"
  • mouse-pressed? - "Variable storing if a mouse button is pressed"
  • mouse-x - "Current horizontal coordinate of the mouse"
  • mouse-y - "Current vertical coordinate of the mouse"
  • no-clip - "Disables the clipping previously started by the clip() function"
  • no-fill - "Disables filling geometry"
  • no-smooth - "Draws all geometry with jagged (aliased) edges"
  • no-stroke - "Disables drawing the stroke (outline)"
  • noise - "Returns the Perlin noise value at specified coordinates"
  • noise-detail - "Adjusts the character and level of detail produced by the Perlin noise function"
  • noise-seed - "Sets the seed value for noise"
  • norm - "Normalize a value to exist between 0 and 1 (inclusive)"
  • ortho - "Sets an orthographic projection and defines a parallel clipping volume"
  • perspective - "Sets a perspective projection applying foreshortening, making distant objects appear smaller than closer ones"
  • pixel-density - "It makes it possible for Processing to render using all of the pixels on high resolutions screens like Apple Retina displays and Windows High-DPI displays"
  • pmouse-x - "Horizontal coordinate of the mouse in the previous frame"
  • pmouse-y - "Vertical coordinate of the mouse in the previous frame"
  • point - "Draws a point, a coordinate in space at the dimension of one pixel"
  • pow - "Facilitates exponential expressions"
  • print-camera - "Prints the current camera matrix to std out"
  • print-projection - "Prints the current projection matrix to std out"
  • quad - "A quad is a quadrilateral, a four sided polygon"
  • quadratic-vertex - "Specifies vertex coordinates for quadratic Bezier curves"
  • radians - "Converts a degree measurement to its corresponding value in radians"
  • random - "Generates random numbers"
  • random-2d - "Returns a new 2D unit vector with a random direction"
  • random-3d - "Returns a new 3D unit vector with a random direction"
  • random-gaussian - "Returns a float from a random series of numbers having a mean of 0 and standard deviation of 1"
  • random-seed - "Sets the seed value for random"
  • raw-key - "Contains the value of the most recent key on the keyboard that was used (either pressed or released)"
  • rect - "Draws a rectangle to the screen"
  • rect-mode - "Modifies the location from which rectangles draw"
  • resize-sketch - "Resizes sketch"
  • round - "Calculates the integer closest to the value parameter"
  • saturation - "Extracts the saturation value from a color"
  • screen-height - "Returns the height of the main screen in pixels"
  • screen-width - "Returns the width of the main screen in pixels"
  • seconds - "Returns the current second as a value from 0 - 59"
  • set-pixel - "Changes the color of any pixel in the display window"
  • set-state! - "Set sketch-specific state"
  • show-cats - "Print out a list of all the categories and subcategories, associated index nums and fn count (in parens)"
  • show-fns - "If given a number, print all the functions within category or subcategory specified by the category index (use show-cats to see a list of index nums)"
  • sin - "Calculates the sine of an angle"
  • sketch - "Create and start a new visualisation applet"
  • smooth - "Draws all geometry with smooth (anti-aliased) edges"
  • sphere - "Generates a hollow ball made from tessellated triangles"
  • sphere-detail - "Controls the detail used to render a sphere by adjusting the number of vertices of the sphere mesh"
  • sq - "Squares a number (multiplies a number by itself)"
  • sqrt - "Calculates the square root of a number"
  • state - "Retrieve sketch-specific state by key"
  • state-atom - "Retrieve sketch-specific state-atom" ๐ŸŸฅ
    The state is not kept in an atom.
  • stroke - "Sets the color used to draw lines and borders around shapes"
  • stroke-cap - "Sets the style for rendering line endings"
  • stroke-join - "Sets the style of the joints which connect line segments"
  • stroke-weight - "Sets the width of the stroke used for lines, points, and the border around shapes"
  • tan - "Calculates the ratio of the sine and cosine of an angle"
  • target-frame-rate - "Returns the target framerate specified with the fn frame-rate"
  • triangle - "A triangle is a plane created by connecting three points"
  • width - "Width of the display window"
  • with-fill - "Temporarily set the fill color for the body of this macro"
  • with-stroke - "Temporarily set the stroke color for the body of this macro"
  • year - "Returns the current year as an integer (2003, 2004, 2005, etc)"

Color

  • alpha - Extracts the alpha value from a color
  • background - Sets the color used for the background of the Processing
  • background-image - Specify an image to be used as the background for a sketch
  • blend-color - Blends two color values together based on the blending mode given specified
  • blue - Extracts the blue value from a color, scaled to match current color-mode
  • brightness - Extracts the brightness value from a color
  • clear - Clears the pixels within a buffer
  • color - Creates an integer representation of a color
  • color-mode - Changes the way Processing interprets color data
  • current-fill - Return the current fill color
  • current-stroke - Return the current stroke color
  • fill - Sets the color used to fill shapes
  • green - Extracts the green value from a color, scaled to match current
  • hue - Extracts the hue value from a color
  • lerp-color - Calculates a color or colors between two color at a specific
  • no-fill - Disables filling geometry
  • no-stroke - Disables drawing the stroke (outline)
  • red - Extracts the red value from a color, scaled to match the current
  • saturation - Extracts the saturation value from a color
  • stroke - Sets the color used to draw lines and borders around shapes
  • with-fill - Temporarily set the fill color for the body of this macro
  • with-stroke - Temporarily set the stroke color for the body of this macro

Structure

  • delay-frame - Forces the program to stop running for a specified time
  • exit - Quits/stops/exits the program
  • no-loop - Stops Processing from continuously executing the code within
  • pop-style - Restores the prior settings on the 'style stack'
  • push-style - Saves the current style settings onto a 'style stack'
  • redraw - Executes the code within the draw function one time (or n times in cljs)
  • start-loop - Causes Processing to continuously execute the code within

Performance issue when increasing canvas size

The bigger the image size drawn in the canvas during the paint event, the lower the frame rate.

This doesn't look like it's caused by drawing the image in the wxPaintDC for the
canvas but something else.

The slowdown is related to the drawing of the bitmap, when commenting it out and printing the frame-rate we would get, the number shows a considerable improvement.

Performance issue with brush, pen and background operations

When synchronous calls are used inside the draw function, the frame rate drops
considerably. Things like getting the canvas' brush/pen, or even creating a
new brush/pen are synchronous operations, which means that when changing the color
of the current brush we should avoid creating a new brush/pen or fetching the
exisiting one.

A possible workaround would be to keep a copy of both pen & brush and just calling
setColour function (which is async).

Image related core functions

  • background-image - "Specify an image to be used as the background for a sketch"
  • blend - "Blends a region of pixels from one image into another with full alpha channel support"
  • blend-color - "Blends two color values together based on the blending mode given specified with the mode keyword"
  • blend-mode - "Blends the pixels in the display window according to the defined mode"
  • blend-modes
  • copy - "Copies a region of pixels from the one image to another"
  • create-image - "Creates a new PImage (the datatype for storing images)"
  • display-filter - "Originally named filter in Processing Language"
  • filter-modes
  • get-pixel - "Reads the color of any pixel or grabs a section of an image"
  • image - "Displays images to the screen"
  • image-filter - "Originally named filter in Processing Language"
  • image-formats
  • image-mode - "Modifies the location from which images draw"
  • image-modes
  • load-image - "Loads an image into a variable of type PImage"
  • mask-image - "Masks part of an image from displaying by loading another image and using it as an alpha channel"
  • no-tint - "Removes the current fill value for displaying images and reverts to displaying images with their original hues"
  • pixels - "Array containing the values for all the pixels in the display window or image"
  • request-image - "This function load images on a separate thread so that your sketch does not freeze while images load during setup"
  • resize - "Resize the image to a new width and height"
  • save - "Saves an image from the display window"
  • save-frame - "Saves an image identical to the current display window as a file"
  • set-image - "Writes an image directly into the display window"
  • tint - "Sets the fill value for displaying images"
  • update-pixels - "Updates the display window or image with the data in the pixels array"

Light related core functions

  • ambient - "Sets the ambient reflectance for shapes drawn to the screen"
  • ambient-light - "Adds an ambient light"
  • directional-light - "Adds a directional light"
  • emissive - "Sets the emissive color of the material used for drawing shapes drawn to the screen"
  • light-falloff - "Sets the falloff rates for point lights, spot lights, and ambient lights"
  • light-specular - "Sets the specular color for lights"
  • lights - "Sets the default ambient light, directional light, falloff, and specular values"
  • no-lights - "Disable all lighting"
  • point-light - "Adds a point light"
  • shininess - "Sets the amount of gloss in the surface of shapes"
  • specular - "Sets the specular color of the materials used for shapes drawn to the screen, which sets the color of hightlights"
  • spot-light - "Adds a spot light"

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.