[erlang-questions] Trying to learn the Erlang Way

Richard A. O'Keefe <>
Wed Feb 12 01:06:27 CET 2014

Perhaps the most important piece of advice I can give
you is that there is an existing Erlang program you
might find useful:  Wings3D.

Quoting http://www.wings3d.com

	Wings 3D is an advanced subdivision modeler
	that is both powerful and easy to use.

	Wings 3D offers a wide range of modeling tools,
	a customizable interface, support for lights
	and materials, and a built-in AutoUV mapping facility.

	There is no support in Wings for animation.

	Wings 3D is written in Erlang, an open source,
	functional programming language distributed by Ericsson.

It's actively maintained; release 1.5.2 came out in
November last year.  And it's open source.

> I appreciate your response and the effort you put into it. And I learned a lot from it. In this case I am learning the thinking mode of Erlang as it is different a bit from what I do to pay the bills. I have yet to get into list comprehensions in Erlang so that is on my ... well ... list. :) You have provided valuable insight.

In the simplest case, list comprehension is

	[ E1 || P <- E2, E3 ]

which says

	for every element of E2,
	    if that element matches P (binding any variables),
	        and E3 comes out true,
		    incorporate the value of E1 into
		    the list we're building.

Adding more "<-" parts gives you nested loops.
The notation is based on mathematical notation for sets:

	{ e | x ∈ s, f }

"the set of all e such that x is an element of s satisfying f".

Almost the only well known functional language that _doesn't_
have list comprehensions is SML.  
> The main focus of the method is if I have a number of objects with a vector position in a simulation and I want to exclude considerations of interactions with objects outside the sphere of influence, I have to quickly discard the candidates that are not inside the sphere of influence.

Then the collection of candidates needs to have some structure,
such as an oct-tree.  If you have the elements in a list, you
have to do *something* with every element just to reach the last

>  I originally thought to write a method that did just the vector math because I was wondering if that kind of math would have to ultimately be turned into something native.

With HiPE, you _get_ native code.
If you give it suitable declarations, such as

	-type pt3() :: {float(),float(),float()}.
	-spec dot(pt3(), pt3()) -> float.

	dot({X1,Y1,Z1}, {X2,Y2,Z2}) ->
	    X1*X2 + Y1*Y2 + Z1*Z2.

[NOT TESTED] you get _reasonable_ native code.

I think you probably want to get Wings3D and play with it for
a bit to get an idea of what _can_ be done in Erlang.

(What I found out is that I have no artistic talent whatsoever,
even _with_ a computer and a fancy tool.  Sigh.)

There's also http://sourceforge.net/projects/rosen/
which I just found out about.
"ROSEN means RObotic Simulation Erlang eNgine; it is a software library, written in Erlang, which simulates 3D environments and in particular autonomous mobile robots, each with its behaviour and interaction capabilities."
I have no idea how good it is, but there's probably something
there you can stealXXXXXlearn from.

More information about the erlang-questions mailing list