Hi, Am 28.12.2008 um 09:13 schrieb TPJ:
So, it's impossible to use Clojure code to generate the following Java
class:
class MyClass
{
private int myIntField;
int getMyIntField() { return myIntField; }
void setMyIntField( int val ) { myIntField = val; }
}
This is perfectly possible, although not necessarily desirable.
(ns com.example.MyClass
(:gen-class
:state state
:init init
:methods [[getMyIntField [] Integer]
[setMyIntField [Integer] Void/TYPE]]))
(defn -init
[x]
[[] (ref x)])
(defn -getMyIntField
[this]
(-> this .state deref))
(defn -setMyIntField
[this x]
(dosync (ref-set (.state this) x)))
(Not tested, though)
b) Some structures inheritance? Is some form of (preferably multiple) structure inheritance supported? So far, I haven't found anything like that, but I think it would be possible to be implemented with macros.
I'm not sure I understand this correctly. In case you are asking for struct-maps: they are not "classes", they simply share their keys and are "just" an optimisation. Something like CLOS can probably be implemented on top of that.
c) CLOS? Does Clojure offer something similar to CLOS (multiple inheritance) known from Common Lisp?
You can implement multiple inheritance with multimethods. (declare A B C) (derive `A `B) (derive `A `C) (defmethod foo `B ...) (defmethod foo `C ...) (prefer-method foo `B `C)
2) In Common Lisp it's possible to define reader macros, and thus create a new syntax. Is it also possible in Clojure?
FAQ: No reader macros due to hygiene reasons. However you can use macros to modify the syntax. Sincerely Meikel
smime.p7s
Description: S/MIME cryptographic signature
