﻿<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=%E5%88%A9%E7%94%A8%E8%80%85%3AAnsimionescu%2FNotes%2F7</id>
	<title>利用者:Ansimionescu/Notes/7 - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.blender.jp/index.php?action=history&amp;feed=atom&amp;title=%E5%88%A9%E7%94%A8%E8%80%85%3AAnsimionescu%2FNotes%2F7"/>
	<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Ansimionescu/Notes/7&amp;action=history"/>
	<updated>2026-07-04T11:23:00Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Ansimionescu/Notes/7&amp;diff=137063&amp;oldid=prev</id>
		<title>Yamyam: 1版 をインポートしました</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Ansimionescu/Notes/7&amp;diff=137063&amp;oldid=prev"/>
		<updated>2018-06-28T20:49:43Z</updated>

		<summary type="html">&lt;p&gt;1版 をインポートしました&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2018年6月28日 (木) 20:49時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ja&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(相違点なし)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Yamyam</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Ansimionescu/Notes/7&amp;diff=137062&amp;oldid=prev</id>
		<title>wiki&gt;Ansimionescu: /* Simple */</title>
		<link rel="alternate" type="text/html" href="https://wiki.blender.jp/index.php?title=%E5%88%A9%E7%94%A8%E8%80%85:Ansimionescu/Notes/7&amp;diff=137062&amp;oldid=prev"/>
		<updated>2012-06-15T22:22:44Z</updated>

		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Simple&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Erlang basics==&lt;br /&gt;
'''Erlang''' is a functional programming language based on a runtime environment which is the basis for program execution. This makes it easily portable - you only have to port the ERTS. For full or short reference/guides, check [1] or [2]. Check out the history/philosophy behind Erlang on Wikipedia [3].&lt;br /&gt;
&lt;br /&gt;
'''OTP''' [4-6] is set of Erlang libraries and design principles providing middle-ware to develop these systems. It includes its own distributed database, applications to interface towards other languages, debugging and release handling tools.&lt;br /&gt;
&lt;br /&gt;
[[Image:Erlang-overview.jpg|frame|center]]&lt;br /&gt;
&lt;br /&gt;
===Types===&lt;br /&gt;
====Simple====&lt;br /&gt;
* '''integers'''&lt;br /&gt;
* '''characters''': implemented like special integers&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;$A % this is 65&amp;lt;/source&amp;gt;&lt;br /&gt;
* '''float'''&lt;br /&gt;
* '''bignums''': long ints&lt;br /&gt;
* '''atoms'''&lt;br /&gt;
** name starts with lower-case&lt;br /&gt;
** can be compared to a constant&lt;br /&gt;
** value(an atom) == the atom itself&lt;br /&gt;
* '''variables'''&lt;br /&gt;
** name starts with upper-case&lt;br /&gt;
** can't change the value once you set it&lt;br /&gt;
* '''references'''&lt;br /&gt;
* '''PIDs'''&lt;br /&gt;
* '''ports'''&lt;br /&gt;
&lt;br /&gt;
====Structures====&lt;br /&gt;
* '''tuples'''&lt;br /&gt;
** symbol: { }&lt;br /&gt;
** containers of fixed number of terms&lt;br /&gt;
** can contain other tuples&lt;br /&gt;
** equivalent of a vector&lt;br /&gt;
* '''lists'''&lt;br /&gt;
** symbol: []&lt;br /&gt;
** container of a variable number of terms&lt;br /&gt;
** equivalent of a linked list&lt;br /&gt;
** can contain other tuples/lists&lt;br /&gt;
* '''binaries'''&lt;br /&gt;
** blobs of memory&lt;br /&gt;
** term &amp;lt;-&amp;gt; binary&lt;br /&gt;
&lt;br /&gt;
===Constructing data===&lt;br /&gt;
Erlang is dynamically typed. You can't declare a type, the system keeps track of this for you.&lt;br /&gt;
&lt;br /&gt;
Appending an element to a list L:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;[element | L]&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Removing an element from L:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;[A | L] = [1, 2, 3]&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Erlang is built on pattern matching, which basically means assigning values to make the '=' statements true.&lt;br /&gt;
&lt;br /&gt;
===Functions===&lt;br /&gt;
* must be declared&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;-export([&amp;lt;name&amp;gt;/&amp;lt;n-of-args&amp;gt;]).&amp;lt;/source&amp;gt;&lt;br /&gt;
* have a head (name, args, optional condition) and a body (sequence of expressions separated by comma)&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;Name(Pattern11,...,Pattern1N) [when GuardSeq1] -&amp;gt;&lt;br /&gt;
    Body1;&lt;br /&gt;
...;&lt;br /&gt;
Name(PatternK1,...,PatternKN) [when GuardSeqK] -&amp;gt;&lt;br /&gt;
    BodyK.&amp;lt;/source&amp;gt;&lt;br /&gt;
* built-in functions (see more examples below): implemented in C code, usually impossible or too difficult to implement in erlang&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;1&amp;gt; tuple_size({a,b,c}).&lt;br /&gt;
3&lt;br /&gt;
2&amp;gt; atom_to_list('Erlang').&lt;br /&gt;
&amp;quot;Erlang&amp;quot;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Guards===&lt;br /&gt;
A way to implement conditional statements. Example of guards:&lt;br /&gt;
* == equality&lt;br /&gt;
* =/= non equality&lt;br /&gt;
* list(L) checks if L is a list&lt;br /&gt;
* tuple(Tup)&lt;br /&gt;
* binary(Bin)&lt;br /&gt;
* pid(Pid)&lt;br /&gt;
* port(Port)&lt;br /&gt;
* length(List)&lt;br /&gt;
* relational operators&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
atomorint(Atom) when atom(Atom) -&amp;gt; true;&lt;br /&gt;
atomorint(Int) when integer(Int) -&amp;gt; true;&lt;br /&gt;
atomorint(_Other) -&amp;gt; false.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Control structures===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
%%% The case statement&lt;br /&gt;
foo() -&amp;gt; case bar(X) of&lt;br /&gt;
   {case1, Arg}    -&amp;gt; handle_it(Arg);&lt;br /&gt;
   {case2, Value}  -&amp;gt; handle2(Value);&lt;br /&gt;
   Anything        -&amp;gt; true            % Works as 'default'&lt;br /&gt;
end.&lt;br /&gt;
&lt;br /&gt;
%%% If statement&lt;br /&gt;
foo(X) -&amp;gt; if&lt;br /&gt;
   X == 2   -&amp;gt; foo1();&lt;br /&gt;
   X == 3   -&amp;gt; foo2();&lt;br /&gt;
   true     -&amp;gt; true                   % Works as 'else'&lt;br /&gt;
end.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Concurrent Erlang==&lt;br /&gt;
Erlang has extremely lightweight processes, since it's build for massive concurrency.&lt;br /&gt;
===Creating processes===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
spawn(Module, Name, Args) -&amp;gt; pid()&lt;br /&gt;
  Module = Name = atom()&lt;br /&gt;
  Args = [Arg1,...,ArgN]&lt;br /&gt;
    ArgI = term()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''spawn'' creates a new process and returns the pid.&lt;br /&gt;
&lt;br /&gt;
The new process will start executing in ''Module:Name(Arg1,..,ArgN)'' where N can be 0.&lt;br /&gt;
&lt;br /&gt;
You can register a process by assigning its pid to a name.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
register(Name, Pid) % Associates the name Name, an atom, with the process Pid.&lt;br /&gt;
registered()        % Returns a list of names which have been &lt;br /&gt;
                    % registered using register/2.&lt;br /&gt;
whereis(Name)       % Returns the pid registered under Name, or&lt;br /&gt;
                    % undefined if the name is not registered.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Terminating processes===&lt;br /&gt;
&lt;br /&gt;
When a process terminates, it always terminates with an '''exit reason'''. The reason may be any term.&lt;br /&gt;
&lt;br /&gt;
A process is said to terminate '''normally''', if the exit reason is the atom normal. A process with no more code to execute terminates normally.&lt;br /&gt;
&lt;br /&gt;
A process terminates with exit reason {''Reason'',''Stack''} when a run-time error occurs.&lt;br /&gt;
&lt;br /&gt;
A process can terminate itself by calling one of the BIFs:&lt;br /&gt;
* ''exit(Reason)''&lt;br /&gt;
* ''erlang:error(Reason)''&lt;br /&gt;
* ''erlang:error(Reason, Args)''&lt;br /&gt;
* ''erlang:fault(Reason)''&lt;br /&gt;
* ''erlang:fault(Reason, Args)''&lt;br /&gt;
&lt;br /&gt;
The process then terminates with reason ''Reason'' for ''exit/1'' or {''Reason'',''Stack''} for the others.&lt;br /&gt;
&lt;br /&gt;
===Message sending===&lt;br /&gt;
[[Image:Erlang-processes-comm.gif|center|frameless|507px]]&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
%%% Send&lt;br /&gt;
Expr1 ! Expr2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Sends the value of ''Expr2'' as a message to the process specified by ''Expr1''. The value of ''Expr2'' is also the return value of the expression.&lt;br /&gt;
&lt;br /&gt;
''Expr1'' must evaluate to a pid, a registered name (atom) or a tuple {''Name'',''Node''}, where ''Name'' is an atom and ''Node'' a node name, also an atom.&lt;br /&gt;
&lt;br /&gt;
*If ''Expr1'' evaluates to a name, but this name is not registered, a ''badarg'' run-time error will occur.&lt;br /&gt;
*Sending a message to a pid never fails, even if the pid identifies a non-existing process.&lt;br /&gt;
*Distributed message sending, that is if ''Expr1'' evaluates to a tuple {''Name'',''Node''} (or a pid located at another node), also never fails.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
%%% Receive&lt;br /&gt;
receive&lt;br /&gt;
    Pattern1 [when GuardSeq1] -&amp;gt;&lt;br /&gt;
        Body1;&lt;br /&gt;
    ...;&lt;br /&gt;
    PatternN [when GuardSeqN] -&amp;gt;&lt;br /&gt;
        BodyN&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Receives messages sent to the process using the send operator ('''!'''). The patterns ''Pattern'' are sequentially matched against the first message in time order in the mailbox, then the second, and so on. If a match succeeds and the optional guard sequence ''GuardSeq'' is true, the corresponding ''Body'' is evaluated. The matching message is consumed, that is removed from the mailbox, while any other messages in the mailbox remain unchanged.&lt;br /&gt;
&lt;br /&gt;
The return value of ''Body'' is the return value of the receive expression.&lt;br /&gt;
&lt;br /&gt;
''receive'' never fails. Execution is suspended, possibly indefinitely, until a message arrives that does match one of the patterns and with a true guard sequence.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
%%% Receive example&lt;br /&gt;
wait_for_onhook() -&amp;gt;&lt;br /&gt;
    receive&lt;br /&gt;
        onhook -&amp;gt;&lt;br /&gt;
            disconnect(),&lt;br /&gt;
            idle();&lt;br /&gt;
        {connect, B} -&amp;gt;&lt;br /&gt;
            B ! {busy, self()},&lt;br /&gt;
            wait_for_onhook()&lt;br /&gt;
    end.&lt;br /&gt;
&lt;br /&gt;
%%% Receive with timeout example&lt;br /&gt;
wait_for_onhook() -&amp;gt;&lt;br /&gt;
    receive&lt;br /&gt;
        onhook -&amp;gt;&lt;br /&gt;
            disconnect(),&lt;br /&gt;
            idle();&lt;br /&gt;
        {connect, B} -&amp;gt;&lt;br /&gt;
            B ! {busy, self()},&lt;br /&gt;
            wait_for_onhook()&lt;br /&gt;
    after&lt;br /&gt;
        60000 -&amp;gt;&lt;br /&gt;
            disconnect(),&lt;br /&gt;
            error()&lt;br /&gt;
    end.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Coding==&lt;br /&gt;
===How to write and run a &amp;quot;.erl&amp;quot;===&lt;br /&gt;
* write your code in module.erl&lt;br /&gt;
* launch 'erl' in console&lt;br /&gt;
* compile your module using c(module). or c(module.erl).&lt;br /&gt;
* now you can use what you declared with '-export([..]).'&lt;br /&gt;
* do it by appending the module name before; e.g. 'module:foo(1).'&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
example.erl&lt;br /&gt;
&lt;br /&gt;
-module(example).&lt;br /&gt;
-export([fact/1]).&lt;br /&gt;
&lt;br /&gt;
fact(0) -&amp;gt; 1;&lt;br /&gt;
fact(N) -&amp;gt; N * fact(N-1).&lt;br /&gt;
&lt;br /&gt;
Eshell V5.5.5  (abort with ^G)&lt;br /&gt;
1&amp;gt; c(example).&lt;br /&gt;
{ok,example}&lt;br /&gt;
2&amp;gt; example:fact(0).&lt;br /&gt;
1&lt;br /&gt;
3&amp;gt; example:fact(5).&lt;br /&gt;
120&lt;br /&gt;
4&amp;gt; example:fact(10).&lt;br /&gt;
3628800&lt;br /&gt;
5&amp;gt; example:fact(25).&lt;br /&gt;
15511210043330985984000000&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Built in functions examples===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
%%% Can be used as guards:&lt;br /&gt;
75&amp;gt; trunc(5.6).&lt;br /&gt;
5&lt;br /&gt;
76&amp;gt; round(5.6).&lt;br /&gt;
6&lt;br /&gt;
77&amp;gt; length([a,b,c,d]).&lt;br /&gt;
4&lt;br /&gt;
78&amp;gt; float(5).&lt;br /&gt;
5.0&lt;br /&gt;
79&amp;gt; is_atom(hello).&lt;br /&gt;
true&lt;br /&gt;
80&amp;gt; is_atom(&amp;quot;hello&amp;quot;).&lt;br /&gt;
false&lt;br /&gt;
81&amp;gt; is_tuple({paris, {c, 30}}).&lt;br /&gt;
true&lt;br /&gt;
82&amp;gt; is_tuple([paris, {c, 30}]).&lt;br /&gt;
false&lt;br /&gt;
&lt;br /&gt;
%%% Can't be used in guards:&lt;br /&gt;
83&amp;gt; atom_to_list(hello).&lt;br /&gt;
&amp;quot;hello&amp;quot;&lt;br /&gt;
84&amp;gt; list_to_atom(&amp;quot;goodbye&amp;quot;).&lt;br /&gt;
goodbye&lt;br /&gt;
85&amp;gt; integer_to_list(22).&lt;br /&gt;
&amp;quot;22&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Simple RPC server-client example===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;erlang&amp;quot;&amp;gt;&lt;br /&gt;
%%% Server&lt;br /&gt;
% Assume the server is registered under the name 'rex'&lt;br /&gt;
loop() -&amp;gt;&lt;br /&gt;
   receive&lt;br /&gt;
      {From, {apply, M, F, A}} -&amp;gt;&lt;br /&gt;
         From ! {rex, node(), apply(M, F, A)}&lt;br /&gt;
         loop();&lt;br /&gt;
      _Other -&amp;gt;&lt;br /&gt;
         loop();&lt;br /&gt;
   end.&lt;br /&gt;
&lt;br /&gt;
%%% Client&lt;br /&gt;
call(Node, M, F, A) -&amp;gt;&lt;br /&gt;
   {rex, Node} ! {self(), {apply, M, F, A}},&lt;br /&gt;
   receive&lt;br /&gt;
      {rex, Node, What} -&amp;gt;&lt;br /&gt;
         What&lt;br /&gt;
   end.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Home:&lt;br /&gt;
&lt;br /&gt;
[0] http://wiki.blender.org/index.php/User:Ansimionescu&lt;br /&gt;
&lt;br /&gt;
Reference:&lt;br /&gt;
&lt;br /&gt;
[1] Short http://www.erlang.org/doc/getting_started/users_guide.html&lt;br /&gt;
&lt;br /&gt;
[2] Full http://www.erlang.org/doc/reference_manual/users_guide.html&lt;br /&gt;
&lt;br /&gt;
[3] Wikipedia http://en.wikipedia.org/wiki/Erlang_(programming_language)#History&lt;br /&gt;
&lt;br /&gt;
[4] Open Telecom Platform https://github.com/erlang/otp&lt;br /&gt;
&lt;br /&gt;
[5] OTP #2 http://learnyousomeerlang.com/what-is-otp&lt;br /&gt;
&lt;br /&gt;
[6] OTP #3 https://github.com/erlang/otp/blob/maint/README.md&lt;/div&gt;</summary>
		<author><name>wiki&gt;Ansimionescu</name></author>
		
	</entry>
</feed>