(car '(3))
Posted on by Idorobots
Finally. Good job, Lazy-me, keep it up! Or shall I say, 'keep it down', dohoho!
So we've seen latmab - the calculator and Scheme - RNoRS Scheme interpreter, both leading to the following, somewhat fun story... After having basics of Scheme implemented even though I did not have any previous Lisp experience, I figured I could do even better. Hell, let's actually learn some Lisp, said my inner smoking-hot stallion-programmer-guy! My journey started with this mans blog and his presentation about Lisp. I visited all kinds of lispy lands, from Scheme, which proved to be elegant and mind-blowing, going through Clojure, having all those Java goodies out of the box, all the way to another planet, simply called The Land of Lisp.
I've stopped there for quite some time and I loved every single minute spent there. That book is, well, unique. I'm sure there are plenty good programming books out there, but none is equally fun to read as Land of Lisp, but that's a story for another post. What's really important is that I still couldn't get 'the Lisp'. 'The Lisp' is often and by many called the most powerful and expressive language ever created, even #lisp
claims it to be the #1=(programmable . #1#)
language out there. Now that's A LOT. Especially for a language over half a century old. Is that so, I asked myself, what's so special about Lisp? It's a bunch of parentheses and symbols after all, but with time passing and more lispy lines coming from underneath my fingers I've begun to finally get it. The Lisp experience was, let's face it, awkwardly enjoyable and rewarding. All this new stuff, all the techniques I wouldn't normally consider or even know of, ALL THIS adorned with just a few lines of code, tight and delicious. After a few weeks with The Land of Lisp I came back to D, richer but not quite there yet... And it struck me. Suddenly I found myself using thunks, arrays of nullary delegates if you please, higher order programming and metaprogramming like a BADASS. It all made way more sence now, the OOP that was dimming my coders sence, was cured (implying it's a disease). I could see the problem from a totally different angle, instead of creating class Derp; here and class Herp; all over the place, as I usually did in C++ or Java, I could solve the problem equally elegantly, with no overhead for stuff like virtual calls and at least TWICE as fun. Those few weeks spent with LoL were more than a challenge for the mind, it truly did make me a better programmer in general. Needless to say, I still continue my journey across the lispy lands, and find it both challenging and rewarding as a mother-
Each day I find something new to admire and enjoy, I even gave Emacs another shot, and this time, thanks to a better understanding of Lisp I'm liking it and I'm fairly sure I'll stick with Emacs for good.
But where's the code!? This is a blog about coding, and this post belongs to a coding series, so... In fact I like Lisp so much I've started another project dedicated to Lisp, a continuation to the Scheme interpreter.
It's called Another Syntactic Monstrosity and it's a new lispy language for my own amusement. Check it out here. I'm writing from scratch, without any implementation to base on, and my main goal is to make Lisp even more expressive and comfortable without getting in its way. Here's a quick example of ASMy code:
## Hello ASM!
## Written in ASM programming language.
## NOTE: This snippet uses JavaScript syntax highlighting.
# Modules built into the language.
(import 'io)
# Lispy macros.
(macro function [name args body]
# Quasiquoting and various built-in collections.
`(var $name [$args $body]))
(function roll [dice]
# Semantic keywords (the ".2") changing basic language behaviour.
(if .2 (dice #is_a collection?)
# Expression comments that can be used to clarify the code.
#pick (random #from dice)
# Or debugging
#(.BUG do something else)))
# Lists,
(var d4 '[1 2 3 4])
# tuples,
(var d6 (range #from 1 #inclusive_to 7 #not_inclusive))
(var d20 (range 1 21))
# and sets,
(var dH '{"head" "leg" "lower body" "upper body" "arm"})
# all programmable and usable the way you like.
# Object oriented programming:
(class Orc {
(var name 'Orc)
(var HP 300)
(var AD d6)
})
(function hit [what] {
(var hitTest (roll d20))
(if (>= hitTest 15) {
(var damage (* 3 (roll d6)))
# Generic setter.
(set! (what HP) (- (what HP) damage))
`(You hit the $(what name)
in the $(roll dH) for $damage damage!)
}
#else `(You miss the $(what name) !))
})
(function attack [what]
# Functional and higher order function programming.
(map [[arg] ((io write) arg " ")]
(hit what)))
# And finally delicious simplicity...
(var orc ((Orc new)))
(attack orc)
# You hit the Orc in the head for 9 damage!
Hopefully, I'll find some more time and willingness to finally finish ASM section of this site. I will also publish a bunch of code-rich posts, about the interpreter and the language, some time in the future.
2016-02-20: Adjusted some links & tags.