Re: Datatype Usage Examples

2010-05-31 Thread Sina K. Heshmati
Hi Meikel, Meikel Brandmeyer wrote: > On Mon, May 31, 2010 at 07:34:24AM +0200, Sina K. Heshmati wrote: > >> > (defn make-module >> > [] >> > (let [state (atom 0) >> > say-hello (fn [] (println "Hello")) >> > public-op (fn [x y] (+ @state x y))] >> > (fn [op] >> > (

Re: Datatype Usage Examples

2010-05-31 Thread Meikel Brandmeyer
Hi, On Mon, May 31, 2010 at 07:34:24AM +0200, Sina K. Heshmati wrote: > > (defn make-module > > [] > > (let [state (atom 0) > > say-hello (fn [] (println "Hello")) > > public-op (fn [x y] (+ @state x y))] > > (fn [op] > > (case op > > :hello say-hello > >

Re: Datatype Usage Examples

2010-05-31 Thread Sina K. Heshmati
Meikel Brandmeyer wrote: > On May 31, 3:15 pm, "Sina K. Heshmati" wrote: > >> True but my main concern is security of a running application. >> It could very well be that B is just a bunch of interactions, >> in which case B can enter A's namespace. > > ??? I'm not sure I understand. How can B "

Re: Datatype Usage Examples

2010-05-31 Thread Meikel Brandmeyer
Hi, On May 31, 3:15 pm, "Sina K. Heshmati" wrote: > True but my main concern is security of a running application. > It could very well be that B is just a bunch of interactions, > in which case B can enter A's namespace. ??? I'm not sure I understand. How can B "enter" the namespace of A? If y

Re: Datatype Usage Examples

2010-05-31 Thread Sina K. Heshmati
Problem solved, see below. Meikel Brandmeyer wrote: > On May 31, 1:46 pm, "Sina K. Heshmati" wrote: > >> Here's my concern: >> >> - My program (A) is running. >> - B is running on the same VM. >> - B accesses the state of A. >> - B alters the state of A in an inconsistent way >> e.g. whenever

Re: Datatype Usage Examples

2010-05-31 Thread Meikel Brandmeyer
Hi, On May 31, 1:46 pm, "Sina K. Heshmati" wrote: > Here's my concern: > > - My program (A) is running. > - B is running on the same VM. > - B accesses the state of A. > - B alters the state of A in an inconsistent way > e.g. whenever the internal state x changes, the > internal state y also

Re: Datatype Usage Examples

2010-05-31 Thread Sina K. Heshmati
"Meikel Brandmeyer" said: > On May 31, 10:58 am, "Sina K. Heshmati" wrote: > >> foo.datatype-01 => (reset! state 13) > ^^^ > > Again: of course you can! You are in the same namespace! In Clojure > the "unit" is a namespace and not a type. If you want this level > privateness you h

Re: Datatype Usage Examples

2010-05-31 Thread Meikel Brandmeyer
Hi, On May 31, 10:58 am, "Sina K. Heshmati" wrote: > foo.datatype-01 => (reset! state 13) ^^^ Again: of course you can! You are in the same namespace! In Clojure the "unit" is a namespace and not a type. If you want this level privateness you have to use one namespace per type. Ho

Re: Datatype Usage Examples

2010-05-31 Thread Sina K. Heshmati
"Meikel Brandmeyer" said: > On May 31, 9:37 am, "Sina K. Heshmati" wrote: > >> The atomic 'state' doesn't seem to be visible to the datatype methods. The >> question is why? >> >> (defprotocol prot-a >>   (op-a [self x y])) >> >> (let [state (atom 10)] >>   (deftype t-a [member] >>     prot-a >>

Re: Datatype Usage Examples

2010-05-31 Thread Meikel Brandmeyer
Hi, On May 31, 9:37 am, "Sina K. Heshmati" wrote: > The atomic 'state' doesn't seem to be visible to the datatype methods. The > question is why? > > (defprotocol prot-a >   (op-a [self x y])) > > (let [state (atom 10)] >   (deftype t-a [member] >     prot-a >     (op-a [self x y] >       (+ (.

Re: Datatype Usage Examples

2010-05-31 Thread Sina K. Heshmati
Sina K. Heshmati wrote: > Meikel Brandmeyer wrote: >> Am 30.05.2010 um 16:39 schrieb Sina K. Heshmati: >> > I'll later try to see if I can export datatypes from within a closure. The atomic 'state' doesn't seem to be visible to the datatype methods. The question is why? (defprotocol prot-a (op

Re: Datatype Usage Examples

2010-05-30 Thread Sina K. Heshmati
Hi Meikel, Meikel Brandmeyer wrote: > Am 30.05.2010 um 16:39 schrieb Sina K. Heshmati: > >> [2] >> http://github.com/sindoc/algorithms/blob/master/src/test/clojure/whiteboard/y2010/hide-adt-state-using-closure.clj > > I'm almost sure, that this code does not what you expect. Nested def's, and

Re: Datatype Usage Examples

2010-05-30 Thread Meikel Brandmeyer
Hi, Am 30.05.2010 um 16:39 schrieb Sina K. Heshmati: > [2] > http://github.com/sindoc/algorithms/blob/master/src/test/clojure/whiteboard/y2010/hide-adt-state-using-closure.clj I'm almost sure, that this code does not what you expect. Nested def's, and in particular defn's, are almost surely w

Re: Datatype Usage Examples

2010-05-30 Thread Sina K. Heshmati
"Adrian Cuthbertson" said: >> That said, I'd rather make sure that my low-level data structures are being >> operated on by only one implementation. > > You could use closures to encapsulate the refs/atoms ... > > (let [car-mem (ref nil)] > (defn set-car-mem [new-car-mem] > (dosync (ref-

Re: Datatype Usage Examples

2010-05-29 Thread Adrian Cuthbertson
> That said, I'd rather make sure that my low-level data structures are being > operated on by only one implementation. You could use closures to encapsulate the refs/atoms ... (let [car-mem (ref nil)] (defn set-car-mem [new-car-mem] (dosync (ref-set car-mem new-car-mem))) (defn update-

Re: Datatype Usage Examples

2010-05-29 Thread Sina K. Heshmati
Krukow wrote: > Sina K. Heshmati wrote: > [snip] >> The only member data _I'm_ able find are the ones that are passed to the >> default >> constructor, namely at the time that the abstraction is reified. What if I'd >> have >> to give create a member field that is not necessarily known by the cal

Re: Datatype Usage Examples

2010-05-28 Thread Krukow
On May 28, 9:59 pm, "Sina K. Heshmati" wrote: > Hi Krukow, [snip] > The only member data _I'm_ able find are the ones that are passed to the > default constructor, namely at the time that the abstraction is reified. What > if I'd have to give create a member field that is not necessarily known

Re: Datatype Usage Examples

2010-05-28 Thread Sina K. Heshmati
Hi Krukow, Krukow wrote: > SinDoc wrote: >> I was wondering if someone could point me to recent usage examples of >> deftype, defrecord, and reify. Reading [1] helped a lot but it wasn't >> particularly easy to find it since it's not linked from the sidebar. > > Blog: http://blog.higher-order.net

Re: Datatype Usage Examples

2010-05-28 Thread Sina K. Heshmati
Hi Meikel, Meikel Brandmeyer wrote: > SinDoc wrote: >> I was wondering if someone could point me to recent usage examples of >> deftype, defrecord, and reify. Reading [1] helped a lot but it wasn't >> particularly easy to find it since it's not linked from the sidebar. >> >> Specifically, what I'd

Re: Datatype Usage Examples

2010-05-28 Thread Krukow
On May 28, 9:52 am, SinDoc wrote: > L.S., > > I was wondering if someone could point me to recent usage examples of > deftype, defrecord, and reify. Reading [1] helped a lot but it wasn't > particularly easy to find it since it's not linked from the sidebar. I've used protocols and defrecords t

Re: Datatype Usage Examples

2010-05-28 Thread Meikel Brandmeyer
Hi, On May 28, 9:52 am, SinDoc wrote: > I was wondering if someone could point me to recent usage examples of > deftype, defrecord, and reify. Reading [1] helped a lot but it wasn't > particularly easy to find it since it's not linked from the sidebar. > > Specifically, what I'd like to know is:

Datatype Usage Examples

2010-05-28 Thread SinDoc
L.S., I was wondering if someone could point me to recent usage examples of deftype, defrecord, and reify. Reading [1] helped a lot but it wasn't particularly easy to find it since it's not linked from the sidebar. Specifically, what I'd like to know is: - How to define and access member data f