Download code

Jump to: navigation, search

Back to Functional_object_(Matlab)

Download for Windows: zip

Download for UNIX: zip, tar.gz, tar.bz2

polymorphism_example.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = polymorphism_example( v)
16 % POLYMORPHISM EXAMPLE -
17 this.value = v;
18 z = struct('get',@get,'set',@set,'to_string',@to_string);
19 function v = get
20     v = this.value;
21 end
22 function set( v)
23     this.value = v;
24 end
25 function str = to_string(pref, v)
26     if nargin<1
27         pref = '';
28     end
29     if nargin<2
30         v = this.value;
31     end
32     if isstr(v)
33         str = [pref '-str:' v ':'];
34     elseif isnumeric(v)
35         if length(v)==1
36             str = [pref '-num:' num2str(v) ':'];
37         else
38             str = [pref '-vnum:' sprintf('%f:',v)];
39         end
40     elseif isstruct(v)
41         fnames = fieldnames(v);
42         str = '';
43         for f=1:length(fnames)
44             str = sprintf('%s%s\n', str, to_string(['struct:' fnames{f}], v.(fnames{f})));
45         end
46         str = str(1:end-1);
47     elseif iscell(v)
48         str = '';
49         for f=1:length(v)
50             str = sprintf('%s%s\n', str, to_string('cell', v{f}));
51         end
52         str = str(1:end-1);
53     elseif isa(v, 'function_handle')
54         str = '@???';
55     else
56         str = '***UNKNOWN***';
57     end
58 end
59 end


hijacker
hijacker
hijacker
hijacker

test_embedded3.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = test_embedded3( a)
16 % TEST_EMBEDDED3 - simple test of embedded function
17 z = @ALPHA_A;
18 function u = ALPHA_A(x)
19    u = ALPHA(a,x);
20 end
21 function u = ALPHA(v,w)
22    u = v+w;
23 end
24 end


hijacker
hijacker
hijacker
hijacker

my_light_object.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = my_light_object( mode, varargin)
16 % MY_LIGHT_OBJECT - a light struct object
17 % two versions embedded:
18 %
19 % 1. functional:
20 % mlo = my_light_object('init', 'alpha', 1, 'beta', 2)
21 % my_light_object('get', mlo, 'alpha')
22 % my_light_object('set', mlo, 'beta', 8, 'garzol', 12)
23 %
24 % 2. struct object
25 % mlo = my_light_object('create', 'alpha', 1, 'beta', 2)
26 % mlo.get('alpha')
27 % mlo.set('beta', 8, 'garzol', 12)
28 % mlo.get()
29 switch lower(mode)
30     case 'init'
31         %<* init a function mlo
32         z = [];
33         for i=1:2:length(varargin)-1
34             z.(varargin{i}) = varargin{i+1};
35         end
36         %>*
37     case 'get'
38         %<* Get attribute
39         if length(varargin)==1
40             z = varargin{1};
41             return
42         end
43         z = {};
44         for i=2:length(varargin)
45             z{end+1} = varargin{1}.(varargin{i});
46         end
47         if length(z)==1
48             z = z{1};
49         end
50         %>*
51     case 'set'
52         %<* set attribute
53         z = varargin{1};
54         for i=2:2:length(varargin)-1
55             z.(varargin{i})= varargin{i+1};
56         end
57         %>*
58     case 'create'
59         %<* object version
60         this = my_light_object('init', varargin{:});
61         z = struct('get', @get_, 'set', @set_);
62         %>*
63     otherwise
64         error('my_light_object:mode', 'mode <%s> is unknown', mode);
65 end
66 
67 %%** Internals
68 %<* Embedded get
69 function v = get_( varargin)
70 v = my_light_object('get', this, varargin{:});
71 end
72 %>*
73 %<* Embedded set
74 function set_(varargin)
75 this = my_light_object('set', this, varargin{:});
76 end
77 %>*
78 end


hijacker
hijacker
hijacker
hijacker

inherit.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = inherit( objects, varargin)
16 % INHERIT - automated inheritance
17 this = struct('value', {varargin}, 'objects', {objects});
18 for o=1:length(objects)
19     this.(objects{o}) = feval(objects{o}, varargin);
20 end
21 z    = struct('get', @get_this, 'invoke', @hinvoke);
22 
23 function [v, os] = hinvoke( method_name, varargin)
24     v  = {};
25     os = {};
26     % For each parent object
27     for o=1:length(this.objects)
28         % Find existing methods with this name
29         idx = strmatch(method_name, fieldnames(this.(objects{o})), 'exact');
30         if ~isempty(idx)
31             % If possible, apply it (and store the name of the used object)
32             os{end+1} = this.objects{o};
33             if isempty(varargin)
34                 v{end+1}  = feval(this.(this.objects{o}).(method_name));
35             else
36                 v{end+1}  = feval(this.(this.objects{o}).(method_name), varargin);
37             end
38         end
39     end
40 end
41 function t = get_this
42     t = this;
43 end
44 end


hijacker
hijacker
hijacker
hijacker

script_to_test_2.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 z = test_embedded2(1);
16 z(2,3)


hijacker
hijacker
hijacker
hijacker

test_embedded1.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = test_embedded1( a)
16 % TEST_EMBEDDED1 - simple test of embedded function
17 z = ALPHA(a,2);
18 function u = ALPHA(v,w)
19    u = v+w;
20 end
21 end
22 


hijacker
hijacker
hijacker
hijacker

functional_object.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = functional_object( v1, ..., vN)
16 % FUNCTIONAL_OBJECT -
17 this = struct('v1', v1, ..., 'vN', vN);
18 z    = struct('get_v', @get_v, 'set_v', @set_v, etc);
19 
20 function f = get_fields
21     f = fieldnames(this);
22 end
23 function v = get_v(n)
24     f = get_fields();
25     v = this.(f{n});
26 end
27 function set_v(n, v)
28     f = get_fields();
29     this.(f{n}) = v;
30 end
31 ...
32 end


hijacker
hijacker
hijacker
hijacker

object1.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = object1( v)
16 % OBJECT1 - addition
17 this.v = v;
18 z      = struct('add', @ADD, 'get', @get, 'set', @set);
19 
20 function v = set(v)
21     this.v = v;
22 end
23 function v = get
24     v = this.v;
25 end
26 function u = ADD( x)
27     u = x+this.v;
28 end
29 end


hijacker
hijacker
hijacker
hijacker

script_pe.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 pe=polymorphism_example( 5)
16 pe.to_string()
17 pe.set(1:10); pe.to_string()
18 pe.set('garzol'); pe.to_string()
19 pe.set({'garzol', 4}); pe.to_string()
20 pe.set(struct('alpha',{{'garzol', 4}},'beta',1:3)); pe.to_string()


hijacker
hijacker
hijacker
hijacker

object2.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = object2( v)
16 % OBJECT2 - substraction
17 this.v = v;
18 z      = struct('substract', @SUBSTRACT, 'get', @get, 'set', @set);
19 
20 function v = set(v)
21     this.v = v;
22 end
23 function v = get
24     v = this.v;
25 end
26 function u = SUBSTRACT( x)
27     u = x-this.v;
28 end
29 end


hijacker
hijacker
hijacker
hijacker

object12.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = object12( v)
16 % OBJECT12 - addition and substraction
17 this = struct('v', v, 'add', object1(v), 'substract', object2(v));
18 z    = struct('substract', this.substract.substract, 'add',this.add.add, ...
19               'get', @get, 'set', @(x)([set(v), this.add.set(v), this.substract.set(v)]));
20 
21 function v = set(v)
22     this.v = v;
23 end
24 function v = get
25     v = this.v;
26 end
27 end


hijacker
hijacker
hijacker
hijacker

use_inheritance_script.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 z = inherit({'object1', 'object2'}, 2);
16 z.get()
17 z.invoke('set', 3);
18 z.invoke('get');
19 z.get()
20 z.invoke('add',1)
21 z.invoke('substract',1)


hijacker
hijacker
hijacker
hijacker

script_to_test_3.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 z = test_embedded3(1);
16 z(2)
17 z(3)


hijacker
hijacker
hijacker
hijacker

test_embedded2.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 function z = test_embedded2( a)
16 % TEST_EMBEDDED2 - simple test of embedded function
17 z = @ALPHA;
18 function u = ALPHA(v,w)
19    u = v+w;
20 end
21 end


hijacker
hijacker
hijacker
hijacker

script4mlo.m

 1 % The authors of this work have released all rights to it and placed it
 2 % in the public domain under the Creative Commons CC0 1.0 waiver
 3 % (http://creativecommons.org/publicdomain/zero/1.0/).
 4 % 
 5 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 % MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 % IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 % CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 % TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 % SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 % 
13 % Retrieved from: http://en.literateprograms.org/Functional_object_(Matlab)?oldid=13870
14 
15 %% How to build simple MATLAB object
16 
17 %% Functionnal version
18 mlo = my_light_object('init', 'alpha', 1, 'beta', 2)
19 my_light_object('get', mlo, 'alpha')
20 my_light_object('set', mlo, 'beta', 8, 'garzol', 12)
21 
22 %% Struct object version
23 mlo = my_light_object('create', 'alpha', 1, 'beta', 2)
24 mlo.get('alpha')
25 mlo.set('beta', 8, 'garzol', 12)
26 mlo.get()


hijacker
hijacker
hijacker
hijacker