
Raytracer.el: a raytracer in Emacs Lisp - kruhft
https://github.com/burtonsamograd/emacs-jit/blob/master/lisp/raytracer.el
======
Cieplak
Another neat pair of raytacers that shows the performance boost from
vectorization:

[http://www.excamera.com/sphinx/article-
ray.html](http://www.excamera.com/sphinx/article-ray.html)

~~~
kruhft
I've also written a GPU tracer using the same style of calculation, and it
just blows anything done on the CPU out of the water. It gets about 10fps with
100 spheres on a mid range Mac Pro.

------
Annatar
That code is so beatiful: clear, easily understandable. I don't think I've
ever seen any C++ code which even comes close to this in readability. And it
_just flows_.

Really, LISP gets way too little credit (and use) than it deserves.

~~~
kahrkunne
Lisp gets nothing but loving praise from most people who've really looked into
it. To me, it's a really good indicator of someone's quality as a programmer -
someone who treats programming as just a job will probably never run into it
in any meaningful way, but a true hacker will eventually encounter it and be
able to appreciate its elegance.

Wanting something like lisp to gain mainstream popularity would be a naive
wish - your average web developer wouldn't be able to appreciate it, and over
time lisp would change to become more like PhP. No offense meant to such
people of course, not everyone needs to have that kind of passion, and
_someone_ needs to do web development - God knows it won't be me!

~~~
Nekorosu
> over time lisp would change to become more like PhP.

A lot of things are so wrong in this statement.

First of all, PHP isn't bad. Don't get me wrong I don't like it (I also don't
like Go but that's another story) but it has become so much better. Several of
my colleagues use it (that's not the only language they use though) and
believe me they are quite passionate about programming. Actually there is some
zen in being able to use any tool life throws at you to solve some practical
problems.

Second, you are comparing family of languages to the one particular language.
This doesn't do justice to both.

Third, if the comparison with PHP was another way to say that Lisp would
become worse then here is another thought. It won't. Every mainstream language
I know is becoming better in a sense of better defaults and FP features. Java
has got lambdas. JS ES6 is going to have TCO and strict mode which fixes a lot
of old vague behaviour. Yes, there are a lot of crazy stuff in those languages
because their features weren't well thought out back in the day and now it's
impossible to fix everything without breaking the core semantics and
behaviour. Basically you can fix some things but you can't evolve one language
into another.

Getting back to Lisp now. It doesn't need fixing. It has very basic and clear
core which doesn't need to be fixed and a lot of advanced language features
can be built upon it (and actually was built and are being built). Taking in
account both that languages are becoming better with time and that Lisp has
awesome core I don't see at all how's popularity can make it worse.

I'd suggest reading some PLT books or taking some related courses. It helps to
get the whole picture. You won't love Lisp less (probably the opposite) but
you'll accept other languages more. :)

I have to add I'd prefer something Lispish over anything else any day of the
week. I'm looking into Clojure(ClojureScript). It's not as elegant as original
Lisps and Schemes but it's tradeoffs come from real world use cases (running
on top of JVM and JS). Even with them it's an awesome language.

~~~
kahrkunne
You're putting words in my mouth. I never said PHP was bad - it's reasonably
good for common use cases on the web.

I'm just saying that if hypothetically lisp became super popular, it would
inevitably change to fit the work flow of the mainstream. Maybe not directly
(i.e. through the spec changing) but definitely indirectly, through changes in
common practice, libraries etcetera, as well as the general culture of
relatively CS-literate, experienced hackers surrounding it.

Of course, I'm not worried about this happening - what's happening instead is
that lisp features are finding their way into other languages (a process that
has been going on since the 70s).

~~~
Annatar
_I 'm just saying that if hypothetically lisp became super popular, it would
inevitably change to fit the work flow of the mainstream._

Being a functional language designed for _metaprogramming_ , it is _expected_
that it be extended: just by defining a new function, one defines LISP on the
fly. That's the core idea of LISP! (:-))

------
agumonkey
If authors adds a lazy DAG transformation on eval and an ASCII dithered
output, you could drop Autodesk Maya for Emacs.

~~~
kruhft
I get the ACSII part, but what would be the purpose/intent of the 'lazy DAG
transformation on eval'?

~~~
agumonkey
Semi-live re-rendering avoiding too much recomputation.

------
ginko
How do I run this? Opening raytracer.el and doing M-x eval-buffer doesn't seem
to work. Guess my Emacs 24.3.1 is too old..

EDIT: Ah, I see. You need emacs-jit from the parent project.

~~~
kruhft
It's built to test the JIT but shouldn't depend on it.

To run:

    
    
        Open raytracer.el
        M-x eval-buffer
        M-: (ray-test 256)
    

Output will be in a buffer as well as in 'image.pbm'

~~~
mrkgnao
ray-test requires an argument.

~~~
kruhft
D'oh. Can't even read my own code this morning :) Thanks.

~~~
mrkgnao
It's fine :) How long is this supposed to take?

~~~
kruhft
At 256 I think about a minute or so...

------
molloy
Awesome project. While going over it to figure out how it worked, I looked up
the 'cl' package and noticed that it has been deprecated in favor of cl-lib.
[1] Also, what license (if any) does this fall under?

[1]
[https://www.emacswiki.org/emacs/CommonLispForEmacs](https://www.emacswiki.org/emacs/CommonLispForEmacs)

~~~
kencausey
I'm assuming you are asking what license cl-lib falls under.

From the top of cl-lib.el in Emacs 25.1:

    
    
      ;;; cl-lib.el --- Common Lisp extensions for Emacs  -*- lexical-binding: t -*-
      
      ;; Copyright (C) 1993, 2001-2016 Free Software Foundation, Inc.
      
      ;; Author: Dave Gillespie <daveg@synaptics.com>
      ;; Version: 1.0
      ;; Keywords: extensions
      
      ;; This file is part of GNU Emacs.
      
      ;; GNU Emacs is free software: you can redistribute it and/or modify
      ;; it under the terms of the GNU General Public License as published by
      ;; the Free Software Foundation, either version 3 of the License, or
      ;; (at your option) any later version.
      
      ;; GNU Emacs is distributed in the hope that it will be useful,
      ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
      ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      ;; GNU General Public License for more details.
      
      ;; You should have received a copy of the GNU General Public License
      ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.

~~~
molloy
Oh no, I meant raytracer.el. Would it fall under the GPL by default? (Does
running raytracer.el within GNU Emacs count as extending it?)

~~~
kencausey
Sorry, here is the license for the project:

[https://github.com/burtonsamograd/emacs-
jit/blob/master/COPY...](https://github.com/burtonsamograd/emacs-
jit/blob/master/COPYING) (GPL v3)

I see nothing else which overrides this but I could be mistaken.

~~~
molloy
Thanks!

------
melling
Here's some additional information on ray tracing:

[https://github.com/melling/ComputerGraphics/blob/master/ray_...](https://github.com/melling/ComputerGraphics/blob/master/ray_tracing.org)

------
pmoriarty
Now if we could only embed a flight simulator in to Emacs...

~~~
eggy
Maybe you can be inspired by the flight sim written in PicoLisp RcSim back in
1991, and still included with the PicoLisp distribution. [1]

    
    
      [1] http://picolisp.com/wiki/?rcsim

------
sclaxton
The whole "web developers can't be talented, passionate, _real_ programmers"
narrative is very myopic, tired, and just down right flawed. "Real programmer"
machismo, in general, has no place on HN or any community that thrives to be
productive and constructive.

~~~
kahrkunne
You misunderstood me. Of course there's plenty of good web developers. It's
just that, in my opinion, the average programming language is less elegant
than Lisp, and the average programmer is less passionate than the average
Lisper.

This says nothing about individual programmers - there's just a lot of web
developers (that's why I picked PHP as an example, because in my mind it's the
standard example of a "mainstream language"), and many of them aren't
particularly passionate about programming, it's just a job to them (which is,
as I tried to point out, perfectly OK!). People who know Lisp, on the other
hand, are almost exclusively passionate about programming, because there's no
real reason to learn Lisp if you're not - it's not known to be particularly
employable.

I never tried to make a value judgement of web developers as a group, it was
just a matter of statistics. I'm sorry if that wasn't clear.

~~~
armitron
Your argument has merit, disregard the dissenters, just noise.

The same is true for other great languages. In my view, Erlang, FORTH,
Smalltalk. I've yet to meet anyone well-versed in these that didn't turn out
to be a good programmer. Moreover, this process is additive. I've met a few
people over the years who are well-versed in subsets of the languages I
mentioned, that turned out to be masters of the craft and helped me improve
tremendously either through them commenting on my work, or me examining their
output and their problem-solving approach. If I had one word to describe these
persons, it'd be Artists.

In close to 20 years in this domain, I've yet to meet a single person whose
primary expertise lies in {C, C++, Javascript, PHP, Java, C#, Python, Ruby},
that has triggered paradigm shifts in me that led to personal growth or re-
evaluating programming. If I had one word to describe these persons, it'd be
laborers. Of course the second group is also far larger than the first, and
includes all the hacks [1], primadonnas [2] and mediocrats [3] one would
expect.

[1] [http://www.morganstanley.com/profiles/bjarne-stroustrup-
mana...](http://www.morganstanley.com/profiles/bjarne-stroustrup-managing-
director-technology)

[2]
[https://en.wikipedia.org/wiki/James_Gosling](https://en.wikipedia.org/wiki/James_Gosling)

[3]
[https://en.wikipedia.org/wiki/Guido_van_Rossum](https://en.wikipedia.org/wiki/Guido_van_Rossum)

