<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.sternwarte.uni-erlangen.de/wiki/index.php?action=history&amp;feed=atom&amp;title=Self-value_management</id>
	<title>Self-value management - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.sternwarte.uni-erlangen.de/wiki/index.php?action=history&amp;feed=atom&amp;title=Self-value_management"/>
	<link rel="alternate" type="text/html" href="https://www.sternwarte.uni-erlangen.de/wiki/index.php?title=Self-value_management&amp;action=history"/>
	<updated>2026-04-16T10:11:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.7</generator>
	<entry>
		<id>https://www.sternwarte.uni-erlangen.de/wiki/index.php?title=Self-value_management&amp;diff=928&amp;oldid=prev</id>
		<title>Lorenz: Created page with &quot;'''This page is under construction'''   Although the code below is very short (52 lines), its advantages are enormous. Thus, the explanation takes a while and is not written y...&quot;</title>
		<link rel="alternate" type="text/html" href="https://www.sternwarte.uni-erlangen.de/wiki/index.php?title=Self-value_management&amp;diff=928&amp;oldid=prev"/>
		<updated>2018-04-12T14:03:50Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;This page is under construction&amp;#039;&amp;#039;&amp;#039;   Although the code below is very short (52 lines), its advantages are enormous. Thus, the explanation takes a while and is not written y...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;'''This page is under construction''' &lt;br /&gt;
&lt;br /&gt;
Although the code below is very short (52 lines), its advantages are enormous. Thus, the explanation takes a while and is not written yet ;-) &lt;br /&gt;
&lt;br /&gt;
It combines &lt;br /&gt;
* [[isis:structfun|structures with functions]] and&lt;br /&gt;
* [[isis:functionnest|function nesting]] &lt;br /&gt;
to prevent values to be calculated multiple times (e.g. cosine of an angle). This is especially very helpful for more complex codes, in which there are many 'shared' values, as the user only has to think about it once when setting up the '''svm-object'''. Afterwards the '''svm-object''' does all the work on its one!&lt;br /&gt;
&lt;br /&gt;
*  '''NOTES:'''&lt;br /&gt;
** Runtime is around twice as slow as compared to same code coded straight forward, which is due to the function calling!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
private define define_retrun_function( return_fields ){&lt;br /&gt;
  if(typeof(return_fields) != Array_Type) return_fields = [return_fields];&lt;br /&gt;
  &lt;br /&gt;
  variable f;&lt;br /&gt;
  foreach f ( return_fields )&lt;br /&gt;
    eval(sprintf(&amp;quot;private define return_%s(obj) { return obj.data.%s; };&amp;quot;, f, f));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private define define_calculation_function( field, execute ){&lt;br /&gt;
  if(typeof(field) != Array_Type) field = [field];&lt;br /&gt;
&lt;br /&gt;
  variable tempfun = &amp;quot;&amp;quot;;&lt;br /&gt;
  variable f,ff;&lt;br /&gt;
  foreach f (field){&lt;br /&gt;
    tempfun += sprintf(&amp;quot;private define calculate_%s(obj) {&amp;quot;, f);&lt;br /&gt;
    tempfun += sprintf(&amp;quot;(%s) = %s;&amp;quot;, strjoin(&amp;quot;obj.data.&amp;quot;+field, &amp;quot;,&amp;quot;), execute);&lt;br /&gt;
    foreach ff (field)&lt;br /&gt;
      tempfun += sprintf(&amp;quot;obj.%s = &amp;amp;return_%s;&amp;quot;, ff, ff);&lt;br /&gt;
    tempfun += sprintf(&amp;quot;return obj.data.%s;&amp;quot;, f);&lt;br /&gt;
    tempfun += &amp;quot;}&amp;quot;;&lt;br /&gt;
    eval(tempfun);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private define reset_fields( obj ){&lt;br /&gt;
  variable fieldnames = get_struct_field_names( obj.data );&lt;br /&gt;
  variable f;&lt;br /&gt;
  foreach f (fieldnames){&lt;br /&gt;
    set_struct_field( obj, f, eval(sprintf(&amp;quot;&amp;amp;calculate_%s&amp;quot;, f)));&lt;br /&gt;
    set_struct_field( obj.data, f, NULL );&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
define object_init() {&lt;br /&gt;
  variable fieldnames = [ &amp;quot;sint&amp;quot;,&amp;quot;cost&amp;quot;,&amp;quot;fun&amp;quot; ];&lt;br /&gt;
  define_retrun_function( fieldnames );&lt;br /&gt;
  define_calculation_function([&amp;quot;sint&amp;quot;,&amp;quot;cost&amp;quot;], &amp;quot;sincos(obj.input.theta)&amp;quot;);&lt;br /&gt;
  define_calculation_function( &amp;quot;fun&amp;quot;, &amp;quot;obj.cost()+obj.sint()&amp;quot;);&lt;br /&gt;
  &lt;br /&gt;
  % Actual object&lt;br /&gt;
  variable obj = struct_combine(struct{&lt;br /&gt;
    data = struct_combine(fieldnames), % Storage for field values&lt;br /&gt;
    input = struct{ theta = 0. },&lt;br /&gt;
    reset = &amp;amp;reset_fields&lt;br /&gt;
  },fieldnames); % Adding defined fields&lt;br /&gt;
&lt;br /&gt;
  % Initialize object fields with pointers to calulating functions&lt;br /&gt;
  reset_fields( obj );&lt;br /&gt;
  &lt;br /&gt;
  return obj;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, let's have a look on the output of the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
isis&amp;gt; variable a = object_init;&lt;br /&gt;
isis&amp;gt; print(a);&lt;br /&gt;
{data=Struct_Type with 3 fields,&lt;br /&gt;
 input=Struct_Type with 1 fields,&lt;br /&gt;
 sint=&amp;amp;calculate_sint,&lt;br /&gt;
 cost=&amp;amp;calculate_cost,&lt;br /&gt;
 fun=&amp;amp;calculate_fun}&lt;br /&gt;
isis&amp;gt; a.fun();&lt;br /&gt;
1.0&lt;br /&gt;
isis&amp;gt; print(a);&lt;br /&gt;
{data=Struct_Type with 3 fields,&lt;br /&gt;
 input=Struct_Type with 1 fields,&lt;br /&gt;
 sint=&amp;amp;return_sint,&lt;br /&gt;
 cost=&amp;amp;return_cost,&lt;br /&gt;
 fun=&amp;amp;return_fun}&lt;br /&gt;
isis&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Isis / Slang]]&lt;/div&gt;</summary>
		<author><name>Lorenz</name></author>
	</entry>
</feed>