<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Creating functions with Aseba language</title>
		<link>http://aseba.wikidot.com/forum/t-638175/creating-functions-with-aseba-language</link>
		<description>Posts in the discussion thread &quot;Creating functions with Aseba language&quot; - Is it possible to define something similar to custom functions, with input parameters and output?</description>
				<copyright></copyright>
		<lastBuildDate>Tue, 14 Jul 2026 22:40:27 +0000</lastBuildDate>
		
					<item>
				<guid>http://aseba.wikidot.com/forum/t-638175#post-1741374</guid>
				<title>Re: Creating functions with Aseba language</title>
				<link>http://aseba.wikidot.com/forum/t-638175/creating-functions-with-aseba-language#post-1741374</link>
				<description></description>
				<pubDate>Fri, 29 Mar 2013 22:43:56 +0000</pubDate>
				<wikidot:authorName>Heidegger</wikidot:authorName>				<wikidot:authorUserId>1560534</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Thank you.</p> <p>German: &quot;Aseba ist simpel, aber leistungsfähig genug, um auch komplexes Programmieren zu erlauben. Zwar gibt es in Aseba keine Möglichkeit Funktionen zu definieren, wie sie in anderen Programmiersprachen bestehen. Es gibt nur Subroutinen ohne Argumente. Da in Aseba aber alle Variablen global sind, können wir etwas ziemlich ähnliches wie Funktionen erhalten, indem wir Subroutinen mit Variablen verwenden: Wir werden sie <em>Pseudofunktionen</em> nennen. Man kann globale Variablen am Anfang deklarieren. Damit lassen sich die Variablen in Subroutinen dazu verwenden Berechnungen anzustellen und Resultate zu erhalten, so als ob man Argumente verwenden würde.<br /> Hier kannst du ein Beispiel für eine Pseudofunktion f1 mit drei Argumenten sehen, die eine Multiplikation der ersten zwei Argumente vollzieht und dann eine Addition eines Dritten.</p> <div class="code"> <pre><code># Wir legen die Variablen unserer Pseudofunktion fest (also die Argumente des In und Outputs). #Wir führen eine Notation in der Form //Pseudofunktionsname_Pseudofunktionsargument// #(Beispiel: f1_arg1) ein, nur zur besseren Übersicht, damit wir uns erinnern können, dass die #Variablen der Pseudofunktion angehören. var f1_arg1 var f1_arg2 var f1_arg3 var f1_res var X # Dekleration der Pseudofunktion sub f1 f1_res = f1_arg1 * f1_arg2 + f1_arg3 # Jetzt kannst du die Pseudofunktion f1 in einem Codeblock so aufrufen: # Initialisieren der Argumente f1_arg1=10 f1_arg2=3 f1_arg3=4 # Aufruf der Pseudofunktion callsub f1 x = f1_res # Das Resultat 34 wird in der Variable x gespeichert</code></pre></div> <p>Beachte, dass dieser Code &quot;sicher&quot; ist, weil du die Funktion nicht in einer rekursiven Weise (auch nicht indirekt) aufrufen kannst (<strong>easier explination needed, if it's important for getting the idea of a pseudofunction</strong>).</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-638175#post-1740860</guid>
				<title>Creating functions with Aseba language</title>
				<link>http://aseba.wikidot.com/forum/t-638175/creating-functions-with-aseba-language#post-1740860</link>
				<description></description>
				<pubDate>Fri, 29 Mar 2013 06:19:50 +0000</pubDate>
				<wikidot:authorName>eziosoma</wikidot:authorName>				<wikidot:authorUserId>1452547</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>The Aseba Language is simple but powerful enough to manage also complex coding.<br /> In Aseba language apparently there is not the possibility to define custom function as you can find in other languages. There are only subroutines without arguments.<br /> Starting with this trick you must take in account that in Aseba all the variables are global.<br /> You can use subroutines and variables in order to implement something very similar to functions that we will call <em>pseudofunctions</em>. You can declare global variables conventionally tied to a subroutine and use them for passing arguments and get back results.<br /> You can see there a sample for a psudofunction f1 with three arguments, that perfroms the multiplication of the first two argoments and then add the third.</p> <div class="code"> <pre><code># declaring pseudofunction input and output arguments. We introduce the notation of prefixing the name of the # variable with the name of the pseudo function, just in order to remember that these # variables are dedicated to the named pseudofunction. var f1_arg1 var f1_arg2 var f1_arg3 var f1_res var X # declaring pseudofunction sub f1 f1_res = f1_arg1 * f1_arg2 + f1_arg3 # Now You can call pseudofunction f1 as follow: # initialize arguments f1_arg1=10 f1_arg2=3 f1_arg3=4 # Call the pseudofunction callsub f1 x = f1_res # The result will be 34 in the variable x</code></pre></div> <p><strong>Note for expert programmers</strong><br /> An expert programmer can consider that normally this is not a good way of implementing functions.<br /> This method is &quot;safe&quot; (in the sense that it works correctly) just only because in the Aseba language you cannot call subroutines in a recursive way (also indirectly). This coding is not re-entrant safe but also <a href="http://en.wikipedia.org/wiki/Reentrancy_%28computing%29" target="_blank">re-entrant</a> programming is not possible (interrupts are not managed at all).</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>