The Hobbit Hole

In a hole there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with nothing in it to sit down on or to eat: it was a hobbit-hole, and that means comfort.

4/28/2010

Theory Proven Incorrect

Filed under: Programming — bilbo @ 10:49 pm

One of my reasons for writing a scheme interpreter/compiler is that I have always thought Scheme would be a good foundation for building a universal dynamic language environment. It seems that this was also a goal of Guile, the GNU extension language. I can (obviously) see the appeal.

Theory proven incorrect aside, I will say my goals are a trifle different. I’m not looking to port existing languages, at least not identically. I don’t think I would have had such hubris. Instead, I’m trying to create a language development environment. I think Scheme provides a great base, or more precisely, any VM that can support a Scheme has the necessary primitives to support just about any dynamic language. So there is my hubris :) .

I believe that a Scheme is the ideal environment for trying dynamic language ideas for a couple of reasons:
1) The syntax of Scheme is similar to an abstract syntax tree. Parsers simply have to create a scheme equivalent and run (print (eval (read))).
2) Add primitives in Scheme. When a dynamic language needs a new primitive, it can easily do so by creating a scheme function or macro.

After getting this project up and running to a 1.0 state, I plan on writing a BASIC interpreter for it to provide a prototype.

1/6/2010

God Wrote in Lisp

Filed under: Programming — bilbo @ 10:15 am

I came across this in an RSS feed, a song about God’s choice of tools when creating the universe. Excellent!

Tags: , ,

10/1/2009

Testing Unit Testing

Filed under: Games,Programming — bilbo @ 8:02 pm

As I’ve been working on my compiler, I’ve been writing tests for each feature as it becomes available. There’s been a couple of times I’ve broken the parser while adding data type support to it. Thankfully the tests found that out as soon as I was done compiling, and I didn’t have to try and figure it out weeks later when I returned to the project. (I only get so much time to work on this project, and it’s often weeks in between times I can put significant effort in.) Thanks to these simple tests, I have been able to maintain functionality.

However, those tests really are just small executables that have asserts. They’re not bad, but after using NUnit for another project, I am thinking I want something more formal. However, I want to write tests quickly and not have to support a lot of infrastructure. I’ve been doing some research on C++ unit testing frameworks. There sure are a lot of them.

I’ve think I’ve narrowed my choice down to two: TUT looks promising, as does UnitTest++. I like TUT because it is headers only. It seems a little obtuse since it uses so many templates, but I’m not one to shy away from templates. I like UnitTest++ since it professes so much cross platform support.

Another one, cput looks like NUnit does, and is even integrated into Visual C++, but I’m looking more for simple than integrated right now. Maybe later when the compiler is further along. Then again, multi-platform is of prime importance, so maybe this one won’t be that useful to me after all.

Do you know of any good C++ testing frameworks that I should look at?

9/4/2009

Essential Scheme

Filed under: Programming — bilbo @ 1:25 pm

For those who are involved, the process for R7RS has begun again. The R6RS standard didn’t leave many happy, so of course there is already heated debate starting on this standard.

One area that was readily agreed on is that Scheme needs to be split into 2 languages, a small language for academic purposes, a larger language for commercial/industrial programming.

There have been several threads going on about the different features that should be included, or excluded, from the small scheme. I thought about what was needed to be essential to a dialect for it to be considered scheme. As I was pondering this, a message from David Horn appeared on the r6rs-discuss mailing list that attempts to do what I was thinking of. I’ve reprinted it here for my own convenience, with formatting changes.

Essential Scheme is the minimal subset of the language expected to be supported by any Scheme system. It represents the fundamental and simple core of the language. It is lightweight at the semantic and implementation level. It is useful for research, prototyping, language experimentation, and understanding existing teaching materials. Its specification is comparable in size to research paper accounts of Scheme (i.e. much smaller than even R3RS).

Core
<variable>
(quote <datum>)
‘<datum>
<constant>
(<operator> <operand1> …)
(lambda <formals> <body>)
[includes dot patterns, body is sequence of one or more expressions.]
(if <test> <consequent> <alternate>)
(set! <variable> <expression>)

Derived
(cond <clause1> <clause2> …)
(let <bindings> <body>)
(letrec <bindings> <body>)
(begin <expression1> <expression2> …)

Programs
(define <variable> <expression>) …

Procedures

Booleans
(not obj)
(boolean? obj)

Equivalence predicates
(eqv? obj1 obj2)
(eq? obj1 obj2)
(equal? obj1 obj2)

Pairs and Lists
(pair? obj)
(cons obj1 obj2)
(car pair)
(cdr pair) ; and caar…cddddr
(null? obj
(list obj …)
(length list)
(append list1 list2)

Symbols
(symbol? obj)
(symbol->string symbol)
(string->symbol string)

Numbers
(number? obj) ;; Full tower is optional
(complex? obj)
(real? obj)
(rational? obj)
(integer? obj)
(zero? z)
(positive? x)
(negative? x)
(odd? n)
(even? n)
(exact? z)
(inexact? z)
(= z1 z2)
(< x1 x2)
(> x1 x2)
(< = x1 x2)
(>= x1 x2)
(max x1 x2)
(min x1 x2)
(+ z1 z2)
(* z1 z2)
(- z1 z2)
(/ z1 z2)
(abs z)
(quotient n1 n2)
(remainder n1 n2)

Characters
(char? obj)
(char=? char1 char2)
(char< ? char1 char2)
(char>? char1 char2)
(char< =? char1 char2)
(char>=? char1 char2)
(char->integer char)
(integer->char n)

Strings
(string? obj)
(string-length string)
(string-ref string k)
(string=? string1 string2)
(string< ? string1 string2)
(string>? string1 string2)
(string< =? string1 string2)
(string>=? string1 string2)
(substring string start end)
(string-append string1 string2)
(string->list string)
(list->string chars)

Vectors
(vector? obj)
(make-vector k)
(vector obj …)
(vector-length vector)
(vector-ref vector k)
(vector-set! vector k obj)
(vector->list vector)
(list->vector list)

Control features
(procedure? obj)
(apply proc args)
(map proc list)
(for-each proc list)
(call-with-current-continuation proc)

I’m not sure I agree with everything on the list, such as complex numbers being required for Scheme. Also, there doesn’t seem to be any provision for macros, so I would at least add defmacro. I won’t try to debate the merits of hygienic macros vs. lisp macros here, but I feel that defmacro would be easier to implement and to be more versatile, as things that are unrestricted generally are. Besides, hygienic macros can be implemented via defmacro.

Tags: ,