Hacker News new | past | comments | ask | show | jobs | submit login
A Cosmac1802 Emulator in 300 Lines of Common Lisp (github.com/rongarret)
42 points by lisper on April 21, 2019 | hide | past | favorite | 7 comments



This is very neat and a true piece of Lisp history!

Folks unfamiliar with Common Lisp should know that this style of Common Lisp is quite eclectic. It’s very, very terse and avoids directly using standard CL functionality like CLOS. The DEFINE-CLASS and DEFINE-METHOD aren’t “standard”, you won’t be able to find their definition in Lisp’s specification. (They probably wrote their own little OO system appropriate for the application domain.)

I contend that using the same old Lisp, this code could be written much more readably, without sacrificing efficiency (not that you need extreme efficiency to emulate such a tiny instrument). This would be done by way of using the standard CLOS functionality, using appropriate names (e.g., DUMP-MEMORY instead of DM), adding doc strings, and avoiding abbreviation (e.g., the MACROLET at the end).


DEFINE-CLASS and DEFINE-METHOD are very thin wrappers over DEFCLASS and DEFMETHOD. Rewriting the code using standard CL would not make it substantially longer. All those macros really do is rearrange the parens (because I can never remember where the parens go in the standard versions).

DM is called DM rather than DUMP-MEMORY because it was used for debugging and typing DM over and over was a lot less annoying than typing DUMP-MEMORY.

As for the use of MACROLET, there is nothing non-standard or unconventional about it.

The definitions of DEFINE-CLASS and DEFINE-MACRO, along with documentation (and a whole bunch of other stuff) can be found here:

https://github.com/rongarret/ergolib

Specifically:

https://github.com/rongarret/ergolib/blob/master/core/ergocl...


To be clear, I am not saying any of the decisions were irrational. As a CL programmer myself, I could read it just fine. But things like “thin wrappers” and abbreviations to accommodate personal taste lead to an eclectic and unidiomatic style.


CL itself is rather eclectic, so I guess I'll take that as a compliment :-)


The OO system looks like a few macro wrappers over CLOS.


Yes, that's exactly what it is. The modern descendant of this code, with documentation, can be found here:

https://github.com/rongarret/ergolib

though the CLOS wrapper is essentially unchanged from 1993.


(A development tool for patching around the failure in Galileo space probe magnetometer instrument)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: