diff options
| author | Joel Martin <github@martintribe.org> | 2015-02-10 01:34:56 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-02-10 01:34:56 -0600 |
| commit | 53942f889aa103e5ea298b92b7a4fc7d7a133d1a (patch) | |
| tree | a6d2b54452b04dd9ed6185fa1427ab57a078456b /matlab/core.m | |
| parent | 6a572dff25a95f460d1b3c1b259c7a0a1f10c2d0 (diff) | |
| download | mal-53942f889aa103e5ea298b92b7a4fc7d7a133d1a.tar.gz mal-53942f889aa103e5ea298b92b7a4fc7d7a133d1a.zip | |
matlab: add metadata and atom support.
Diffstat (limited to 'matlab/core.m')
| -rw-r--r-- | matlab/core.m | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/matlab/core.m b/matlab/core.m index 5947c2d..ef3848e 100644 --- a/matlab/core.m +++ b/matlab/core.m @@ -124,6 +124,35 @@ classdef core ret = types.List(cells{:}); end + function new_obj = with_meta(obj, meta) + new_obj = clone(obj); + new_obj.meta = meta; + end + + function meta = meta(obj) + switch class(obj) + case {'types.List', 'types.Vector', + 'types.HashMap', 'types.Function'} + meta = obj.meta; + otherwise + meta = types.nil; + end + end + + function ret = reset_BANG(atm, val) + atm.val = val; + ret = val; + end + + function ret = swap_BANG(atm, f, varargin) + args = [{atm.val} varargin]; + if isa(f, 'types.Function') + f = f.fn; + end + atm.val = f(args{:}); + ret = atm.val; + end + function n = ns() n = containers.Map(); n('=') = @types.equal; @@ -177,6 +206,14 @@ classdef core n('count') = @(a) length(a); n('apply') = @core.apply; n('map') = @core.map; + + n('with-meta') = @core.with_meta; + n('meta') = @core.meta; + n('atom') = @types.Atom; + n('atom?') = @(a) isa(a, 'types.Atom'); + n('deref') = @(a) a.val; + n('reset!') = @core.reset_BANG; + n('swap!') = @core.swap_BANG; end end end |
