wisp-lang / wisp

A little Clojure-like LISP in JavaScript
https://gozala.github.io/wisp/
Other
982 stars 68 forks source link

Fix deftypes with mutable fields #82

Open Gozala opened 10 years ago

Gozala commented 10 years ago
(defprotocol IMutate
  (mutate [this]))

(deftype Mutate [^:mutable a]
  IMutate
  (mutate [_] (set! a 'foo)))
Gozala commented 10 years ago

I guess I could simply modify generated code to be:

var Mutate = exports.Mutate = (function () {
        var Mutate = function Mutate(a) {
            this.a = a;
            return this;
        };
        Mutate.prototype[IMutate.wisp_core$IProtocol$id] = true;
        Mutate.prototype[IMutate.mutate.name] = function (_) {
            var a = this.a;
            try {
              return a = symbol(void 0, 'foo');
            } finally {
              this.a = a
            }
        };
        return Mutate;
    })();