🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

I should have just written a Lisp clone...

Published March 06, 2009
Advertisement
The big project of the day is adding support for anonymous lists. The concept is very simple: for certain functions, it makes sense to send them a list of parameters to operate on. For example, the add function and the boolean or function both can combine multiple parameters.

In order to pass the parameters to the functions, you must first construct an anonymous list on the stack. This is easier than it sounds:

assign(foo, add(list(40, 1, 1, -7, 5, 2)))

The internal add function is overloaded to accept either 2 operands, or a list. In the list case, all the values are summed up and the result is returned. This is a vast improvement over the old syntax:

assign(foo, add(add(add(add(add(40, 1), 1), -7), 5), 2))

Right now I'm in the middle of cleaning up and refactoring the list support implementation, so only a couple of builtin functions can use the list syntax at the moment. My goal for the night is to get all the appropriate functions to support lists.


Assuming that goes well, I should be set to start working on the multiprocessing stuff over the weekend.

0 likes 2 comments

Comments

Telastyn
Do you really mean list, or can that be extended/modified to use tuples?
Why go add list rather than fold/coalesce/aggregate style function that takes a list and a function?
March 07, 2009 12:34 AM
ApochPiQ
Yep, it's a list - all elements must be of the same type. This makes things a bit simpler to implement, especially from a type checking standpoint (i.e. when the list is consed up I just ensure all elements are the same type, and when a function is passed a list, it only has to check one element's type to know if it is correct).

Tuples, while they are supported, have a minimum amount of usefulness at the moment. To be honest I haven't done a whole lot of serious programming in languages that have good tuple support, so I'm not even sure what kind of features would be desirable.


As for map/fold type functions - I definitely intend to get these implemented at some point. I see the current syntax (and its implementation) as a stepping stone to a proper map/fold system. In other words, since I have the concept of lists implemented, and the concept of higher order functions is already available, it should take a minimal amount of work to add the state tracking that is necessary for a map or a fold.
March 07, 2009 09:28 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement