How to convert a CLOS program to COALTON.
devosalain opened this issue · comments
I want to change this program to coalton :
(load "~/quicklisp/setup.lisp")
(declaim (optimize (speed 3) (safety 3) (space 0) (debug 3)))
(ql:quickload "serapeum")
(defpackage mypack
(:use :cl :serapeum)
(:export main));defpackage
(in-package :mypack)
(defclass bank-account ()
(customer-name balance))
(defgeneric balance (dummy))
(defgeneric customer-name (dummy))
(-> customer-name (bank-account) String)
(defmethod customer-name ((account bank-account))
(slot-value account 'customer-name))
(-> balance (bank-account) Integer)
(defmethod balance ((account bank-account))
(slot-value account 'balance))
(-> (setf customer-name) (String bank-account) nil)
(defmethod (setf customer-name) (aname account)
(setf ( slot-value account 'customer-name ) aname))
(-> (setf balance) (Integer bank-account) nil)
(defmethod (setf balance) (abal account)
(setf ( slot-value account 'balance ) abal))
(defparameter *account* (make-instance 'bank-account))
(-> main () integer )
(defun main ()
(setf (customer-name *account*) "Alain")
(setf (balance *account*) 100)
(print (customer-name *account*))
(print (balance *account*))
0)
(in-package :cl)
(defun main ()
(mypack::main)
0 )
(sb-ext:save-lisp-and-die "test.exe" :toplevel #'main :executable t)
If you need to be able to access the objects from outside of Coalton, define them in Lisp first and then import the type to Coalton
(Defclass bank-account...
(Coalton-toplevel
(Repr :native bank-account)
(Define-type BankAccount))
If you just want it all in Coalton, use define-struct to make similar objects:
(Coalton-toplevel
(Define-struct BankAccount
(Customer-name String)
(Acct-number UFix)))
Unless you're going to have multiple structs using the same methods, you can just use regular function definitions. If you do want multiple structs/types using the same functions, use define-class to define a typeclass
There exist a book "The book of Shen".
It would be nice if someone could write "The book of Coalton". As i'm missing alot.