https://github.com/fitzgen/protolith
Just for exploratory fun, I decided to see what it takes to write a prototypical object system in Lisp.
https://github.com/fitzgen/protolith
Last synced: 6 months ago
JSON representation
Just for exploratory fun, I decided to see what it takes to write a prototypical object system in Lisp.
- Host: GitHub
- URL: https://github.com/fitzgen/protolith
- Owner: fitzgen
- Created: 2010-01-29T03:51:42.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2010-01-29T03:59:00.000Z (over 16 years ago)
- Last Synced: 2025-10-29T00:46:10.511Z (8 months ago)
- Language: Common Lisp
- Homepage: http://fitzgeraldnick.com/weblog/
- Size: 74.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Just for exploratory fun, I decided to see what it takes to write a prototypical
object system in Lisp. Apparently its not much, I'm far from an experienced
Lisper (barely fluent, if that) and I got it done in ~50 lines. A testament to
Lisp's flexibility and expressiveness.
CL-USER> (load "/home/fitzgen/dev/protolith/protolith.lisp")
T
CL-USER> (in-package :protolith)
#
PROTOLITH> (defobj account ()
(bal 0)
(deposit (lambda (self x)
(funcall self 'set 'bal (+ (funcall self 'bal)
x)))))
ACCOUNT
PROTOLITH> (account 'bal)
0
PROTOLITH> (account 'deposit 50)
50
PROTOLITH> (account 'bal)
50
PROTOLITH> (defobj checking-account (account)
(withdraw (lambda (self x)
(progn
(funcall self 'set 'bal (- (funcall self 'bal)
x))
x))))
CHECKING-ACCOUNT
PROTOLITH> (checking-account 'bal)
50
PROTOLITH> (checking-account 'withdraw 10)
10
PROTOLITH> (checking-account 'withdraw 10)
10
PROTOLITH> (checking-account 'bal)
30
PROTOLITH> (checking-account 'proto)
#