<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7315093977193209605</id><updated>2024-12-23T23:59:44.587+01:00</updated><category term="F#"/><category term="C/C++"/><category term="HTML"/><category term="Web Server"/><category term="OpenGL in C/C++"/><title type='text'>Code Power</title><subtitle type='html'>C/C++, F#, HTML, OpenGL, Java, PHP, CSS, JavaScript, JSP, VBA, algoritmi interessanti</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-4202581171803507766</id><published>2012-01-15T20:38:00.000+01:00</published><updated>2012-01-15T20:38:15.434+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Tipi derivati</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Come è stato detto negli articoli precedenti &lt;b&gt;F#&lt;/b&gt; possiede una serie di &lt;b&gt;tipi nativi&lt;/b&gt; del linguaggio, come il tipo &lt;b&gt;intero&lt;/b&gt;, &lt;b&gt;float&lt;/b&gt;, &lt;b&gt;boolean&lt;/b&gt; e così via. Ma come è stato detto, questi sono dei tipi nativi, già presenti nel linguaggio, che possono, però, contribuire alla creazione di nuovi tipi, i così detti &lt;b&gt;tipi derivati&lt;/b&gt;. Esistono, sostanzialmente, tre categorie di tipi derivati: tipi &lt;b&gt;enumerati&lt;/b&gt;, tipi &lt;b&gt;unione&lt;/b&gt; e tipi &lt;b&gt;record&lt;/b&gt;.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Tipi enumerati&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Nella categoria dei tipi enumerati rientrano i tipi creati mediante l&#39;enumerazione degli elementi che fanno parte dell&#39;insieme del tipo. Se per esempio vogliamo creare un nuovo tipo, che rappresenti l&#39;insieme dei giorni della settimana. Quello che dobbiamo fare è dare un nome ad ogni giorno della settimana e indicare che quel elemento appartiene all&#39;insieme dei giorni della settimana. Di seguito è stato rappresentato l&#39;insieme del tipo che andremo a creare:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;giorno = {Lunedì, Martedì, Mercoledì, Giovedì, Venerdì, Sabato, Domenica}&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
In altre parole, l&#39;insieme appena citato contiene soltanto i valori elencati. La creazione di un tipo enumerato in F# viene fatto in un modo analogo:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;type&lt;/b&gt;&lt;/span&gt; giorno= Lunedi | Martedi | Mercoledi | Giovedi | Venerdi | Sabato | Domenica;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In questo modo abbiamo definito un nuovo tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;giorno&lt;/span&gt;, il cui insieme dei valori è uguale a quello elencato in precedenza. Proviamo ad eseguire in &lt;b&gt;F# Interactive&lt;/b&gt;(Ctrl+Alt+F) il codice di seguito riportato:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; x = Sabato;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Come risposta dell&#39;interprete avremo questo messaggio:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;val x : giorno = Sabato&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Da questa risposta possiamo vedere che l&#39;interprete ha deciso automaticamente che la variabile &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt; è di tipo &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;giorno&lt;/span&gt;&lt;/span&gt; ed il suo valore è uguale a &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Sabato&lt;/span&gt;&lt;/span&gt;.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A questo punto potremo scrivere una funzione, che prende come argomento un &lt;b&gt;giorno&lt;/b&gt; della settimana e come risultato restituisce un valore &lt;b&gt;booleano&lt;/b&gt;, per indicare se il giorno è lavorativo:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; lavorativo day =&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;match&lt;/span&gt;&lt;/b&gt; day &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;with&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | Sabato | Domenica &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;-&amp;gt; false&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | _ &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;-&amp;gt; true&lt;/b&gt;&lt;/span&gt;;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
La funzione, quindi, prende come argomento un valore di tipo &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;giorno&lt;/span&gt;&lt;/span&gt; e lo confronta con il valore &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Sabato&lt;/span&gt;&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Domenica&lt;/span&gt;. Se &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;day&lt;/span&gt; è uguale a &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Sabato&lt;/span&gt;&lt;/span&gt;, oppure a &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Domenica&lt;/span&gt;, allora restituisce &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt;, perché &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;day&lt;/span&gt;&lt;/span&gt; non rappresenta un giorno lavorativo. In tutti gli altri casi &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;day&lt;/span&gt; rappresenta un giorno lavorativo, quindi la funzione restituisce &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt;.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;Tipi unione&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A differenza dei tipi enumerati i tipi unione non devono essere elencati uno ad uno, quando si vuole definire un nuovo tipo, perché essi vengono creati sulla base degli altri tipi, già definiti. In pratica per definire un nuovo tipo unione dobbiamo elencare soltanto i suoi elementi e il tipo di tali elementi. Per esempio, potremo creare un tipo, che permetta di identificare un oggetto dal nome, oppure da un numero identificativo. Di seguito è riportato il codice di come sia possibile farlo:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;type&lt;/span&gt;&lt;/b&gt; id = Name &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;of string&lt;/b&gt;&lt;/span&gt; | Id &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;of int&lt;/b&gt;&lt;/span&gt;;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In questo modo verrà definito il tipo &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;id&lt;/span&gt;&lt;/span&gt;, che ha come elementi &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Name&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Id&lt;/span&gt;&lt;/span&gt;. Ma anche se la definizione del tipo unione è molto simile a quella dei tipi enumerati, l&#39;impiego di questi tipi è leggermente diverso. Di seguito è riportato un esempio di come sia possibile dichiarare una variabile di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;id&lt;/span&gt;:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; identity = Name &lt;span style=&quot;color: #990000;&quot;&gt;&quot;Tizio&quot;&lt;/span&gt;;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; identity2 = Id &lt;span style=&quot;color: magenta;&quot;&gt;4231&lt;/span&gt;;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Come si può vedere dall&#39;esempio, bisogna fare attenzione a scrivere prima l&#39;elemento dell&#39;insieme del tipo, seguito dal valore del rispettivo tipo. Il vantaggio di avere questo modo di definire i tipi è quello di poter utilizzare il tipo stesso nella sua definizione, che ci permette di creare delle strutture informatiche molto importanti, quali le &lt;b&gt;liste concatenate&lt;/b&gt; e gli &lt;b&gt;alberi&lt;/b&gt;. Di seguito è riportato il codice che ci permette di creare una &lt;b&gt;lista concatenata&lt;/b&gt;, una struttura dati molto simile alle &lt;b&gt;liste&lt;/b&gt;:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;type&lt;/span&gt;&lt;/b&gt; MyList = Empty | Nodo &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;of int&lt;/span&gt;&lt;/b&gt; * MyList;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In questo modo una variabile di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;MyList&lt;/span&gt; può assumere il valore &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Empty&lt;/span&gt;, che rappresenta la lista vuota, oppure un valore formato da una coppia da un valore di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int&lt;/span&gt; e uno di tipo &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;MyList&lt;/span&gt;&lt;/span&gt;. Concatenando in questo modo più valori è possibile creare una lista lunga a piacere di elementi. Ecco un esempio di come si può creare una lista di questo tipo:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; lista = Node(&lt;span style=&quot;color: magenta;&quot;&gt;1&lt;/span&gt;,Node(&lt;span style=&quot;color: magenta;&quot;&gt;2&lt;/span&gt;,Node(&lt;span style=&quot;color: magenta;&quot;&gt;3&lt;/span&gt;,Empty)));;&lt;/span&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
La particolarità di questo tipo di struttura è che possiamo aggiungere una quantità illimitata di elementi e in ogni momento abbiamo la possibilità di aggiungerne un&#39;altro, cosa molto utile nel caso in cui non sappiamo quanti elementi dobbiamo esaminare.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Tipi record&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I tipi record differiscono dagli altri due per il fatto che è più adatto a descrivere le caratteristiche di un determinato oggetto o soggetto, per esempio l&#39;eta, l&#39;altezza ed il peso di una persona, per cui utilizzando i tipi record possiamo racchiudere facilmente in un&#39;unica variabile delle grandezze che descrivono un determinato oggetto o soggetto. Giusto per fare un esempio di come vengono definiti i tipi record, cercheremo di creare un nuovo tipo che permetta di contenere le informazioni riguardanti il nome, l&#39;altezza e l&#39;età di una persona:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;type&lt;/span&gt;&lt;/b&gt; Persona = {nome: &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&lt;/b&gt;; altezza: &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;/b&gt;; eta: &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt;};;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Sostanzialmente abbiamo creato un nuovo tipo, chiamato &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Persona&lt;/span&gt;, che è caratterizzato da tre elementi: &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;nome&lt;/span&gt;&lt;/span&gt;, &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;altezza&lt;/span&gt;&lt;/span&gt; ed &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;eta&lt;/span&gt;&lt;/span&gt;. Ma a differenza dei tipi enumerati e quelli unione, se vogliamo creare una nuova variabile di tipo &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Persona&lt;/span&gt;&lt;/span&gt; dobbiamo inizializzare tutti i suoi attributi:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; p = {nome=&lt;span style=&quot;color: #990000;&quot;&gt;&quot;Tizio&quot;&lt;/span&gt;;altezza=&lt;span style=&quot;color: magenta;&quot;&gt;172.4&lt;/span&gt;;eta=&lt;span style=&quot;color: magenta;&quot;&gt;23&lt;/span&gt;};;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Bene, abbiamo visto come creare un tipo record, abbiamo anche visto come creare ed inizializzare una variabile del tipo creato, ma come fare ad utilizzare questi tipi nella programmazione? Per rispondere a questa domanda proviamo a scrivere una funzione che, data una lista di persone e dato il nome di una persona, ci restituisce una lista contenente tutte le persone che hanno il nome indicato:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let rec&lt;/span&gt;&lt;/b&gt; search lst x =&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;match&lt;/span&gt;&lt;/b&gt; lst &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;with&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | [] &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/b&gt; []&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | y::ys &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;-&amp;gt; if&lt;/b&gt;&lt;/span&gt; y.nome=x &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;then&lt;/span&gt;&lt;/b&gt; y::(search ys x)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(search ys x);;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Dal codice si può vedere che se la lista contiene almeno un elemento, la variabile locale y assume il valore del primo elemento della lista e visto che la lista è di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Persona&lt;/span&gt;, per conoscere il nome della prima persona della lista, viene usata la scrittura &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y.nome&lt;/span&gt;. In questo modo viene letto l&#39;attributo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;nome&lt;/span&gt; della persona corrispondente. Se viene trovata una corrispondenza tra il nome della persona della lista e il nome da cercare, la persona viene aggiunta in testa ad una nuova lista, che alla fine verrà restituita come risultato.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/4202581171803507766/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2012/01/f-tipi-derivati.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/4202581171803507766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/4202581171803507766'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2012/01/f-tipi-derivati.html' title='F# - Tipi derivati'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-6513154952607860303</id><published>2012-01-14T17:29:00.003+01:00</published><updated>2012-01-14T17:29:59.692+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Liste</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Al giorno d&#39;oggi programmando, molto spesso si imbatte nella necessità di &lt;b&gt;raggruppare&lt;/b&gt; più elementi dello &lt;b&gt;stesso tipo&lt;/b&gt;. Proprio in questi casi in &lt;b&gt;F#&lt;/b&gt; vengono usate le &lt;b&gt;liste&lt;/b&gt;, per memorizzare queste sequenze di elementi. Nei linguaggi di &lt;b&gt;programmazione procedurale&lt;/b&gt;, come &lt;b&gt;Java&lt;/b&gt; e &lt;b&gt;C++&lt;/b&gt;, queste strutture dati vengono chiamate &lt;b&gt;liste&lt;/b&gt; &lt;b&gt;concatenate&lt;/b&gt;, perché tra un elemento della lista e il suo successivo esiste un collegamento. &lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;Oltre alle liste esiste un&#39;altra struttura dati per raggruppare più elementi dello stesso tipo ed viene chiamata &lt;b&gt;array&lt;/b&gt;, però gli array hanno il grosso svantaggio di essere &lt;b&gt;limitati&lt;/b&gt;, perché una volta creato non può modificare la sua lunghezza.&lt;br /&gt;
Ma come segue dal titolo dell&#39;articolo, ci occuperemo dello studio delle liste e non degli array, per cui andiamo a vedere i modi in cui possono essere create le liste:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; lista = [];;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; lista2 = &lt;span style=&quot;color: magenta;&quot;&gt;0&lt;/span&gt;::&lt;span style=&quot;color: magenta;&quot;&gt;1&lt;/span&gt;::&lt;span style=&quot;color: magenta;&quot;&gt;2&lt;/span&gt;::lista;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; lista3 = [&lt;span style=&quot;color: magenta;&quot;&gt;3&lt;/span&gt;;&lt;span style=&quot;color: magenta;&quot;&gt;4&lt;/span&gt;;&lt;span style=&quot;color: magenta;&quot;&gt;5&lt;/span&gt;;&lt;span style=&quot;color: magenta;&quot;&gt;6&lt;/span&gt;];;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;let&lt;/b&gt;&lt;/span&gt; lista4 = lista2 @ lista3;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Con queste righe di codice abbiamo, sostanzialmente, creato 4 liste diverse. La prima lista non è altro che una &lt;b&gt;lista vuota&lt;/b&gt;, ovvero una lista che non contiene elementi e quindi è &lt;b&gt;lunga 0&lt;/b&gt;. Nella seconda riga di codice, invece, abbiamo usato l&#39;operazione di &lt;b&gt;concatenazione&lt;/b&gt; di elementi ad una lista, aggiungendo in testa alla prima lista gli elementi &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1&lt;/span&gt;&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;2&lt;/span&gt; e il risultato l&#39;abbiamo scritto in &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lista2&lt;/span&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;L&#39;operazione di concatenazione può essere usato soltanto per &lt;b&gt;aggiungere&lt;/b&gt; elementi in &lt;b&gt;testa&lt;/b&gt; alla lista e come &lt;b&gt;ultimo elemento&lt;/b&gt; della concatenazione deve per forza essere una &lt;b&gt;lista&lt;/b&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Con la terza riga del codice abbiamo creato una nuova lista, inserendo direttamente gli elementi al suo interno, mentre la quarta lista l&#39;abbiamo creata mediante la concatenazione della seconda e della terza lista, visto che l&#39;operatore &lt;span style=&quot;background-color: #ffd966; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;@&lt;/span&gt; permette di concatenare due liste, mettendo per primi gli elementi della prima lista, seguiti da quelli della seconda lista.&lt;br /&gt;
Molto spesso, lavorando con le liste sorge la necessità di suddividere la lista in &lt;b&gt;testa&lt;/b&gt; e c&lt;b&gt;oda&lt;/b&gt;, dove la testa rappresenta il primo elemento della lista, mente la coda rappresenta il resto della lista. Di seguito è riportato un esempio in cui viene fatto ciò:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; lista = [&lt;span style=&quot;color: magenta;&quot;&gt;1&lt;/span&gt;;&lt;span style=&quot;color: magenta;&quot;&gt;2&lt;/span&gt;;&lt;span style=&quot;color: magenta;&quot;&gt;3&lt;/span&gt;;&lt;span style=&quot;color: magenta;&quot;&gt;4&lt;/span&gt;];;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;let&lt;/b&gt;&lt;/span&gt; testa::coda = lista;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
In questi modo abbiamo detto all&#39;interprete di F# di assegnare al nome &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;testa&lt;/span&gt;&lt;/span&gt; il primo elemento di &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lista&lt;/span&gt;&lt;/span&gt; e di assegnare la coda di &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lista&lt;/span&gt;&lt;/span&gt; al nome &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;coda&lt;/span&gt;&lt;/span&gt;. Fare così è equivalente a spezzettare la lista originale in testa e coda, che spesso si rivela molto utile quando si scrivono funzioni ricorsive, che devono dare determinate operazioni sulle liste.&lt;br /&gt;
Proviamo a vedere un breve esempio di funzione, che determina la lunghezza di una lista. L&#39;idea risolutivo è quello di spezzettare la lista in testa e coda, dopodiché aggiungere 1 alla lunghezza della coda della lista:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let rec&lt;/span&gt;&lt;/b&gt; lunghezza lst =&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;match&lt;/span&gt;&lt;/b&gt; lst &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;with&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | [] &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/span&gt; &lt;span style=&quot;color: magenta;&quot;&gt;0&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | x::xs &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/b&gt; &lt;span style=&quot;color: magenta;&quot;&gt;1&lt;/span&gt; + (lunghezza xs);;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Come possiamo vedere, per la scrittura della funzione abbiamo usato il &lt;b&gt;pattern matching&lt;/b&gt;, in cui confrontiamo la lista, passata come argomento della funzione, con la lista vuota e con una lista, che contiene almeno un elemento. Con la scrittura &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x::xs&lt;/span&gt; viene la lista viene spezzettata, come è stato spiegato in precedenza, per cui richiamando la funzione stessa, passandogli &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;xs&lt;/span&gt; come argomento, è equivalente al richiamo della funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lunghezza&lt;/span&gt;&lt;/span&gt; sulla coda della lista &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lst&lt;/span&gt;. In questo modo primo o poi si arriva alla situazione in cui la lista &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lst&lt;/span&gt; è uguale alla lista vuota e quindi si chiude il ciclo. Ma aggiungere ad ogni passaggio 1 al risultato equivale al contare in quanti passaggi la lista si svuota, per cui viene trovata la lunghezza della lista.&lt;br /&gt;
Se proviamo ad analizzare i vari passaggi che esegue l&#39;interprete di F# per restituire il risultato della funzione in un esempio concreto otteniamo il seguente risultato:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lunghezza [1;2;3;4]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+(lunghezza [2;3;4])&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+(1+(lunghezza [3;4]))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+(1+(1+(lunghezza [4])))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+(1+(1+(1+(lunghezza []))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+(1+(1+(1+0)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+(1+(1+1))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+(1+2)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+3&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;4&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Dalla traccia riportata in alto si può vedere molto bene come ad ogni passaggio viene aumentato il numero dei &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;1+&lt;/span&gt;, mentre dalla lista viene eliminato il primo elemento. Inoltre, vediamo che il risultato restituito dalla funzione è 4, che è proprio la lunghezza della lista passata come argomento alla funzione, quindi possiamo affermare che la funzione è corretta.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/6513154952607860303/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2012/01/f-liste.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6513154952607860303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6513154952607860303'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2012/01/f-liste.html' title='F# - Liste'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-9180203803702108159</id><published>2012-01-13T22:19:00.000+01:00</published><updated>2012-01-13T22:21:50.280+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Web Server"/><title type='text'>Web Server - Installazione MySQL</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Spesso nella costruzione dei siti web c&#39;è la necessità di conservare dati, riguardanti gli utenti che utilizzano il vostro sito web, ma organizzando i dati sui file di testo è estremamente inefficace, specie nel momento in cui si deve cercare una particolare informazione. Il problema può essere risolto legando al sito un database, però per questo è necessario disporre di un &lt;b&gt;DBMS&lt;/b&gt;(DataBase Managment System), che ci servirà per gestire i database del sito. &lt;b&gt;MySQL&lt;/b&gt; è un DBMS molto usato per la gestione dei siti web, anche complessi, perché permette un interfacciamento molto semplice con &lt;b&gt;PHP&lt;/b&gt;.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Vediamo, allora, come si fa ad installare MySQL e a configurarlo per l&#39;interfacciamento con PHP. Prima di tutto scaricate il pacchetto di installazione, scaricabile gratuitamente da&amp;nbsp;&lt;a href=&quot;http://dev.mysql.com/downloads/installer/&quot; style=&quot;text-align: left;&quot; target=&quot;_blank&quot;&gt;http://dev.mysql.com/downloads/installer/&lt;/a&gt;, dopo aver selezionato il vostro sistema operativo. Dopodiché basta far partire l&#39;installatore e seguire i passi di installazioni, come descritto in basso:&lt;br /&gt;
&lt;br /&gt;
1. Non appena parte il programma di installazione viene visualizzato un menu, dal quale potete scegliere l&#39;operazione che volete eseguire, ma dato che vogliamo installare MySQL, dobbiamo scegliere la prima opzione: &quot;Install MySQL Products&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSMGbSEiLhPHmHcdpvu5N3Tl2feKYW5JXpMMCOliczWXCWjykhjzyJOUbFpTWT19-PgthxEaLclDrsDHkPSnqQHiEt2NP873mRwejuuWSIi4aiPpwl5UW62AosqWNtgMIkahKDReir2b8/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;298&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSMGbSEiLhPHmHcdpvu5N3Tl2feKYW5JXpMMCOliczWXCWjykhjzyJOUbFpTWT19-PgthxEaLclDrsDHkPSnqQHiEt2NP873mRwejuuWSIi4aiPpwl5UW62AosqWNtgMIkahKDReir2b8/s400/1.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2. Scelta l&#39;opzione di installazione del prodotto vi viene presentata la licenza del prodotto, che dovete leggere ed accettare se volete utilizzarlo, quindi dovete spuntare la casella in basso e andare avanti.&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0kvUasAUqC3bCmbeylF6vGIhzlhFV6_M5yK9qV3emSUGnFy_vmTXYuP7mawB3fU30pyCvn8sJgkdd0BQaGqIdyr87uxo9rM5FocBGy-yJywwtPKOZH0dsfTmjf6kuM0MweLVaJSJltRA/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0kvUasAUqC3bCmbeylF6vGIhzlhFV6_M5yK9qV3emSUGnFy_vmTXYuP7mawB3fU30pyCvn8sJgkdd0BQaGqIdyr87uxo9rM5FocBGy-yJywwtPKOZH0dsfTmjf6kuM0MweLVaJSJltRA/s400/2.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
3. Prima di procedere all&#39;installazione vi viene chiesto se volete verificare la presenza di versioni più recenti del prodotto, quindi se siete sicuri di utilizzare la versione più recente del programma potete deselezionare la casella in basso e procedere con l&#39;installazione.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFuewAD3LFHKiMBdud1dr_ULjGBYRpBPI-l3uF4yOYRHL5clTwFu2qkb0yAABK7f3hkyC2_BUeSRdgCES8qnWyyWuZn_zhW8E63ZgOWk98AA0TWHpK6b3afRzaQXuovU_xDgQzVwKULTw/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFuewAD3LFHKiMBdud1dr_ULjGBYRpBPI-l3uF4yOYRHL5clTwFu2qkb0yAABK7f3hkyC2_BUeSRdgCES8qnWyyWuZn_zhW8E63ZgOWk98AA0TWHpK6b3afRzaQXuovU_xDgQzVwKULTw/s400/3.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
4. A questo punto vi viene chiesto di selezionare il tipo di installazione che volete fare. Selezionando l&#39;opzione &quot;Developer Default&quot; verranno installati i componenti necessari per lo sviluppo, che possono essere utili per lo sviluppo di database per il web.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuh7FufNSfHh6oC7YSd9JfpHLTD2JOjPzX2c7VYh6-nh9az8PCT0JfRLdk6EN64AXXoRQ3qTSBpxdI3Ptl8BYwA7grRrpuupjt5PoA6TlOjZQCJApsHI7BNgHe0mFq3fY3vAKI6HRyQBc/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuh7FufNSfHh6oC7YSd9JfpHLTD2JOjPzX2c7VYh6-nh9az8PCT0JfRLdk6EN64AXXoRQ3qTSBpxdI3Ptl8BYwA7grRrpuupjt5PoA6TlOjZQCJApsHI7BNgHe0mFq3fY3vAKI6HRyQBc/s400/4.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
5. I componenti aggiuntivi possono richiedere l&#39;installazione di componenti aggiuntivi, necessari per il funzionamento delle utilità che andremo ad installare, quindi basta andare avanti e seguire i passi dell&#39;installazione guidata.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9nUe9NhC3Lv27yPbV9N8_MmEG4TT22wu56nX-cFnHt2-B5iCqqGJS1y9kGKuOXK3cHdSIspGpHDiV2P-MnDVttG_vaR_8LlBS2_w-gm0zIk5HNsMLswA18LxptQvepVhwyVmgdPb8cSk/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9nUe9NhC3Lv27yPbV9N8_MmEG4TT22wu56nX-cFnHt2-B5iCqqGJS1y9kGKuOXK3cHdSIspGpHDiV2P-MnDVttG_vaR_8LlBS2_w-gm0zIk5HNsMLswA18LxptQvepVhwyVmgdPb8cSk/s400/5.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
6. Questo passo dell&#39;installazione prevede l&#39;installazione dei componenti di MySQL e delle utilità scelte al quarto passaggio.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB0sQ0dbvEqhqVKfAC4eqmXGICZt0GgOxVFThOjE2LOWPtCGXqD6wS7QpIwGxMUxiTinq9Jh1AryNYI9td0zDgHWb1_PrjKBQ-hkdicQAAtphbniQWS-llsDiYRDJTXEjzxgqqLYWDKZk/s1600/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiB0sQ0dbvEqhqVKfAC4eqmXGICZt0GgOxVFThOjE2LOWPtCGXqD6wS7QpIwGxMUxiTinq9Jh1AryNYI9td0zDgHWb1_PrjKBQ-hkdicQAAtphbniQWS-llsDiYRDJTXEjzxgqqLYWDKZk/s400/7.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
7. Finita l&#39;installazione si procede con la configurazione di MySQL. Se seguente schermata ha il compito di visualizzare i componenti da configurare.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigvxE_XXlyQz8P4v5Og0wVU-jp3Sm9VbWxVZyNahwpeBM6RV4QGvzg6XSpLsv70UdQKUTnnlpwcCm_rimzIpSrF7KXc34ZGIbqgq6IUMOHNnd7IJuslJ1zQIkAwCkgYpnh0dQZCI-c28g/s1600/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigvxE_XXlyQz8P4v5Og0wVU-jp3Sm9VbWxVZyNahwpeBM6RV4QGvzg6XSpLsv70UdQKUTnnlpwcCm_rimzIpSrF7KXc34ZGIbqgq6IUMOHNnd7IJuslJ1zQIkAwCkgYpnh0dQZCI-c28g/s400/8.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
8. Questo passo della configurazione permette di decidere la quantità di risorse di sistema da attribuire al servizio MySQL, che potrà essere utilizzato in ogni momento. Selezionando la prima opzione, &quot;Developer Machine&quot;, si decide di dare poche risorse al servizio ed è la scelta migliore se il computer sul quale installate il prodotto lo utilizzerete anche per altri scopi. Le altre due opzioni permettono di attribuire al servizio sempre più risorse di sistema.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG9aGIKg9B-BBT-m3tuHjlH1i6pKCHSM0gAH3Qg7ydJ2HlrQTBi1OSfh_v9p_tiLZE8ihUNihGPN459HfVlF5BmYYebisiJrfzHnCAJYHKRJwRy9R0N5Z0y2YhI-6qm4udd4Q-QaWpyfo/s1600/9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiG9aGIKg9B-BBT-m3tuHjlH1i6pKCHSM0gAH3Qg7ydJ2HlrQTBi1OSfh_v9p_tiLZE8ihUNihGPN459HfVlF5BmYYebisiJrfzHnCAJYHKRJwRy9R0N5Z0y2YhI-6qm4udd4Q-QaWpyfo/s400/9.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
9. A questo punto dobbiamo impostare alcuni parametri funzionali del servizio MySQL. Andremo a modificare soltanto il terzo punto, nominato &quot;Security Settings&quot;, dove andremo a mettere una password per proteggere i database dalle persone non autorizzate. Dovete digitare la stessa password sia nella prima, che nella seconda casella di testo.&lt;br /&gt;
&lt;b&gt;N.B.&lt;/b&gt; &lt;b&gt;Se dimenticate la password non c&#39;è modo di recuperarla&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJjDVFPe-k84o9Ia-qiSZbQxxKt3EiQKNSaM0-NV0rS1mBMcLoVFjvF6M0UQmuy8D35A3zFSqwq1u_3UHZVOPZ_cG-ff_LhcMosXb5dM_snDkPNq7jUpxetHvD_XGn2fCyUKNclC8XdiQ/s1600/10.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJjDVFPe-k84o9Ia-qiSZbQxxKt3EiQKNSaM0-NV0rS1mBMcLoVFjvF6M0UQmuy8D35A3zFSqwq1u_3UHZVOPZ_cG-ff_LhcMosXb5dM_snDkPNq7jUpxetHvD_XGn2fCyUKNclC8XdiQ/s400/10.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
10. Finalmente l&#39;installazione è giunta alla fine e se viene visualizzata la schermata riportata in basso, allora l&#39;installazione è andata a buon fine e possiamo iniziare ad utilizzare MySQL.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEianovJa6BRfSlsrgUhWji_bTH60zqebwjFpHGKq1ovm139se7Rs41ysZ_kuGAHrzsd0WR30wXoLg8vBh-V6TLwMDsbGQeuZMpbsEwAryPt-MzAil7nOaqW9MDf599Hh7RG8mM_T2bKnVs/s1600/11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;297&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEianovJa6BRfSlsrgUhWji_bTH60zqebwjFpHGKq1ovm139se7Rs41ysZ_kuGAHrzsd0WR30wXoLg8vBh-V6TLwMDsbGQeuZMpbsEwAryPt-MzAil7nOaqW9MDf599Hh7RG8mM_T2bKnVs/s400/11.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Per verificare se MySQL funziona correttamente basta andare in &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Start-&amp;gt; Tutti i programmi-&amp;gt; MySQL-&amp;gt; MySQL Server x.x -&amp;gt; MySQL x.x Command Line Client&lt;/span&gt; (le x.x indicano la versione del prodotto). Verrà aperta una finestra di Prompt dei Comandi, dove vi verrà chiesta l&#39;immissione della password che avete scelto:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRPaLqQVO3lEzedXbnFDTtI4hXqWkTCI7iSpu2DfObxA0Y-FKTKxrrp2uN2W9UYRLjiVs9ultz7iqNbli1LeYtuITS28EiMU9R4vlYxaxNJTPn1Q4sFqBfLwhXfeYdfJt3BKfgF7BfN6o/s1600/cmd.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;256&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRPaLqQVO3lEzedXbnFDTtI4hXqWkTCI7iSpu2DfObxA0Y-FKTKxrrp2uN2W9UYRLjiVs9ultz7iqNbli1LeYtuITS28EiMU9R4vlYxaxNJTPn1Q4sFqBfLwhXfeYdfJt3BKfgF7BfN6o/s400/cmd.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Se avete inserito la password correttamente vi verrà mostrata la schermata che vedete sopra. Provate a eseguire i comandi riportati in basso:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;show databases;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Come risultato dovreste ottenere una tabella con i database già presenti nel DBMS:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXlevbMNPll3AiIqXECW10BVZBluBY45S8L5SWWry9h81S9vws-IJfKbqruILB7Q0B9if5nVyyRvAtuejIM5DUrXkOR07m5YrInMcw17b1Lr3eh13HOz7Cad9Wtu2UPCpcDIUpHG24i44/s1600/show_databases.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;258&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXlevbMNPll3AiIqXECW10BVZBluBY45S8L5SWWry9h81S9vws-IJfKbqruILB7Q0B9if5nVyyRvAtuejIM5DUrXkOR07m5YrInMcw17b1Lr3eh13HOz7Cad9Wtu2UPCpcDIUpHG24i44/s400/show_databases.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Per fare chiamate alle tabelle di un determinato database dovete prima scegliere il database, che volete caricare e dove si trova la tabella da voi cercata. Per fare ciò dovete inserire il seguente comando:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;use nomedatabase;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
dove al posto di &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;nomedatabase&lt;/span&gt; dovete inserire il nome del database che volete selezionare.&lt;br /&gt;
&lt;br /&gt;
Un&#39;ultima cosa riguardante la configurazione del interprete PHP. Se avete installato una delle ultime versioni di PHP, allora dovreste avere già abilitato il supporto di MySQL. Per verificare se MySQL è abilitato per le connessioni da PHP dovete caricare la pagina *.php creata per verificare la configurazione di PHP, che visualizza un elenco dei parametri di PHP. Se nella lista trovate anche la tabella che riguarda MySQL, allora la funzionalità è abilitata:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://4.bp.blogspot.com/-2DgS31UVYeI/TxCdgHGCVII/AAAAAAAAAJQ/t1VzGJs9HF0/s1600/php_mysql.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-2DgS31UVYeI/TxCdgHGCVII/AAAAAAAAAJQ/t1VzGJs9HF0/s1600/php_mysql.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Se, invece, non trovate questa tabella, allora dovete modificare il file di configurazione di PHP, nominato &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;php.ini&lt;/span&gt;&lt;/span&gt;. Esso dovrebbe trovarsi nella cartella &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;C:\Windows&lt;/span&gt; se avete installato una &lt;b&gt;versione obsoleta&lt;/b&gt; di PHP e in ogni caso dovreste avere una copia nella cartella di PHP, di default &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;C:\Programmi\PHP&lt;/span&gt;. Quello che dovete fare è togliere il simbolo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;;&lt;/span&gt; davanti alla riga:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;extension=php_mysql.dll&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
Fatto ciò dovrete riavviare il server web, nel nostro caso Apache e ricaricare la pagina web. Se tutto è andato a buon fine dovreste vedere anche la tabella riportata in alto.&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/9180203803702108159/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2012/01/web-server-installazione-mysql.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/9180203803702108159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/9180203803702108159'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2012/01/web-server-installazione-mysql.html' title='Web Server - Installazione MySQL'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSMGbSEiLhPHmHcdpvu5N3Tl2feKYW5JXpMMCOliczWXCWjykhjzyJOUbFpTWT19-PgthxEaLclDrsDHkPSnqQHiEt2NP873mRwejuuWSIi4aiPpwl5UW62AosqWNtgMIkahKDReir2b8/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-7462691665733768009</id><published>2012-01-13T00:03:00.001+01:00</published><updated>2012-01-13T00:07:39.794+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Ennuple</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Molto spesso programmando in qualsiasi linguaggio si verifica la necessità di raggruppare più variabili, anche di tipo diverso, che magari descrivono le caratteristiche di un determinato oggetto o soggetto. &lt;b&gt;F#&lt;/b&gt; propone una soluzione molto semplice a questo problema, utilizzando le così dette &lt;b&gt;ennuple&lt;/b&gt;. &lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Esse, in pratica, sono un raggruppamento di due o più valori, anche di tipo diverso. Molto spesso le ennuple vengono usate come l&#39;insieme dei parametri da passare ad una funzione. Per esempio, se vogliamo che nel momento in cui viene richiamata la nostra funzione vengano passati tutti i parametri assieme, basta usare una ennupla come argomento della funzione. Ma prima di scendere in dettagli vediamo come possono essere create ed utilizzate le ennuple in F#:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;let&lt;/b&gt;&lt;/span&gt; ennupla = (&lt;span style=&quot;color: magenta;&quot;&gt;65&lt;/span&gt;,&lt;span style=&quot;color: #990000;&quot;&gt;&#39;A&#39;&lt;/span&gt;);;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; annedate = (ennupla,(&lt;span style=&quot;color: magenta;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: magenta;&quot;&gt;3&lt;/span&gt;),&lt;span style=&quot;color: magenta;&quot;&gt;12&lt;/span&gt;);;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Come si può vedere dal codice, una ennupla viene creata utilizzando le &lt;b&gt;parentesi tonde&lt;/b&gt; e separando ogni elemento dall&#39;altro mediante la &lt;b&gt;virgola&lt;/b&gt;. Nella prima riga di codice vediamo una &lt;b&gt;coppia&lt;/b&gt; formata da un numero intero e un carattere. Con la seconda riga di codice, invece, abbiamo creato un&#39;ennupla formata da 3 elementi, di cui il primo non è altro che la coppia dichiarata in precedenza, il secondo elemento anch&#39;esso è una coppia, però questa volta di interi, mente il terzo elemento è un intero. E qui abbiamo visto che le ennuple possono essere annidate e lunghe quanto vogliamo, però una volta create non possono modificare la &lt;b&gt;dimensione&lt;/b&gt; e il &lt;b&gt;tipo&lt;/b&gt; degli elementi.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Vediamo un semplice esempio di come possono essere impiegate le ennuple. Supponiamo di voler scrivere una funzione, che restituisce il risultato di una &lt;b&gt;equazione di secondo grado&lt;/b&gt;, noti &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;a&lt;/span&gt;, &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;b&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;c&lt;/span&gt;. In quanto una equazione di secondo grado può avere al massimo 2 soluzioni, dobbiamo per forza restituire una &lt;b&gt;coppia&lt;/b&gt; di valori e quindi useremo le &lt;b&gt;ennuple&lt;/b&gt; per la scrittura della funzione:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; soluzioni (a:&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;/b&gt;) (b:&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;/b&gt;) (c:&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;float&lt;/b&gt;&lt;/span&gt;) =&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; d = b*b - &lt;span style=&quot;color: magenta;&quot;&gt;4.0&lt;/span&gt;*a*c &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;match&lt;/span&gt;&lt;/b&gt; d &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;with&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; d &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;when&lt;/span&gt;&lt;/b&gt; d&amp;lt;&lt;span style=&quot;color: magenta;&quot;&gt;0.0&lt;/span&gt; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/b&gt; failwith &lt;span style=&quot;color: #990000;&quot;&gt;&quot;l&#39;equazione non ha soluzioni in R&quot;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | &lt;span style=&quot;color: magenta;&quot;&gt;0.0&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/span&gt; ((-b-sqrt(d))/(&lt;span style=&quot;color: magenta;&quot;&gt;2.0&lt;/span&gt;*a),(-b-sqrt(d))/(&lt;span style=&quot;color: magenta;&quot;&gt;2.0&lt;/span&gt;*a))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; | d &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;when&lt;/span&gt;&lt;/b&gt; d&amp;gt;&lt;span style=&quot;color: magenta;&quot;&gt;0.0&lt;/span&gt; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/b&gt; ((-b-sqrt(d))/(&lt;span style=&quot;color: magenta;&quot;&gt;2.0&lt;/span&gt;*a),(-b-sqrt(d))/(&lt;span style=&quot;color: magenta;&quot;&gt;2.0&lt;/span&gt;*a));;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Proviamo ad esaminare il codice appena proposto. In pratica, abbiamo creato una funzione, che prende tre argomenti di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt;. In questo caso abbiamo forzato il tipo dei parametri, per non dover di seguito convertire ogni volta il tipo delle variabili, inoltre in questo modo otteniamo un valore più esatto. Un&#39;altra novità che introduce questo codice è la dichiarazione di una &lt;b&gt;variabile locale&lt;/b&gt; nella funzione. Ciò è stato fato utilizzando la solita parola chiave &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;let&lt;/span&gt;, seguita dalla dichiarazione del nome, dopodiché segue la parola chiave &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;in&lt;/span&gt;, che indica la fine della dichiarazione. Dopo aver introdotto il nuovo nome, che abbiamo chiamato &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;d&lt;/span&gt;, abbiamo attribuito ad esso il valore del &lt;b&gt;discriminante&lt;/b&gt; dell&#39;equazione.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Utilizzando il pattern matching abbiamo definito i tre casi, ovvero quando &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;d&amp;gt;0&lt;/span&gt;, quando &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;d&amp;lt;0&lt;/span&gt; e quando &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;d=0&lt;/span&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Nel caso in cui &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;d&amp;lt;0&lt;/span&gt; verrà generata un&#39;&lt;b&gt;eccezione&lt;/b&gt;, ovvero un messaggio in output, che indicherà che l&#39;equazione con quei parametri non ha soluzione dell&#39;insieme dei reali. Questa decisione è stata presa perché una funzione può restituire un valore di un solo tipo e non sarebbe molto corretto restituire una coppia di reali.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Se il discriminante, invece, vale 0, allora l&#39;equazione ha un&#39;unica soluzione, o meglio, le due soluzioni coincidono, per cui restituiamo una coppia di numeri &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt; uguali.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Finalmente, nel caso in cui &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;d&amp;gt;0&lt;/span&gt; l&#39;equazione ha due soluzioni, per cui viene restituita rispettivamente una coppia di numeri &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt;. Per il calcolo delle soluzioni è stata utilizzata, inoltre, la funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sqrt&lt;/span&gt;, una funzione predefinita di &lt;b&gt;F#&lt;/b&gt;, che serve per calcolare la &lt;b&gt;radice quadrata&lt;/b&gt; di un numero &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt;&lt;/span&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Se proviamo a vedere lo stampo di questa funzione, eseguendo il codice in alto, utilizzando l&#39;interprete di &lt;b&gt;F#&lt;/b&gt;, otterremo il seguente output:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;val soluzioni : float -&amp;gt; float -&amp;gt; float -&amp;gt; float * float&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Come possiamo vedere, eseguendo il codice viene introdotta una nuova funzione, chiamata soluzioni, che prende tre argomenti di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt;. Come risultato essa restituisce una coppia di &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt; e visto che &lt;b&gt;F#&lt;/b&gt; è un linguaggio che ha un forte legame con il linguaggio matematico, l&#39;insieme delle soluzioni viene rappresentata come il prodotto dell&#39;insieme dei reali per se stesso, ovvero &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float*float&lt;/span&gt;.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/7462691665733768009/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2012/01/f-ennuple.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/7462691665733768009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/7462691665733768009'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2012/01/f-ennuple.html' title='F# - Ennuple'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-673902758350637381</id><published>2012-01-05T17:24:00.008+01:00</published><updated>2012-01-05T17:39:11.361+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Web Server"/><title type='text'>Web Server - Installazione PHP</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Fino ad ora abbiamo visto come installare il server web, per inviare la corrispondente pagina html, quando essa viene richiesta da un client. Ma in questo modo possiamo avere soltanto le pagine statiche, che potrebbero essere utili soltanto per depositare informazioni sul nostro sito e non avremo la possibilità di fare uno scambio di dati con l&#39;utente. &lt;/div&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;text-align: justify;&quot;&gt;Il problema si risolve utilizzando un linguaggio di programmazione come PHP, usato sul lato server, che permette di generare le pagine html a seconda della richiesta che viene fatta. Inoltre, in questo modo potremmo utilizzare anche un database, per gestire i dati degli utenti del nostro sito. Ma prima di utilizzare questo linguaggio di programmazione, dobbiamo installare un suo interprete e configurarlo in modo che Apache sappia utilizzare quel interprete.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;L&#39;&lt;b&gt;interprete&lt;/b&gt;&amp;nbsp;di un linguaggio di programmazione è un programma, che decodifica&amp;nbsp;&lt;b&gt;al volo&lt;/b&gt;&amp;nbsp;il codice scritto nel corrispondente linguaggio di programmazione e esegue le istruzioni decodificate. Anche nel caso di&amp;nbsp;&lt;b&gt;PHP&lt;/b&gt;&amp;nbsp;abbiamo un&amp;nbsp;&lt;b&gt;interprete&lt;/b&gt;, che decodifica le pagine&amp;nbsp;&lt;b&gt;*.php&lt;/b&gt;, eseguendo le istruzioni trovate nella pagina e restituendo come output una pagina *.&lt;b&gt;html&lt;/b&gt;. In altre parole, quando verrà richiamata una pagina di estensione *.php, l&#39;interprete eseguirà le istruzione&amp;nbsp;&lt;b&gt;PHP&lt;/b&gt;&amp;nbsp;presenti in quel file e restituirà una pagina&amp;nbsp;&lt;b&gt;*.html&lt;/b&gt;, che verrà inviata al client. In questo modo potremmo alla stessa chiamata rispondere con una pagina completamente diversa.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ma, come è stato detto, abbiamo bisogna dell&#39;interprete PHP. Per chi utilizza il sistema operativo Windows, lo può scaricare da&amp;nbsp;&lt;a href=&quot;http://windows.php.net/download/&quot; target=&quot;_blank&quot;&gt;http://windows.php.net/download/&lt;/a&gt;, mentre per gli altri sistemi operativi, lo potete scaricare da&amp;nbsp;&lt;a href=&quot;http://php.net/downloads.php&quot; target=&quot;_blank&quot;&gt;http://php.net/downloads.php&lt;/a&gt;. Se avete deciso di scaricare l&#39;archivio, allora lo dovete scompattare in una cartella, preferibilmente in modo da avere un percorso della cartella più corto(es.&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;C:\php\&lt;/span&gt;), mentre se avete scaricato il pacchetto di installazione di PHP, allora basta seguire le indicazioni del installatore:&lt;br /&gt;
&lt;br /&gt;
1. Viene visualizzata la schermata iniziale con la versione dell&#39;interprete e qualche sugerimento.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBbAfTC-N7MWt4sg5tkDPP0oN5bkJbTexY50FjEwQiKLoa92Kp3xwS_zdTjlBO3SIcskbpH_MWs6dyFDuHf0p5kZdWRBPzzVjlu3DSde10dqnprdjqfKC_QfmRkUdOdLOlZql6jcxQO3M/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBbAfTC-N7MWt4sg5tkDPP0oN5bkJbTexY50FjEwQiKLoa92Kp3xwS_zdTjlBO3SIcskbpH_MWs6dyFDuHf0p5kZdWRBPzzVjlu3DSde10dqnprdjqfKC_QfmRkUdOdLOlZql6jcxQO3M/s1600/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&amp;nbsp;2. Dopo aver letto i termini e le condizioni della licenza dovete spuntare le casella in basso, per indicare che accettate le condizioni della licenza. Questo è necessario per installare il programma.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT3N5lx2wkWmjlQrc_UzibS27-kfTEFv2_ocsuIc6WSY2qhzIGPzaqKVdHIjtELrAW2hdrIms7VWhz5J8mUL81CAK76kCXC5ZghNQjGo2ldQ51jp-VYNVRLDLezcuhyphenhyphenq5gex7vhFPvkKQ/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiT3N5lx2wkWmjlQrc_UzibS27-kfTEFv2_ocsuIc6WSY2qhzIGPzaqKVdHIjtELrAW2hdrIms7VWhz5J8mUL81CAK76kCXC5ZghNQjGo2ldQ51jp-VYNVRLDLezcuhyphenhyphenq5gex7vhFPvkKQ/s1600/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
3. Scegliete la cartella dove volete installare l&#39;interprete e ricordatevela, perché ci servirà in seguito per configurare Apache.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL5WHj_jcAuJjlpHdo6CMOIrqSbdRLa6GE4xQ0WdDr-Ut92qVk48KXyL8f2o16WjqRdl1uH0DhuMD-l5AbyS6cP8io_5VL4PD89W_2kL9CuC1oxpNV_m51nbkXPvvJNoqe27_M9iiCaXA/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgL5WHj_jcAuJjlpHdo6CMOIrqSbdRLa6GE4xQ0WdDr-Ut92qVk48KXyL8f2o16WjqRdl1uH0DhuMD-l5AbyS6cP8io_5VL4PD89W_2kL9CuC1oxpNV_m51nbkXPvvJNoqe27_M9iiCaXA/s1600/3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
4. Scegliamo il tipo di server che vogliamo configurare, nel nostro caso è&amp;nbsp;&lt;b&gt;Apache 2.2.x Module&lt;/b&gt;.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_hDvk_PxwRnN8sr_KGrF4qDY8VBO9vMMW2PkRGu3oVhBUEuVXNjSalttmajdm1TLDJil6kJnqDOjF5BhjC3PIKFusF7zAQBDrY5U1BGwKUBqZNr5DYKaQKWlAGj8wF76TLGrly_Adcgc/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_hDvk_PxwRnN8sr_KGrF4qDY8VBO9vMMW2PkRGu3oVhBUEuVXNjSalttmajdm1TLDJil6kJnqDOjF5BhjC3PIKFusF7zAQBDrY5U1BGwKUBqZNr5DYKaQKWlAGj8wF76TLGrly_Adcgc/s1600/4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
5. A questo punto dobbiamo scegliere la cartella dove è installato Apache.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgKRojz3nsJLqrRORGiNMInC426CfIj9lQhVkW2E9CjpcuMcI9eRlpPsmJlAmewN7QdwjAhPFpLXXcdkwx2EcKnHpA3QzmyIFqApe3HDU0dvzsEvsNaiIiKhFt48nmm-Kr_5wAYqnene8/s1600/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgKRojz3nsJLqrRORGiNMInC426CfIj9lQhVkW2E9CjpcuMcI9eRlpPsmJlAmewN7QdwjAhPFpLXXcdkwx2EcKnHpA3QzmyIFqApe3HDU0dvzsEvsNaiIiKhFt48nmm-Kr_5wAYqnene8/s1600/8.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
6. Scegliete i componenti che volete installare. Potete lasciare anche la configurazione iniziale.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJQfuE0fY8XL1LSM1HPXRBO8ETc6h4KTgEUWHtX0sqjdZtzANYxcYx33hQi-ws3IQEQYhEdtYzaYZTKqDRHTwSUnhU36tCcrexUH2chhZQjDHeKVmV9A94INRYp07mef6Z9cmqpIIi-ZE/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJQfuE0fY8XL1LSM1HPXRBO8ETc6h4KTgEUWHtX0sqjdZtzANYxcYx33hQi-ws3IQEQYhEdtYzaYZTKqDRHTwSUnhU36tCcrexUH2chhZQjDHeKVmV9A94INRYp07mef6Z9cmqpIIi-ZE/s1600/5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
7. Confermate l&#39;installazione e l&#39;installatore farà il suo lavoro in automatico, configurando anche Apache.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidAhjByeqCGyDd0FoxRVV81PfiBZZnCrMFBbEhdN6mqX2DWaUyavgUxkTNej97G2NTedE8XRfYirAOVVi46o_QDIpdXubumVSE0DWPRKpI_V47Wi3T_wYyzyRAQM-pU-RDE8ah8BgNV2w/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidAhjByeqCGyDd0FoxRVV81PfiBZZnCrMFBbEhdN6mqX2DWaUyavgUxkTNej97G2NTedE8XRfYirAOVVi46o_QDIpdXubumVSE0DWPRKpI_V47Wi3T_wYyzyRAQM-pU-RDE8ah8BgNV2w/s1600/6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
8. Se tutto è andato a buon fine, verrà visualizzata la schermata finale con il messaggio di successo.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuLHVkwWiRjfinPs6zbaT1J8iJ15LRqpiQ0QZYq8W2vVR7bckMhCKC7GYev3fz5tba975rVyZQ1RgDU3tjfoIzgI8sOzdblOF4y4mZea-Q_9wrVhGgW6OX0Y35Qq6KSxGJXMAD98Oo0hM/s1600/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuLHVkwWiRjfinPs6zbaT1J8iJ15LRqpiQ0QZYq8W2vVR7bckMhCKC7GYev3fz5tba975rVyZQ1RgDU3tjfoIzgI8sOzdblOF4y4mZea-Q_9wrVhGgW6OX0Y35Qq6KSxGJXMAD98Oo0hM/s1600/7.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Adesso abbiamo completato l&#39;installazione e il nostro server è completamente funzionante. Per provare se il server funziona correttamente, creiamo un nuovo file di estensione&amp;nbsp;&lt;b&gt;*.php&lt;/b&gt;&amp;nbsp;e dentro scriviamo il seguente codice:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;?php phpinfo(); ?&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Il file deve essere copiato nella cartella delle pagine web, che avete indicato durante la configurazione di Apache (di default&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;htdocs&lt;/span&gt;), dopodiché richiamato dal browser, digitando nella barra degli indirizzi&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;http://localhost/nome_file.php&lt;/span&gt;. Come risultato dovreste ottenere una tabella con i dettagli della configurazione di PHP:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq1ZUalRtXCM2T0XpcKifTUV8GxvIkwhoepRJV8e-G2eEViuYigQj8Ytc7tHqGkQOgSRQxx254ZRCjs-TPDvRF_AD7tnLZrNy_tSJ9CxH5MEwIZspGo207EZZiTWNywOmUa7uU2fcgQ3o/s1600/phpinfo.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;301&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgq1ZUalRtXCM2T0XpcKifTUV8GxvIkwhoepRJV8e-G2eEViuYigQj8Ytc7tHqGkQOgSRQxx254ZRCjs-TPDvRF_AD7tnLZrNy_tSJ9CxH5MEwIZspGo207EZZiTWNywOmUa7uU2fcgQ3o/s400/phpinfo.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Con questo si conclude l&#39;installazione e la configurazione di PHP.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/673902758350637381/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2012/01/varie-installazione-php.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/673902758350637381'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/673902758350637381'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2012/01/varie-installazione-php.html' title='Web Server - Installazione PHP'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBbAfTC-N7MWt4sg5tkDPP0oN5bkJbTexY50FjEwQiKLoa92Kp3xwS_zdTjlBO3SIcskbpH_MWs6dyFDuHf0p5kZdWRBPzzVjlu3DSde10dqnprdjqfKC_QfmRkUdOdLOlZql6jcxQO3M/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-5176766246857893178</id><published>2012-01-05T17:24:00.007+01:00</published><updated>2012-01-05T17:39:00.087+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Web Server"/><title type='text'>Web Server - Installazione Apache</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Al giorno d&#39;oggi l&#39;&lt;b&gt;Internet&lt;/b&gt; è diventato una risorsa molto importante del mondo intero, ma per molti ancora resta un mistero il funzionamento di tale sistema. Il tutto, in fondo, non è così complicato come potrebbe sembrare, se si cerca di astrarre un po&#39; le varie parti di questo sistema, ignorando la struttura di esse e pensando soltanto alle operazioni che esse svolgono.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In generale l&#39;&lt;b&gt;Interne&lt;/b&gt;t può essere pensato come un enorme &lt;b&gt;graffo&lt;/b&gt;, ovvero una struttura fatta di &lt;b&gt;nodi&lt;/b&gt; e di &lt;b&gt;archi&lt;/b&gt;, dove ogni nodo rappresenta un &lt;b&gt;computer&lt;/b&gt; e ogni arco rappresenta un &lt;b&gt;collegamento&lt;/b&gt; tra due computer. Ma non tutti i nodi sono uguali, perché ci sono computer che fanno richiesta di un servizio e vengono chiamati &lt;b&gt;client&lt;/b&gt;, mentre altri sono fatti per fornire i servizi richiesti e vengono chiamati &lt;b&gt;server&lt;/b&gt;. Quindi nel momento in cui proviamo a collegarci all&#39;Internet e vogliamo andare su un determinato sito, il nostro computer è un &lt;b&gt;client&lt;/b&gt; e il computer, sul quale si trova il sito web rappresenta un &lt;b&gt;server&lt;/b&gt;, che ci fornisce un servizio, inviandoci la pagina ipertestuale corrispondente.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Normalmente i computer sono dei client e vengono utilizzati per richiedere servizi, ma installando un programma come &lt;b&gt;Apache&lt;/b&gt; possiamo rendere il nostro computer anche un server e quindi esso potrà sia richiedere servizi, che fornirli.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Installazione Apache&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Come abbiamo visto, installando Apache possiamo fare in modo di avere un server sul nostro computer. Installando Apache, noi sostanzialmente creiamo un servizio sul nostro computer, che nel momento in cui viene fatta una richiesta, cerca in una cartella da noi indicata la pagina web richiesta e una volta trovata la invia al cliente che l&#39;ha richiesta.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;L&#39;installazione di questo programma è molto semplice, perché basta seguire i passaggi dell&#39;installatore, che farà tutto. Quindi dovete per prima cosa procurarvi il pacchetto di installazione o l&#39;archivio di Apache, che lo potete scaricare gratuitamente da&amp;nbsp;&lt;a href=&quot;http://httpd.apache.org/download.cgi#apache22&quot; style=&quot;text-align: left;&quot; target=&quot;_blank&quot;&gt;http://httpd.apache.org/download.cgi#apache22&lt;/a&gt;, scegliendo l&#39;archivio, oppure il pacchetto corrispondente al vostro sistema operativo. In ogni caso vi consiglio di scaricare il pacchetto di installazione, perché è più semplice l&#39;installazione. L&#39;installazione avviene in 9 passaggi:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;1. Al primo passaggio appare la schermata iniziale con la versione del programma.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZuOpeLvpR_g2mQpIbFT8oS-dyG47v6vLCPbyDRV8fqeAA94nbIdd6Mj9AqdPswFdu30QkbCcCeJyzHQhohXrFp69o-W5i3WKDXDM0oXdqtO0edsyFvWF5TD0D2hTIEVw98r578_rlETU/s1600/1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZuOpeLvpR_g2mQpIbFT8oS-dyG47v6vLCPbyDRV8fqeAA94nbIdd6Mj9AqdPswFdu30QkbCcCeJyzHQhohXrFp69o-W5i3WKDXDM0oXdqtO0edsyFvWF5TD0D2hTIEVw98r578_rlETU/s1600/1.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;2. Dopodiché viene visualizzata la licenza del programma, che dovette accettare per poter installare il programma. In questo modo accettate di rispettare i termini e le condizioni di questo prodotto.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv4jdy5SQGoUL2X7gifmKoHeWIT8MiRgAkMSZMuXzTQf8q0YbTutCo8ERCCvbdo1pE3Nm8vR0FtvxCwtEO59iA5GZOB9X3JF8v6qV6hvIrYeYnaUo4SvC0yr7WLYp1fKoFyWcFbGQfMv0/s1600/2.png&quot; imageanchor=&quot;1&quot; style=&quot;display: inline !important; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhv4jdy5SQGoUL2X7gifmKoHeWIT8MiRgAkMSZMuXzTQf8q0YbTutCo8ERCCvbdo1pE3Nm8vR0FtvxCwtEO59iA5GZOB9X3JF8v6qV6hvIrYeYnaUo4SvC0yr7WLYp1fKoFyWcFbGQfMv0/s1600/2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;3. Viene visualizzata una breve descrizione del software e sul suo funzionamento.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvaT79gAuobo7YS8-UZaEUO3dqUrlOPIuBDYzZLJmNFKF10tGPmV6ZnBG9dWCSeBNxfMX78Tj9n9jyjnSvH-vJGGCaONka-7kbLe6q99UVwqhDpWEw4Nm2NHUOqQKQSjsIp70r_X9iMOc/s1600/3.png&quot; imageanchor=&quot;1&quot; style=&quot;display: inline !important; margin-left: 1em; margin-right: 1em; text-align: left;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgvaT79gAuobo7YS8-UZaEUO3dqUrlOPIuBDYzZLJmNFKF10tGPmV6ZnBG9dWCSeBNxfMX78Tj9n9jyjnSvH-vJGGCaONka-7kbLe6q99UVwqhDpWEw4Nm2NHUOqQKQSjsIp70r_X9iMOc/s1600/3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&amp;nbsp;&lt;span style=&quot;text-align: left;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;4. A questo passaggio dovete indicare le vostre preferenze riguardanti il &lt;b&gt;nome del server&lt;/b&gt; e il suo &lt;b&gt;dominio&lt;/b&gt;. Nell&#39;immagine ho indicato&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;localhost&lt;/span&gt;, in quanto questo server sarà visibile con questo nome soltanto dal vostro computer. In ogni caso questi nomi sono modificabili anche dal file di configurazione di Apache, però la modifica di quel file è consigliabile soltanto se avete un po&#39; di esperienza con la configurazione di Apache, perché si rischia di rendere il programma non funzionante.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf7jekiGM4Xxz_uOkZ1VVWeTuXTKWK0xY05pWtHN8U6hOkvrC6KlSkCz9gqjKxBT2hibEN0WmsAS_q7rgaVhfXlRu65ShS55KFheBW-y8Cimq5kukNhGXthNBcXxf-xVYcKZx_MEftjY0/s1600/4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf7jekiGM4Xxz_uOkZ1VVWeTuXTKWK0xY05pWtHN8U6hOkvrC6KlSkCz9gqjKxBT2hibEN0WmsAS_q7rgaVhfXlRu65ShS55KFheBW-y8Cimq5kukNhGXthNBcXxf-xVYcKZx_MEftjY0/s1600/4.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
5. Scegliendo &lt;b&gt;Typical&lt;/b&gt;, il programma verrà installato con le componenti e la configurazione standard.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR3bGzJ7tq-uWYwMRLF2Z0Y4E0P958d6BB9xEIN4IKL1ze3upcOoIQmFJ7dur6D0R44cYFdmr6onuXorrh4qb-tBmqpNtixIMpJBu1187f3k0T7LaCLA_1M4r1RqF9aAmrcdxvRniFLT4/s1600/5.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR3bGzJ7tq-uWYwMRLF2Z0Y4E0P958d6BB9xEIN4IKL1ze3upcOoIQmFJ7dur6D0R44cYFdmr6onuXorrh4qb-tBmqpNtixIMpJBu1187f3k0T7LaCLA_1M4r1RqF9aAmrcdxvRniFLT4/s1600/5.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
6. Qui potete scegliere la cartella nella quale volete installare Apache.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh26WqmCKdwYEs7DfEfe-TKOKD6sVfwDJdvXbfd4noi38z02ApEvUBNIeW1y6nhWCKstXEjJxXVpMpni3ZpU1_LOUgwwormIzjgxA3Rl9HdYyyVUKSsq3Ltp0E8sPCovQBWeTzAIvnhVMc/s1600/6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh26WqmCKdwYEs7DfEfe-TKOKD6sVfwDJdvXbfd4noi38z02ApEvUBNIeW1y6nhWCKstXEjJxXVpMpni3ZpU1_LOUgwwormIzjgxA3Rl9HdYyyVUKSsq3Ltp0E8sPCovQBWeTzAIvnhVMc/s1600/6.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
7. A questo punto dovete confermare l&#39;installazione.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI2NUbfgFJvesWm9RDUjGBEMUQ_PUZGS7dX9E9XM9FWBfLb31LTDrabKrxWn965E-_WuFHaud98IuX2d2FA-22IPFHN7h-Pm2R2twotQNk2xvB5pWWMgHY20JrUKlhvpkDu_VilzDmrJ4/s1600/7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI2NUbfgFJvesWm9RDUjGBEMUQ_PUZGS7dX9E9XM9FWBfLb31LTDrabKrxWn965E-_WuFHaud98IuX2d2FA-22IPFHN7h-Pm2R2twotQNk2xvB5pWWMgHY20JrUKlhvpkDu_VilzDmrJ4/s1600/7.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
8. L&#39;installazione partirà automaticamente e durerà qualche minuto.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFMc5-63zkhqtFK8cOOx_mbGloaSRkqw2jiOllc58kfReBEiWpxF1bXI5k5oIc-_PTinLpi9HsBAKzMWypbrQTNJ-3kSh2nZW-8EV8btW-B9l3jZfLgYF9yt1Rky1mI4sLURDHDxhGRiw/s1600/8.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFMc5-63zkhqtFK8cOOx_mbGloaSRkqw2jiOllc58kfReBEiWpxF1bXI5k5oIc-_PTinLpi9HsBAKzMWypbrQTNJ-3kSh2nZW-8EV8btW-B9l3jZfLgYF9yt1Rky1mI4sLURDHDxhGRiw/s1600/8.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
9. L&#39;installazione è stata completata e potete vedere il risultato dell&#39;installazione.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYrfrlf8_i9_58pGPxbpfNxIX-swMsn7_ydKUOjP0kx86aQkvSA_dQ3Yxh0jAx4dZXQtBoLXE7vwAF0aaIj8GKAu2Ze4-SWCNf85cbo3UUrOVlRaODqzABuAPUxHPftrU2kmKXzLuLZ4I/s1600/9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYrfrlf8_i9_58pGPxbpfNxIX-swMsn7_ydKUOjP0kx86aQkvSA_dQ3Yxh0jAx4dZXQtBoLXE7vwAF0aaIj8GKAu2Ze4-SWCNf85cbo3UUrOVlRaODqzABuAPUxHPftrU2kmKXzLuLZ4I/s1600/9.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Una volta installato Apache, il server dovrebbe già essere funzionante, se tutto è andato a buon fine. Per verificare che tutto funziona correttamente, basta aprire il browser e digitare il nome del dominio, che nel mio caso è &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;http://localhost&lt;/span&gt; . Come risposta dovreste ottenere il seguente risultato:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZOxGz4cXbOejXStFSU5hyphenhyphenNmjqO3ytE9Rb9dzx881XAbqP3wf2KxD6jEC_BxlQP2ppEw1tF8n-jXdB3Ftp761zRDdYarD-9KQKZtFadM5Ub9i-fuHmV9Bla8WVIKn9RkwARUHR5_7GkTc/s1600/it_works.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZOxGz4cXbOejXStFSU5hyphenhyphenNmjqO3ytE9Rb9dzx881XAbqP3wf2KxD6jEC_BxlQP2ppEw1tF8n-jXdB3Ftp761zRDdYarD-9KQKZtFadM5Ub9i-fuHmV9Bla8WVIKn9RkwARUHR5_7GkTc/s1600/it_works.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Il browser dovrebbe caricare una pagina predefinita, chiamata &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;index.html&lt;/span&gt;, che si trova all&#39;interno della cartella dove è stato installato Apache, dentro la cartella &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;htdocs&lt;/span&gt;. Per rendere visibili anche altre pagine web, dovete metterle in questa cartella. Dal browser potrete richiedere i file, indicando i loro nomi dopo il nome del dominio (es. &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;http://localhost/mio_file.html&lt;/span&gt;). Inoltre, è preferibile che non usiate gli spazi nei nomi dei file, perché alcuni browser potrebbero non capire il nome del file da richiedere.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Un&#39;altra cosa, che potrebbe essere scomoda, è che i documenti che stanno sul server devono trovarsi nella cartella &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;htdocs&lt;/span&gt;, non accessibile in pochi click. Ma modificando la configurazione di Apache, possiamo modificare anche la posizione della cartella delle pagine web.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Per fare ciò dobbiamo modificare il file&lt;span style=&quot;background-color: white; font-family: inherit;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;httpd.con&lt;/span&gt;f, che si trova nella cartella &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;conf&lt;/span&gt; della cartella di Apache. Il file può essere modificato anche con blocco note. Nel file trovate la riga&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DocumentRoot &quot;C:/Program Files/Apache Software Foundation/Apache2.2/htdocs&quot;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;e sostituite la parte tra apici con la posizione della cartella, nella quale volete mettere le pagine web. La posizione della cartella la potete copiare dalla barra degli indirizzi:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnIusni_WjP_C8sigwlr42o2kuvQpbgSgt3gOf9YWmX-OGe7J47sRXMUpCIImvHqLDz6tT4Ou89GhyphenhyphenSP1yKTPikK7SIPV5Mqtf_dcQlhDtHWG-BWsO_KJpgekrnWDAOKSSWpr-BqqKXQQ/s1600/posizione_cartella.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnIusni_WjP_C8sigwlr42o2kuvQpbgSgt3gOf9YWmX-OGe7J47sRXMUpCIImvHqLDz6tT4Ou89GhyphenhyphenSP1yKTPikK7SIPV5Mqtf_dcQlhDtHWG-BWsO_KJpgekrnWDAOKSSWpr-BqqKXQQ/s1600/posizione_cartella.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Però dovete fare attenzione ad usare le &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/&lt;/span&gt; e non le &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;\&lt;/span&gt; per indicare la posizione. Nel mio caso dovrei sostituire il testo sopra indicato con:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DocumentRoot &quot;C:/Users/Administrator/Desktop/web&quot;&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;
In questo modo potrete accedere alla cartella con le pagine web da un posto più accessibile.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/5176766246857893178/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2012/01/varie-installazione-apache.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/5176766246857893178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/5176766246857893178'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2012/01/varie-installazione-apache.html' title='Web Server - Installazione Apache'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZuOpeLvpR_g2mQpIbFT8oS-dyG47v6vLCPbyDRV8fqeAA94nbIdd6Mj9AqdPswFdu30QkbCcCeJyzHQhohXrFp69o-W5i3WKDXDM0oXdqtO0edsyFvWF5TD0D2hTIEVw98r578_rlETU/s72-c/1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-6018226290791421592</id><published>2012-01-03T15:33:00.000+01:00</published><updated>2012-01-03T15:33:22.540+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><title type='text'>HTML - Hello, World!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Fino ad ora si è parlato su come può essere impiegato il linguaggio di programmazione&lt;b&gt; HTML&lt;/b&gt; e su come deve essere la struttura di un documento ipertestuale, scritto in questo linguaggio. Ma vediamo ora come procedere per creare la più semplice pagina, che dovrà contenere il messaggio &lt;b&gt;&quot;Hello, World!&quot;&lt;/b&gt;.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Beh, per creare in &lt;b&gt;HTML&lt;/b&gt; una pagina che scriva un messaggio non ci vuole molto, perché una volta scritti i tag della struttura della pagina, basta inserire nel corpo il testo del messaggio che vogliamo visualizzare:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Hello, World!&lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Hello, World!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Per vedere il risultato può essere utilizzato anche un semplice&amp;nbsp;&lt;b&gt;editor di testo&lt;/b&gt;, va bene anche &lt;b&gt;blocco note&lt;/b&gt;, basta che salviate il documento come file&lt;b&gt; *.html.&lt;/b&gt; Quindi se usate blocco note, dopo aver inserito il codice, andate su &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;File-&amp;gt;Salva con nome...&lt;/span&gt; &amp;nbsp;e scegliete di salvare come tutti i file. Nella casella di testo inserite il nome che volete, seguito da&lt;b&gt; .html&amp;nbsp;&lt;/b&gt;(es. hello.html)&amp;nbsp;e il gioco è fatto. Adesso per vedere il risultato, è sufficiente aprire il file creato con un doppiò click e il file verrà aperto come documento ipertestuale nel browser predefinito installato sul computer. Il risultato che dovreste vedere dovrebbe essere il seguente:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4m0A1KAFLS5b-lcUmWekO0lOz0QzWrrj79DkttIzjaROa3sjaji7npwxN8QgEDycudPwtMIFJMVY6_PJfS2MSpgpFRwDlDvvmUfisBx0HrzySFnRi7OwsyeQyEJzGdSPzwuSiII0x-yM/s1600/hello_world_html.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4m0A1KAFLS5b-lcUmWekO0lOz0QzWrrj79DkttIzjaROa3sjaji7npwxN8QgEDycudPwtMIFJMVY6_PJfS2MSpgpFRwDlDvvmUfisBx0HrzySFnRi7OwsyeQyEJzGdSPzwuSiII0x-yM/s1600/hello_world_html.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Come potete osservare abbiamo creato un documento HTML, che scrive &lt;b&gt;&quot;Hello, World!&quot;&lt;/b&gt;, però questo testo lo vediamo scritto in due posti: come titolo della finestra del browser e all&#39;interno della pagina. Anche se sembrerebbe che lo faccia in automatico, in realtà siamo stati noi a dire di fare così. Infatti, con &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;title&amp;gt;Hello, World!&amp;lt;/title&amp;gt;&lt;/span&gt; abbiamo indicato di nominare la pagina con il testo contenuto tra i due tag, mentre il testo che è stato scritto all&#39;interno della pagina è stato preso dal tag &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;. E in generale, tutto quello che deve essere visualizzato deve essere scritto tra &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;, mentre tutto ciò che si riferisce all&#39;impostazione della pagina viene messo tra &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/6018226290791421592/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2012/01/html-hello-world.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6018226290791421592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6018226290791421592'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2012/01/html-hello-world.html' title='HTML - Hello, World!'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4m0A1KAFLS5b-lcUmWekO0lOz0QzWrrj79DkttIzjaROa3sjaji7npwxN8QgEDycudPwtMIFJMVY6_PJfS2MSpgpFRwDlDvvmUfisBx0HrzySFnRi7OwsyeQyEJzGdSPzwuSiII0x-yM/s72-c/hello_world_html.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-2681993754181860774</id><published>2011-12-31T02:04:00.001+01:00</published><updated>2011-12-31T02:10:09.087+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Funzioni ricorsive</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Nel mondo dell&#39;informatica odierna viene spesso incontrata l&#39;espressione di &lt;b&gt;funzione ricorsiva&lt;/b&gt;, una funzionalità che possiedono alcuni dei linguaggi di programmazione, molto utile al giorno d&#39;oggi nello sviluppo delle applicazioni, perché permettono di semplificare estremamente il codice di un programma, che utilizza determinate strutture dati.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Vediamo più in dettaglio perché questa funzionalità è così importante al giorno d&#39;oggi. Il motivo più importante che spinge i nuovi linguaggi di programmazione ad avere la possibilità di scrivere funzioni ricorsive è che la correttezza di una funzione ricorsiva è possibile dimostrare matematicamente sfruttando la &lt;b&gt;dimostrazione per induzione&lt;/b&gt;, per cui&amp;nbsp;viene resa possibile la ricerca matematica della soluzione ad un problema e la successiva traduzione dell&#39;algoritmo matematico in codice.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Fino ad ora si è parlato delle funzioni ricorsive, ma non è stato ancora detto cosa sono, per cui procediamo con la definizione di esse: &lt;b&gt;una funzione è detta ricorsiva quando nel suo corpo esegue una chiamata a se stessa&lt;/b&gt;, ovvero rincorre se stessa come fa il cane con la sua coda.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ma proviamo a vedere come si fa a creare una funzione ricorsiva in F#. Beh, è molto semplice, perché non ci sono molte differenze rispetto alla definizione di una normale funzione. L&#39;unica differenza sta nel fatto che dobbiamo dichiarare esplicitamente che la funzione che stiamo definendo è una funzione ricorsiva, aggiungendo dopo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;let&lt;/span&gt; la parola chiave &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;rec&lt;/span&gt;, inoltre non dobbiamo dimenticarci che la funzione deve richiamare se stessa per almeno una volta:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;rec&lt;/span&gt;&lt;/b&gt; somma n =&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; n&amp;lt;1 &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;then&lt;/span&gt;&lt;/b&gt; 0&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/b&gt; n+(somma (n-1));;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;La funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma&lt;/span&gt;&lt;/span&gt; deve sostanzialmente restituire il risultato della somma di tutti i numeri interi da 0 a &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;. Ciò viene fatto sommando &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;n&lt;/span&gt; alla somma di tutti i numeri da 0 a &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(n-1)&lt;/span&gt;. Quando arriviamo alla condizione in cui &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;n&amp;lt;1&lt;/span&gt; restituiamo 0, e il ciclo si interrompe. La funzione può essere capita più facilmente analizzando i passaggi che esegue un compilatore in un esempio:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma 5 -&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;5 non è minore di 1, quindi esegue l&#39;istruzione del ramo else&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(somma 4) -&amp;gt; (&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;4 non è minore di 1, quindi esegue l&#39;istruzione del ramo else&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+(somma 3)) -&amp;gt; (&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;3 non è minore di 1, quindi esegue l&#39;istruzione del ramo else&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+(3+(somma 2))) -&amp;gt; (&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;2 non è minore di 1, quindi esegue l&#39;istruzione del ramo else&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+(3+(2+(somma 1)))) -&amp;gt; (&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;1 non è minore di 1, quindi esegue l&#39;istruzione del ramo else&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+(3+(2+(1+(somma 0))))) -&amp;gt; (&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;0&amp;lt;1, quindi restituisce 0&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+(3+(2+(1+0))))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+(3+(2+1)))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+(3+3))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+(4+6)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;5+10&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;15&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Come potete vedere il risultato restituito dalla funzione è 15, che è uguale alla somma dei numeri interi da 0 a 5. Infatti, se guardiamo il 7° passaggio possiamo identificare proprio la somma dei primi &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;n&lt;/span&gt;&lt;/span&gt; numeri naturali. E adesso, tolto il dubbio della correttezza della funzione, analizziamo perché è stato possibile arrivare a questo risultato. In pratica noi non abbiamo fatto altro che riutilizzare la funzione stessa, però passandogli un parametro, che è minore di 1 del precedente, finché siamo arrivati alla condizione in cui sappiamo con certezza qual è il risultato che la funzione deve restituire. Questa condizione viene chiamata &lt;b&gt;caso base&lt;/b&gt;. A quel punto è diventato possibile il calcolo del risultato della funzione, il cui parametro è maggiore di 1 e così via, fino ad arrivare a &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;n&lt;/span&gt;&lt;/span&gt;.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Riassumendo, per scrivere una &lt;b&gt;funzione ricorsiva&lt;/b&gt; dobbiamo trovare un &lt;b&gt;caso base&lt;/b&gt;, ovvero una condizione in cui sappiamo con certezza il risultato della funzione, e richiamare la funzione stessa, modificando il parametro della funzione, per avvicinarlo al caso base, perché se il caso base non si verifica la funzione &lt;b&gt;non termina&lt;/b&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Proviamo adesso a scrivere una funzione fatt, che calcolerà il fattoriale di un certo numero intero n&amp;gt;0. Ma prima di scrivere direttamente il codice della funzione vediamo la definizione matematica del fattoriale:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;0! = 1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;n! = n * (n-1)!&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Partendo da questa definizione matematica, scrivere la funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;fatt&lt;/span&gt;&lt;/span&gt; sarà un gioco da ragazzi, perché il caso base è quando dobbiamo calcolare il fattoriale di 0, mentre in tutti gli altri casi basta moltiplicare &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;n&lt;/span&gt;&lt;/span&gt; per il fattoriale di &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(n-1)&lt;/span&gt;&lt;/span&gt;:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let rec&lt;/span&gt;&lt;/b&gt; fatt n =&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; n=0 &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;then&lt;/span&gt;&lt;/b&gt; 1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/b&gt; n*(fatt (n-1));;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;La funzione è praticamente identica alla precedente e, una cosa molto bella di &lt;b&gt;F#&lt;/b&gt;, se proviamo a tradurre il codice in italiano otteniamo proprio la definizione matematica della funzione fattoriale. E questa è il vero punto di forza della &lt;b&gt;programmazione funzionale&lt;/b&gt;.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ma se da una parte l&#39;impiego delle &lt;b&gt;funzioni ricorsive&lt;/b&gt; nella programmazione permette di semplificare notevolmente il codice di un programma, dall&#39;altra parte viene richiesta molta &lt;b&gt;più memoria&lt;/b&gt; rispetto alle versioni &lt;b&gt;iterative&lt;/b&gt; delle funzioni, che vedremo più avanti. &amp;nbsp;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/2681993754181860774/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/f-funzioni-ricorsive_31.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/2681993754181860774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/2681993754181860774'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/f-funzioni-ricorsive_31.html' title='F# - Funzioni ricorsive'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-7739056627721758397</id><published>2011-12-30T02:13:00.002+01:00</published><updated>2012-01-03T14:23:19.595+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><title type='text'>HTML - I tag e struttura pagina</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Nel post precedente è stato accennato che il linguaggio &lt;b&gt;HTML&lt;/b&gt; è stato creato per rendere possibile lo scambio di informazioni tra i computer, mediante documenti ipertestuali, create utilizzando questo linguaggio di programmazione. &lt;b&gt;HTML&lt;/b&gt; è un linguaggio di programmazione &lt;b&gt;descrittivo&lt;/b&gt;, ovvero un linguaggio nel quale dobbiamo descrivere il risultato che vogliamo ottenere, mentre è il &lt;b&gt;browser&lt;/b&gt; si impegnerà&amp;nbsp;a trovare la strada per arrivare al risultato voluto.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;I tag&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Come è stato detto, il &lt;b&gt;browser &lt;/b&gt;ha il compito di capire che cosa vogliamo che venga visualizzato, semplicemente descrivendo il risultato, ma una descrizione a parole in una lingua usata dagli uomini per comunicare sarebbe troppo complicata per il browser, per cui è stato proposto di usare dei &lt;b&gt;tag&lt;/b&gt;, ovvero delle parole chiavi, che devono essere racchiuse tra &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;, e che devono portare l&#39;informazione su come deve essere fatta la pagina. In altre parole, useremo i &lt;b&gt;tag &lt;/b&gt;per dire al browser cosa vogliamo che venga visualizzato e come vogliamo che quel componente venga visualizzato. Quasi tutti i &lt;b&gt;tag&lt;/b&gt; hanno un &lt;b&gt;tag di chiusura&lt;/b&gt;, che hanno la forma &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;/tag&amp;gt;&lt;/span&gt; e che indica dove finisce l&#39;azione di un determinato &lt;b&gt;tag&lt;/b&gt;.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Struttura pagina&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Una pagina ipertestuale deve avere una struttura ben definita, affinché venga interpretata correttamente da tutti i browser, per cui esistono alcune regole che devono essere rispettate durante la scrittura di una pagina html. La &lt;b&gt;prima &lt;/b&gt;regola da rispettare è quella di chiudere tutti i tag, che hanno un tag di chiudura, in modo da evitare la visualizzazione errata dei componenti della pagina. La &lt;b&gt;seconda&lt;/b&gt; è quella di rispettare la struttura ad albero delle pagine ipertestuali, per non interferire con altri elementi dello stesso tipo presenti sulla pagina. E la &lt;b&gt;terza &lt;/b&gt;regola è quella di rispettare la struttura base della pagina e mettere ogni elemento della pagina al suo posto.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Vediamo ora come deve essere fatta una pagina html:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;HTML&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;HEAD&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;TITLE&amp;gt;&lt;/span&gt; Titolo della pagina &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/TITLE&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/HEAD&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;BODY&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&amp;lt;/BODY&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;/HTML&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Proviamo ad analizzare la struttura proposta. Il tag &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;HTML&amp;gt;&amp;lt;/HTML&amp;gt;&lt;/span&gt;&lt;/span&gt; indica che la pagina è una pagina ipertestuale, e serve ad indicare al browser di non interpretare i tag come testo ma come comandi, inoltre deve contenere tutto il contenuto della pagina, per cui non ci deve essere nulla dopo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;/HTML&amp;gt;&lt;/span&gt;. Il secondo tag &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;HEAD&amp;gt;&amp;lt;/HEAD&amp;gt;&lt;/span&gt; rappresenta la testa della pagina, ovvero contiene le informazioni riguardanti la descrizione della pagina, dove rientra anche il tag &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;TITLE&amp;gt;&amp;lt;/TITLE&amp;gt;&lt;/span&gt;, che indica il titolo della pagina, che verrà visualizzato nella barra del titolo del browser. Infine, il tag &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;BODY&amp;gt;&amp;lt;/BODY&amp;gt;&lt;/span&gt;&lt;/span&gt; rappresenta il corpo della pagina, cioè l&#39;insieme di tutti gli elementi che verranno visualizzati nel browser.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Il linguaggio HTML non è case sensitive, per cui i tag possono essere scritti sia in maiuscolo che in minuscolo, senza alcuna differenza, inoltre le pagine html non sono altro che documenti di testo, quindi possono essere create anche con un semplice editor di testo come il Notepad(blocco note) presente nei sistemi operativi Windows, però vi consiglio vivamente di utilizzare un editor che sia indirizzato alla scrittura delle pagine html, perché nel corso dello studio verrete aiutati dal programma.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/7739056627721758397/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/html-i-tag-e-struttura-pagina.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/7739056627721758397'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/7739056627721758397'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/html-i-tag-e-struttura-pagina.html' title='HTML - I tag e struttura pagina'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-5208742800460587960</id><published>2011-12-30T01:18:00.000+01:00</published><updated>2011-12-30T01:18:52.542+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="HTML"/><title type='text'>HTML - Introduzione</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;HTML - HyperText Markup Language&lt;/b&gt; è un linguaggio di programmazione sviluppato alla fine degli anni ottanta da &lt;b&gt;Tim Berners-Lee&lt;/b&gt; allo scopo di editare dei ipertesti per poterli poi inviare via Internet. Assieme al linguaggio di programmazione è stato creato un protocollo per la trasmissione di documenti scritti in questo linguaggio, che venne, appunto, chiamato &lt;b&gt;HTTP&lt;/b&gt; (HyperText Transfer Protocol).&lt;a name=&#39;more&#39;&gt;&lt;/a&gt; All&#39;inizio non ebbe un grande successo, ma con lo sviluppo di Internet fu vivamente utilizzato e modificato, per soddisfare le esigenze dei web designer.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Con il tempo al linguaggio vennero aggiunte nuove funzionalità e la possibilità di includere codici di altri linguaggi come &lt;b&gt;JavaScript&lt;/b&gt;, &lt;b&gt;VBScript&lt;/b&gt;, &lt;b&gt;CSS&lt;/b&gt; e &lt;b&gt;Java&lt;/b&gt;, per rendere le pagine più dinamiche, in modo da interagire con gli utenti, senza dover cambiare pagina. In questo modo il web designer doveva soltanto scrivere le pagine html e pubblicarli su un &lt;b&gt;server&lt;/b&gt;, che quando viene fatta una richiesta, deve inviare il contenuto del corrispondente documento ipertestuale, mentre un programma chiamato &lt;b&gt;browser&lt;/b&gt; eseguito sul lato del &lt;b&gt;cliente&lt;/b&gt; deve occuparsi dell&#39;interpretazione di tale documento.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Tutto questo andava bene per creare delle semplici pagine web, che potevano contenere dei testi, delle immagini e magari contenere qualche elemento grafico o funzionale che interagiva con l&#39;utente, però rivelava un grosso difetto nel momento in cui si voleva creare un sito più complesso, che doveva contenere più pagine, perché tutti i dati dovevano essere inseriti manualmente e diventava estremamente complicato aggiornare un sito, oppure modificare la sua grafica.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Il problema è stato risolto inventando nuovi &lt;b&gt;linguaggi di programmazione lato server&lt;/b&gt;, che attraverso un &lt;b&gt;interprete&lt;/b&gt; che viene lanciato sul &lt;b&gt;server&lt;/b&gt;, permette di generare una pagina diversa a seconda della richiesta che arriva. In questo modo il web designer potrebbe scrivere soltanto una pagina per un sito, perché le parti statiche della pagina possono essere scritte in html, mentre la parte dinamica delle pagine viene scritta in uno dei linguaggi server. I linguaggi lato server attualmente più conosciuti sono &lt;b&gt;PHP&lt;/b&gt;, &lt;b&gt;ASP&lt;/b&gt; e &lt;b&gt;JSP&lt;/b&gt;, che in fondo generano sempre delle pagine html, per poi spedirli al &lt;b&gt;cliente&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/5208742800460587960/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/html-introduzione.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/5208742800460587960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/5208742800460587960'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/html-introduzione.html' title='HTML - Introduzione'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-6171316426973946780</id><published>2011-12-29T19:19:00.001+01:00</published><updated>2012-01-15T13:59:55.484+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Costrutto if e pattern matching</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Il più delle volte, quando si scrive un programma si ricorre all&#39;utilizzo di costrutti condizionali, che permettono di scegliere le istruzioni da eseguire in base ad un valore o al risultato di un confronto. Ciò è possibile grazie ai costrutti &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if&lt;/span&gt;&lt;/span&gt;, presente in tutti i linguaggi di programmazione e di &lt;b&gt;pattern matching&lt;/b&gt;.&amp;nbsp;&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #666666;&quot;&gt;Il costrutto &lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Come accennato prima, questo costrutto permette di far eseguire un&#39;istruzione, oppure l&#39;altra in base alla condizione imposta dopo la parola chiave &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if&lt;/span&gt;. Vediamo un esempio di come viene impiegato questo costrutto:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; a&amp;gt;b &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;then&lt;/span&gt;&lt;/b&gt; a-b&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt; b-a;;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Se proviamo a tradurre letteralmente in italiano, otteniamo la seguente frase: se &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;a&amp;gt;b&lt;/span&gt; allora restituisci &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;a-b&lt;/span&gt;&lt;/span&gt;, altrimenti restituisci &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;b-a&lt;/span&gt;. In altre parole quando la condizione restituisce &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt;&lt;/span&gt;, allora eseguiamo l&#39;istruzione del ramo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;then&lt;/span&gt;, altrimenti eseguiamo l&#39;istruzione del ramo &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;else&lt;/span&gt;&lt;/span&gt;.&lt;br /&gt;
Se, per esempio, vogliamo restituire il massimo tra due numeri, allora possiamo fare in questo modo:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; a&amp;gt;b &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;then&lt;/b&gt;&lt;/span&gt; a &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/b&gt; b;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
letteralmente, se &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;a&lt;/span&gt; è maggiore di &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;b&lt;/span&gt;&lt;/span&gt; allora restituisci &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;a&lt;/span&gt;, altrimenti restituisci &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;b&lt;/span&gt;. Quindi se vogliamo scrivere una funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;max&lt;/span&gt;, che restituisce il massimo degli argomenti passati in input, avremo:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; max a b =&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; a&amp;gt;b &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;then&lt;/span&gt;&lt;/b&gt; a&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/b&gt; b;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;I pattern matching&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I &lt;b&gt;pattern matching&lt;/b&gt; sono sostanzialmente dei costrutti condizionali, che confrontano un valore con gli altri, che rappresentano i suoi rami, e una volta trovata la corrispondenza, esegue l&#39;istruzione corrispondente. Volendo si potrebbe anche evitare l&#39;utilizzo di tale costrutto, però il codice diventerebbe meno chiaro, perché saremmo costretti ad usare dei costrutti &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if&lt;/span&gt; annidati (una soluzione poco elegante e poco chiara). Ma vediamo come si utilizzano i pattern matching:&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;match&lt;/span&gt;&lt;/b&gt; valore &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;with&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;corrispondenza1 &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/span&gt; istruzione&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;| corrispondenza2 &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/b&gt; istruzione&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;| _ &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;/b&gt; istruzione_default;;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In pratica in questo modo confrontiamo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;valore&lt;/span&gt; con le corrispondenze e una volta trovata la corrispondenza eseguiamo l&#39;istruzione scritta dopo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;-&amp;gt;&lt;/span&gt;, inoltre ogni corrispondenza deve essere separata dalle altre tramite il simbolo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;|&lt;/span&gt;. Qualcuno avrà notato che come ultima corrispondenza è stato messo il simbolo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;_&lt;/span&gt;, che in F# indica &lt;b&gt;qualunque cosa&lt;/b&gt;&amp;nbsp;e in questo caso sta per tutti gli altri casi e viene usato quando non vogliamo definire tutti i possibili casi. Dobbiamo, inoltre, tenere a mente che le corrispondenze vengono processate nel ordine scritto nel pattern matching e una volta trovata la corrispondenza, vengono ignorate tutte le altre.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
L&#39;utilizzo più approfondito di questo costrutto verrà spiegato assieme alle funzioni ricorsive, dove molto spesso viene preferito l&#39;utilizzo di questo costrutto, invece del costrutto &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if&lt;/span&gt;.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/6171316426973946780/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/f-costrutto-if-e-pattern-matching.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6171316426973946780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6171316426973946780'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/f-costrutto-if-e-pattern-matching.html' title='F# - Costrutto if e pattern matching'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-1425493048712047892</id><published>2011-12-29T01:29:00.002+01:00</published><updated>2011-12-29T01:35:04.509+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Funzioni</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Spesso programmando ci si ritrova di fronte ad un fatto poco gradevole, quale la ripetizione di una sequenza di istruzione all&#39;interno del programma, rendendo il codice poco elegante e comprensibile. Il modo più semplice di evitare che ciò accada è quello di creare delle funzioni, che contengano la sequenza delle istruzioni che si ripetono e raggrupparle sotto un&#39;unico nome.&amp;nbsp;F# è uno dei linguaggi in cui le funzioni vengono usate molto spesso, per cui è un argomento molto importante per chi ha deciso di programmare in questo linguaggio.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Esistono due modi per scrivere una funzione, che in fondo hanno più o meno la stessa identica struttura e differiscono soltanto per il modo in cui viene indicato che si sta per definire una funzione.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Vediamo il primo modo in cui può essere definita una funzione:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; somma = &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;fun&lt;/span&gt;&lt;/b&gt; a b &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;-&amp;gt;&lt;/b&gt;&lt;/span&gt; a + b;;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Con questa istruzione abbiamo creato un nuovo nome, che e una funzione e che ha due argomenti &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;a&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;b&lt;/span&gt;. Una volta ottenuti i due argomenti la funzione restituisce la somma di &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(a+b)&lt;/span&gt;. In questo modo quando scriviamo il nome &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma&lt;/span&gt;&lt;/span&gt; il compilatore si aspetta che noi gli diamo altri due valori dello stesso tipo e che supportano l&#39;operazione di somma. Di default il compilatore decide che &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;a&lt;/span&gt;&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;b&lt;/span&gt;&lt;/span&gt; devono essere interi, per cui anche il risultato della funzione sarà un intero.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Il secondo modo per scrivere una funzione è il seguente:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; somma a b = a+b;;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Questo modo è più corto di quello mostrato in precedenza e di conseguenza viene anche maggiormente usato. Dal punto di vista di funzionalità non c&#39;è alcuna differenza tra usare il primo modo, oppure il secondo, perché il concetto è sempre lo stesso, visto che nel primo caso diciamo esplicitamente che la somma corrisponde a una funzione che ha due argomenti, mentre nel secondo caso diciamo che dopo il nome somma ci aspettiamo altri due argomenti, che devono essere di tipo intero, perché nel corpo viene usato l&#39;operatore di somma.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ma vediamo ora cosa succede se scriviamo la seguente istruzione:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; incrementa = somma 1;;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Proviamo ad analizzare questa istruzione e vedere come si comporta il compilatore di F#. In poche parole viene introdotto il nome &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;incrementa&lt;/span&gt; ed è uguale alla funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma&lt;/span&gt;&lt;/span&gt;, però abbiamo indicato che il primo parametro della funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma&lt;/span&gt;&lt;/span&gt; deve valere 1, ma il compilatore si aspetta che alla funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma&lt;/span&gt;&lt;/span&gt; vengano passati due argomenti, quindi il secondo verrà richiesto nel momento in cui chiameremo la funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;incrementa&lt;/span&gt;&lt;/span&gt;. In questo modo abbiamo ottenuto un&#39;altra funzione, che non fa altro che incrementare di 1 un numero intero, passato come argomento.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;E questo è un modo per definire nuove funzioni sulla base di una già definita, mantenendo costante uno dei suoi argomenti.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Per provare ad eseguire queste istruzioni basta aprire Visual Studio e aprire &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;F# Interactive&lt;/span&gt; dal menu &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;View-&amp;gt;Other Windows-&amp;gt;F# Interactive&lt;/span&gt;, oppure premere &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Ctrl+Alt+F&lt;/span&gt;. Verrà aperta una nuova finestra come questa:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwuVvYkTi2zXzc_ob_exlDNT4O8LHe-zYcp1e53a1t5_jFGgPQyTWG29dxNAl8Aa9oIIWQEpYstWpOfbvC-tQ_Gbluf72vaGdaXE5UZK3uhMIMhtax5Cngfdjl6uYD-OdePsI6aJWnfaw/s1600/f_interactive.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;206&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwuVvYkTi2zXzc_ob_exlDNT4O8LHe-zYcp1e53a1t5_jFGgPQyTWG29dxNAl8Aa9oIIWQEpYstWpOfbvC-tQ_Gbluf72vaGdaXE5UZK3uhMIMhtax5Cngfdjl6uYD-OdePsI6aJWnfaw/s640/f_interactive.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Subito dopo il carattere &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;gt;&lt;/span&gt; digitate l&#39;istruzione che volete provare, terminando ogni istruzione con &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;;;&lt;/span&gt;&lt;/span&gt; e dando Invio. Così scrivendo una delle istruzioni per la creazione della funzione somma otterremo la seguente risposta dal compilatore:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;val somma : int -&amp;gt; int -&amp;gt; int&lt;/span&gt; &lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;che ci dice che è stato introdotto il nome &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma&lt;/span&gt;&lt;/span&gt;, che prende un argomento di tipo intero, dopodiché ne prende un&#39;altro argomento intero e restituisce un risultato sempre intero. Mentre se proviamo a scrivere l&#39;istruzione relativa alla dichiarazione della funzione &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;incrementa&lt;/span&gt;&lt;/span&gt;, otteniamo il seguente risultato:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;val incrementa : (int -&amp;gt; int)&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;che ci indica che è stato introdotto il nome &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;incrementa&lt;/span&gt;&lt;/span&gt;, uguale ad una funzione che prende un argomento di tipo intero e restituisce un valore intero, che guarda caso è proprio lo stampo della funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;incrementa&lt;/span&gt;, la quale prende in input un numero intero, lo incrementa di 1 e restituisce il risultato, che è sempre intero.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/1425493048712047892/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/f-funzioni.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/1425493048712047892'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/1425493048712047892'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/f-funzioni.html' title='F# - Funzioni'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwuVvYkTi2zXzc_ob_exlDNT4O8LHe-zYcp1e53a1t5_jFGgPQyTWG29dxNAl8Aa9oIIWQEpYstWpOfbvC-tQ_Gbluf72vaGdaXE5UZK3uhMIMhtax5Cngfdjl6uYD-OdePsI6aJWnfaw/s72-c/f_interactive.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-2933351854358282177</id><published>2011-12-29T00:01:00.001+01:00</published><updated>2011-12-29T01:51:56.980+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Variabili e tipi</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Come è stato detto nell&#39;introduzione, F# è un linguaggio giovanissimo, che come abbiamo visto si vanta di alcuni punti di forza rispetto ai linguaggi di programmazione già esistenti. Un&#39;altro punto di forza di questo linguaggio è quello di non dover specificare il tipo della variabile, o meglio, del nome che vogliamo creare, perché è il compilatore a capre il tipo del nome a seconda dei valori che gli viene attribuito, tuttavia non permettendo l&#39;esecuzione di operazioni tra tipi diversi, allo scopo di evitare errori di precisione. Questo comportamento del compilatore facilità notevolmente lo sviluppo dei programmi, specie per i programmatori novellini.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;Le variabili (nomi)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In F# dichiarare un nuovo nome è molto semplice, perché il programmatore non deve preoccuparsi del tipo della &amp;nbsp;variabile che andrà a creare, visto che il compilatore si prende la responsabilità di fare questo lavoro, ma nonostante ciò dobbiamo dichiarare esplicitamente che vogliamo introdurre un nuovo nome. Per fare ciò viene usata la parola chiave&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;let&lt;/span&gt;, che può essere tradotto in italiano come &lt;b&gt;sia&lt;/b&gt;. Vediamo, allora, come vengono dichiarate le variabili:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; numero = 5;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; decimale = 3.452;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;let&lt;/b&gt;&lt;/span&gt; booleano = &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;true&lt;/b&gt;&lt;/span&gt;;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;let&lt;/b&gt;&lt;/span&gt; carattere = &lt;span style=&quot;color: #990000;&quot;&gt;&#39;a&#39;&lt;/span&gt;;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;let&lt;/span&gt;&lt;/b&gt; stringa = &lt;span style=&quot;color: #990000;&quot;&gt;&quot;una sequenza di caratteri&quot;&lt;/span&gt;;;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Dal codice possiamo vedere che ogni riga inizia con la parola &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;let&lt;/span&gt;, che dice sia &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;numero&lt;/span&gt; uguale a 5 e sia &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;decimale&lt;/span&gt; uguale a 3.452 e così via. Dopo questa definizione per il compilatore il nome &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;numero&lt;/span&gt; e 5 sono la stessa cosa. Un&#39;altra cosa che si può notare analizzando il codice è che ogni riga finisce con &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;;;&lt;/span&gt;. In questo modo viene indicata la fine dell&#39;istruzione, tuttavia in F# non è strettamente necessario l&#39;utilizzo di questo delimitatore.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Il tipo booleano&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Il tipo booleano è un tipo nativo di F#, ovvero è un tipo predefinito, che non deve essere costruito e può essere usato per la reazione di altri tipi, non nativi. Questo tipo rappresenta un insieme che contiene solamente 2 elementi: &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt;&lt;/span&gt;. Viene usato molto per risolvere problemi di tipo logico, perché possono indicare se una condizione è vera oppure è falsa. Esistono tre operazioni che possono essere applicate ai booleani. Le operazioni booleane sono state elencate e descritte in basso:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;codice&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Operazione: &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;and&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Simbolo: &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Descrizione: questa operazione può essere fatta tra due valori booleani e come risultato si può ottenere&lt;span style=&quot;background-color: #fff2cc;&quot;&gt; &lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;true&lt;/b&gt;&lt;/span&gt; &lt;/span&gt;se entrambi i termini valgono &lt;span style=&quot;background-color: #fff2cc; color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;true&lt;/b&gt;&lt;/span&gt;, oppure &lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt; &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;in tutti gli altri casi.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Operazion: &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;or&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Simbolo: &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;||&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Descrizione: l&#39;operazione può essere fatta tra due valori booleani e restituisce come risultato &lt;span style=&quot;background-color: #fff2cc; color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt; se entrambi i termini valgono &lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;false&lt;/b&gt;&lt;/span&gt; e &lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;true&lt;/b&gt;&lt;/span&gt; altrimenti.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Operazione: &lt;b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;not&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Simbolo: &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;not&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Descrizione: la seguente operazione viene eseguita su un termine di tipo booleano, restituendo come risultato la negazione del suo valore, ovvero se il termine vale &lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;true&lt;/b&gt;&lt;/span&gt;, allora il risultato varrà &lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b style=&quot;background-color: #fff2cc;&quot;&gt;false&lt;/b&gt;&lt;/span&gt; e viceversa.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Il tipo intero&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Si può intuire dal titolo l&#39;insieme che identifica questo tipo, cioè l&#39;insieme dei numeri interi, ovvero in numeri che vanno teoricamente da -infinito a +infinito, ma in F# sono limitati con un intervallo più stretto, a causa della memoria finita del computer. Ad ogni modo sono i numeri con segno senza la parte decimale, quindi ...,-3,-2,-1,0,1,2,3,... Le operazioni che possono essere applicati a questi tipi sono:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;codice&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;somma: &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;+&lt;/span&gt;&amp;nbsp; -&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;esegue la somma tra numeri interi&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;sottrazione: &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;-&lt;/span&gt;&amp;nbsp; -&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;esegue la sottrazione tra numeri interi&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;prodotto: &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;*&lt;/span&gt;&amp;nbsp; -&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;esegue il prodotto tra numeri interi&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;quoziente: &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;/&lt;/span&gt;&amp;nbsp; -&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;restituisce la parte intera del quoziente&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;modulo: &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;%&lt;/span&gt; &amp;nbsp;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;restituisce il resto della divisione&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Il tipo float&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Questo tipo nativo rappresenta l&#39;insieme dei numeri con virgola mobile, ovvero l&#39;insieme dei numeri decimali, con l&#39;eccezione di avere un insieme finito a causa del limite imposto dalla memoria. Le operazioni che si possono eseguire con i numeri con virgola mobile sono le stesse dei numeri interi, tranne il &lt;b&gt;modulo&lt;/b&gt;, perché nei numeri decimali non c&#39;è il resto della divisione. D&#39;altronde per i numeri float c&#39;è l&#39;operatore per l&#39;&lt;b&gt;elevamento a potenza&lt;/b&gt;, che si indica con &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;**&lt;/span&gt;. Però bisogna tener ben presente il fatto che non possono essere eseguite operazioni su termini che sono di tipi diversi. Ma a questo punto sorge un problema, perché se per esempio come risultato di una operazione abbiamo ottenuto un valore intero, però dopo dobbiamo eseguire un&#39;operazione di cui un termine è intero e l&#39;altro è float, come facciamo? La risposta è molto semplice: usiamo la funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float(int)&lt;/span&gt;, che converte un numero intero in uno di tipo float, oppure la funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int(float)&lt;/span&gt;, che permette di convertire un numero con virgola mobile in un numero intero. In questo modo il programmatore è costretto a decidere quale tipo devono avere i termini prima di eseguire un&#39;operazione, evitando errori di precisione.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Il tipo carattere&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Spesso nella programmazione viene incontrata la necessità di utilizzare il tipo carattere, ad esempio per confrontare due parole, che non è altro che una sequenza di caratteri. In F# ci sono 256 caratteri diversi, nominati anche caratteri ASCII. Essi comprendono le cifre, le lettere minuscole e maiuscole del alfabeto inglese e del alfabeto cirillico, inoltre contengono una serie di caratteri speciali, come lo spazio, il punto la virgola e cosi via. Ad ogni carattere corrisponde un codice, che non è altro che un numero intero da 0 a 255, che identifica quel particolare carattere. Visto che esiste la corrispondenza tra tipi interi e caratteri esiste anche la possibilità di convertire l&#39;uno nel corrispondente dell&#39;altro mediante le funzioni &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int(char)&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;char(int)&lt;/span&gt;. L&#39;unica operazione che può essere eseguita su di un carattere è l&#39;operazione di somma, che permette di ottenere un&#39;altro carattere, però appartenente ad un&#39;altro insieme di caratteri, chiamato Unicode, che contiene tutti i caratteri del codice ASCII e gli alfabeti delle lingue del mondo.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Il tipo stringa&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
La stringa non è altro che una sequenza di caratteri. Esso è un tipo molto usato nella programmazione, perché nel momento in cui il programma deve comunicare qualche cosa all&#39;utente in modo testuale, vengono usate le stringhe. Inoltre, F# possiede già un insieme di funzioni per permettere al programmatore di eseguire diverse operazioni sulle stringhe, senza doverle definire. L&#39;operazione di base che può essere eseguito sulle stringhe è l&#39;operazione di concatenazione, la cui funzione è di restituire una stringa formata dalla prima, seguita dalla seconda. Questa operazione può essere fatta mediante l&#39;operatore &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;+&lt;/span&gt;&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #666666; font-family: Georgia, &#39;Times New Roman&#39;, serif; font-size: large;&quot;&gt;&lt;b&gt;Gli operatori di confronto&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Oltre agli operatori presentati in precedenza, che permettono di calcolare un nuovo valore dello stesso tipo esistono anche operatori di confronto, che dati due termini dello stesso tipo restituiscono un valore booleano. Questi operatori sono applicabili a tutti i tipi nativi e restituiscono sempre un valore &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt;&lt;/span&gt; oppure &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt;&lt;/span&gt;. Gli operatori di confronto sono 6:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;uguale: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;=&lt;/span&gt; &amp;nbsp; &amp;nbsp;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;true se i termini sono uguali&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;non uguale: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt; &amp;nbsp; -&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;true se i termini non sono uguali&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;maggiore: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;gt;&lt;/span&gt; &amp;nbsp; &amp;nbsp;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;true se il termine a sinistra è maggiore di quello a destra&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;minore: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;lt;&lt;/span&gt; &amp;nbsp; &amp;nbsp;-&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;true se il termine a sinistra è minore di quello a destra&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;maggiore o uguale: &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;gt;=&lt;/span&gt; &amp;nbsp; -&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;true se il termine a sinistra è maggiore o uguale a quello di destra&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;minore o uguale: &amp;nbsp; &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;lt;=&lt;/span&gt; &amp;nbsp; -&amp;gt; &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;true se il termine a sinistra è minore o uguale a quello di destra&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Gli operatori di confronto vengono usati molto per eseguire delle scelte in base ai valori che abbiamo e scegliere di eseguire un&#39;istruzione o un gruppo di istruzioni, oppure un&#39;altra istruzione o gruppo di istruzioni.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/2933351854358282177/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/f-variabili-e-tipi.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/2933351854358282177'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/2933351854358282177'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/f-variabili-e-tipi.html' title='F# - Variabili e tipi'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-6091495277426629031</id><published>2011-12-21T19:08:00.942+01:00</published><updated>2012-01-09T17:37:53.825+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OpenGL in C/C++"/><title type='text'>OpenGL in C/C++ - Impostazione progetto</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Per lavorare con OpenGL abbiamo bisogno di un elemento grafico come la finestra, per cui il primo passo da fare è aprire Dev C++ e creare un nuovo progetto di tipo Windows Application, e scegliere come linguaggio di programmazione C++, perché così possiamo utilizzare le funzionalità sia di C che di C++. L&#39;ambiente di sviluppo genererà in automatico il codice per la creazione della finestra e della procedura principale per la gestione dei messaggi della finestra.&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Per avere un progetto più ordinato possiamo suddividerlo in più file che conterranno un certo gruppo di funzioni, perciò ci serve un header file per contenere le definizioni delle funzioni, mentre creeremo dei file di estensione *.cpp, che conterranno i costruttori delle funzioni. Ai file da aggiungere ho deciso di dare i seguenti nomi:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;background-color: #fff2cc; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;functions.h&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; - sarà il nostro file header e conterrà i nomi delle funzioni da noi definite&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #fff2cc; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;init.cpp&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; &lt;span style=&quot;font-family: inherit;&quot;&gt;- il file che conterrà i costruttori delle funzioni che ci serviranno per l&#39;inizializzazione di OpenGL&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #fff2cc; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;draw.cpp&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; &lt;span style=&quot;font-family: inherit;&quot;&gt;- conterrà i costruttori delle funzioni necessarie per il disegno nella finestra&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Per aggiungere un nuovo file al progetto basta andare in &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Project-&amp;gt;New file&lt;/span&gt;.&lt;br /&gt;
A questo punto dobbiamo modificare le &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include&lt;/span&gt; del nostro progetto sostituendo con quelli elencati in basso, nei file indicati nel codice:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// main.cpp&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include &quot;functions.h&quot;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// functions.h&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include &amp;lt;windows.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include &amp;lt;gl/gl.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include &amp;lt;gl/glu.h&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// init.cpp&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include &quot;functions.h&quot;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;// draw.cpp&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #38761d; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;#include &quot;functions.h&quot;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Adesso dobbiamo dire al compilatore di importare le librerie che ci servono per utilizzare le funzioni definite nei header di OpenGL. Per questo dobbiamo andare in &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Project-&amp;gt;Project Options&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; e selezionare la scheda Parameters. Nella terza colonna sotto nome Linker aggiungere le seguenti righe:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #fff2cc; border-bottom-color: rgb(102, 102, 102); border-bottom-style: dashed; border-bottom-width: 1px; border-image: initial; border-left-color: rgb(102, 102, 102); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(102, 102, 102); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(102, 102, 102); border-top-style: dashed; border-top-width: 1px; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px;&quot;&gt;../../../../../../../Dev-Cpp/lib/libopengl32.a&lt;br /&gt;
../../../../../../../Dev-Cpp/lib/libglaux.a&lt;br /&gt;
../../../../../../../Dev-Cpp/lib/libglu32.a&lt;br /&gt;
../../../../../../../Dev-Cpp/lib/libglut.a&lt;br /&gt;
../../../../../../../Dev-Cpp/lib/libglut32.a&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: inherit;&quot;&gt;Come risultato dovreste avere la seguente schermata:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWPbEei9f9zqrcIZlOOoA2Y1huE1JuKClUyD_vG2v6Kj9CSYlC-mDfrRXnyMSSDryHakE5yEiqddHxdibrukmYeMGWyu-iAcHnfF2eioC1nynSUhYkG2FWgkpSuIXtYkEH9P_h7v1CfEU/s1600/schermata_linker.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWPbEei9f9zqrcIZlOOoA2Y1huE1JuKClUyD_vG2v6Kj9CSYlC-mDfrRXnyMSSDryHakE5yEiqddHxdibrukmYeMGWyu-iAcHnfF2eioC1nynSUhYkG2FWgkpSuIXtYkEH9P_h7v1CfEU/s1600/schermata_linker.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Dopodiché dovete premere su ok per terminare la procedura. Adesso il compilatore sa dove andare a prendere il corpo delle funzioni di OpenGL che utilizzeremo nei nostri progetti.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Il passo successivo è quello di andare a impostare la finestra per rendere possibile il disegno su di essa da parte di OpenGL, per questo dobbiamo creare alcune variabili globali, che metteremo&amp;nbsp;subito&amp;nbsp;prima della funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;WinMain&lt;/span&gt;:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;background-color: #fff2cc; border: #666 dashed 1px; display: block; padding: 5px;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b style=&quot;color: blue;&quot;&gt;bool&lt;/b&gt; fullscreen = &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&lt;/b&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* indica se vogliamo una finestra a schermo intero, oppure una finestra normale */&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;color: blue;&quot;&gt;int&lt;/b&gt; width = &lt;span style=&quot;color: purple;&quot;&gt;800&lt;/span&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* la larghezza della finestra */&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt; height = &lt;span style=&quot;color: purple;&quot;&gt;600&lt;/span&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* l&#39;altezza della finestra */&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;color: blue;&quot;&gt;int&lt;/b&gt; bits = &lt;span style=&quot;color: purple;&quot;&gt;32&lt;/span&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* il numero di bit per pixel che determinera` anche il numero di colori a disposizione e quindi la qualita` dell&#39;immagine */&lt;/span&gt;&amp;nbsp; &lt;br /&gt;
&lt;b style=&quot;color: blue;&quot;&gt;bool&lt;/b&gt; keys[&lt;span style=&quot;color: purple;&quot;&gt;256&lt;/span&gt;]; &lt;span style=&quot;color: #999999;&quot;&gt;/* l&#39;array di booleani ci permettera` di rilevare i tasti premuti, anche se contemporaneamente */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt; left_down = &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&lt;/b&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* indica se è premuto il pulsante sinistro del mouse */&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;color: blue;&quot;&gt;int&lt;/b&gt; x = &lt;span style=&quot;color: purple;&quot;&gt;400&lt;/span&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* la posizione orizzontale del mouse */&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;color: blue;&quot;&gt;int&lt;/b&gt; y = &lt;span style=&quot;color: purple;&quot;&gt;300&lt;/span&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* la posizione verticale del mouse */&lt;/span&gt; &lt;br /&gt;
HDC hDC; &lt;span style=&quot;color: #999999;&quot;&gt;/* l&#39;HDC della finestra sulla quale disegneremo */&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Le prime quattro righe servono sostanzialmente per impostare la modalità di visualizzazione della vostra applicazione. Le tre variavili &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;width&lt;/span&gt;, &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;height&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;bits&lt;/span&gt; ci serviranno per impostare la risoluzione dello schermo nel caso in cui andremo nella modalità fullscreen, mentre la variabile booleana &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;fullscreen&lt;/span&gt; indicherà se vogliamo andare nella modalità fullscreen, oppure visualizzare l&#39;applicazione nella modalità windowed.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Le successive tre variabili ci serviranno, invece, per determinare i tasti premuti e la posizione del mouse, visto che la procedura del disegno verrà effettuata in un&#39;altra funzione, per non fare confusione. Quindi l&#39;array &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;keys&lt;/span&gt; verrà inizializzato a &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt; per indicare che nessun tasto della tastiera è stato premuto e nel momento in cui viene premuto un tasto metteremo a &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt; l&#39;elemento il cui indice corrisponde al codice del tasto premuto. In questo modo ci assicuriamo di rilievare la pressione su più tasti. E come si è potuto capire le variabili &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;x&lt;/span&gt; e &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;y&lt;/span&gt; memorizzerano la posizione del mouse, che ci servirà nei casi in cui vorremo effettuare delle operazioni con il mouse. Mentre, invece, la variabile booleana &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;left_down&lt;/span&gt;&lt;/span&gt; ci indicherà se è premuto il bottone sinistro del mouse ed non è stato rilasciato.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;L&#39;ultima variabile è molto importante, perché rappresenterà il handle al device context, ovvero l&#39;accesso al dispositivo grafico che gestirà il processo di disegno della nostra finestra.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Per semplificare il codice del programma aggiungiamo altre tre variabili, però questa volta nel corpo della funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;WinMain&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;codice&quot; style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;RECT wndrect; &lt;span style=&quot;color: #999999;&quot;&gt;/* necessaria per impostare la modalità di visualizzazione */&lt;/span&gt;&lt;br /&gt;
DWORD dwExStyle; &lt;span style=&quot;color: #999999;&quot;&gt;/* conterrà il parametro ExStyle alla creazione della finestra principale */&lt;/span&gt;&lt;br /&gt;
DWORD dwStyle; &lt;span style=&quot;color: #999999;&quot;&gt;/* conterrà lo stile della finestra principale */&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;La prima variabile ci servirà per impostare la dimensione della finestra nel caso in cui visualizzeremo l&#39;applicazione della modalità windowed.&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;dwExStyle&lt;/span&gt; ci servirà per memorizzare lo stile esteso della finestra a seconda della modalità di visualizzazione della finestra. Mentre &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;dwStyle&lt;/span&gt;&lt;/span&gt; avrà il compito di contenere lo stile della finestra, anch&#39;esso determinato in base alla modalità di visualizzazione.&lt;br /&gt;
Per quanto riguardo la classe della finestra, possiamo lasciare il codice generato da Dev C++. &lt;br /&gt;
Il passo successivo è quello di registrare la classe creata, che viene effettuata mediante la funzione&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;RegisterClassEx(WNDCLASSEX)&lt;/span&gt;. La funzione la mettiamo come condizione di un costrutto &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;if&lt;/span&gt;, per avere immediatamente il risultato della registrazione e fermare il programma nel caso di fallimento. Per fare ciò inseriamo le seguenti righe di codice:&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; (!RegisterClassEx (&amp;amp;wincl)){ &lt;span style=&quot;color: #999999;&quot;&gt;/* in caso di fallimento */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; MessageBox(NULL,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TEXT(&lt;span style=&quot;color: red;&quot;&gt;&quot;Errore registrazione classe finestra&quot;&lt;/span&gt;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TEXT(&lt;span style=&quot;color: red;&quot;&gt;&quot;Errore&quot;&lt;/span&gt;),MB_OK); &lt;span style=&quot;color: #999999;&quot;&gt;/* visualizza messaggio di errore */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/b&gt; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* esce dal programma */&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Una volta verificato che la classe della finestra sia stata registrata procediamo con il riempimento della variabile &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;wndrect&lt;/span&gt;, che è una struttura di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;RECT&lt;/span&gt; e ci servirà per determinare l&#39;area della finestra, nella quale potremo disegnare dopo l&#39;impostazione della modalità di visualizzazione di essa. Il codice per il riempimento di questa struttura lo trovate di seguito:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;wndrect.left = (&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;long&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: purple; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;wndrect.top = (&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;long&lt;/span&gt;&lt;/b&gt;)&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;wndrect.right = width;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;wndrect.bottom = height;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;In questo modo abbiamo definito la dimensione dell&#39;area interna della finestra sulla quale andremo a disegnare, che nel caso della modalità fullscreen rappresenta la dimensione della finestra stessa, mentre nel caso in cui siamo nella modalità windowed rappresenta soltanto la parte interna, escludendo i bordi e l&#39;intestazione.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Fatto ciò procediamo con l&#39;impostazione della modalità di visualizzazione, quindi dobbiamo vedere se vogliamo andare nella modalità fullscreen e nel caso affermativo riempiamo una struttura di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DEVMODE&lt;/span&gt;, dopodiché con la funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ChangeDisplaySettings(*DEVMODE,&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;)&lt;/span&gt; cambiamo la risoluzione dello schermo a quella da noi richiesta. Per fare ciò creiamo una nuova funzione nel file&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;init.cpp&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt; &lt;b&gt;set_fullscreen&lt;/b&gt;(&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; width, &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; height, &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt; bits){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; DEVMODE dmScreenSettings;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; memset(&amp;amp;dmScreenSettings,&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;,&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;sizeof&lt;/span&gt;&lt;/b&gt;(dmScreenSettings));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dmScreenSettings.dmSize = &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;sizeof&lt;/span&gt;&lt;/b&gt;(dmScreenSettings);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dmScreenSettings.dmPelsWidth = width;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dmScreenSettings.dmPelsHeight = height;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dmScreenSettings.dmBitsPerPel = bits;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dmScreenSettings.dmFields = DM_PELSWIDTH |&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DM_PELSHEIGHT | DM_BITSPERPEL;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (ChangeDisplaySettings(&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;amp;dmScreenSettings,&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;CDS_FULLSCREEN)!=&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DISP_CHANGE_SUCCESSFUL){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MessageBox(NULL,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TEXT(&lt;span style=&quot;color: red;&quot;&gt;&quot;Impossibile passare alla modalitа fullscreen&quot;&lt;/span&gt;),&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TEXT(&lt;span style=&quot;color: red;&quot;&gt;&quot;Errore&quot;&lt;/span&gt;),MB_OK | MB_ICONERROR);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/b&gt; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt;&lt;/b&gt; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;true&lt;/b&gt;&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
In questo modo quando chiamiamo la funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;set_fullscreen&lt;/span&gt; appena definita riempiamo una struttura di tipo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DEVMODE&lt;/span&gt;, per poi utilizzarla nella funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ChangeDisplaySettings&lt;/span&gt;, che cambierà la risoluzione dello schermo. Ma nel caso in cui la risoluzione scelta non sia disponibile sul computer usato, viene visualizzato un messaggio di errore e la funzione termina restituendo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;false&lt;/span&gt;, che determina il relativo comportamento del programma, altrimenti esce restituendo &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;true&lt;/span&gt;. Naturalmente la definizione della funzione deve essere fatta anche nel file &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;functions.h&lt;/span&gt;, che viene fatta semplicemente aggiungendo la seguente riga di codice:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;set_fullscreen&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;width,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;height,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;int&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;bits);&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
A questo punto nel file &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;main.cpp&lt;/span&gt; scriviamo:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; (fullscreen){ &lt;span style=&quot;color: #999999;&quot;&gt;/* se è richiesta la modalità fullscreen */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* richiamiamo la funzione definita in init.cpp */&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; fullscreen = set_fullscreen(width,height,bits); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt;&lt;/b&gt; (fullscreen){ &lt;span style=&quot;color: #999999;&quot;&gt;/* se il dispositivo supporta il fullscreen */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* Visualizza la finestra sopra la barra delle applicazioni */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dwExStyle = WS_EX_APPWINDOW;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dwStyle = WS_POPUP; &lt;span style=&quot;color: #999999;&quot;&gt;/* la finestra è una popup */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; ShowCursor(&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;); &lt;span style=&quot;color: #999999;&quot;&gt;/* nasconde il cursore quando è fullscreen */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt;{ &lt;span style=&quot;color: #999999;&quot;&gt;/* se siamo nella modalità windowed */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dwExStyle = WS_EX_WINDOWEDGE | WS_EX_APPWINDOW;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; dwStyle = WS_OVERLAPPEDWINDOW; &lt;span style=&quot;color: #999999;&quot;&gt;/* la finestra ha i bordi */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* adatta la dimensione della finestra alla dimensione indicata dalla struttura wndrect e a seconda dello stile della finestra */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;AdjustWindowRectEx(&amp;amp;wndrect,dwStyle,&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;,dwExStyle);&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
E adesso possiamo procedere con la creazione della finestra principale, sulla quale andremo a disegnare. Nel codice generato abbiamo già la chiamata alla funzione che crea la finestra, però dobbiamo applicare qualche modifica per crearla in base ai valori delle variabili globali definite all&#39;inizio del programma:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;hwnd = CreateWindowEx(dwExStyle, &lt;span style=&quot;color: #999999;&quot;&gt;/* lo stile esteso */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;szClassName, &amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;/* nome della classe della finestra */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;TEXT(&lt;span style=&quot;color: red;&quot;&gt;&quot;Model Editor&quot;&lt;/span&gt;), &lt;span style=&quot;color: #999999;&quot;&gt;/* titolo della finestra */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, &lt;span style=&quot;color: #999999;&quot;&gt;/* stile */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;CW_USEDEFAULT, &lt;span style=&quot;color: #999999;&quot;&gt;/* posizione orizzontale definito da windows */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;CW_USEDEFAULT,&amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;/* posizione verticale definito da windows */&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wndrect.right-wndrect.left, &lt;span style=&quot;color: #999999;&quot;&gt;/* larghezza finestra */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;wndrect.bottom-wndrect.top, &lt;span style=&quot;color: #999999;&quot;&gt;/* altezza finestra */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;HWND_DESKTOP, &lt;span style=&quot;color: #999999;&quot;&gt;/* la finestra padre */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;NULL, &lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* nessun menu */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;hThisInstance, &lt;span style=&quot;color: #999999;&quot;&gt;/* istanza del programma */&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;NULL);&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
Con questa istruzione abbiamo creato la nostra finestra principale, che ha le impostazioni da noi richieste, quindi dobbiamo procedere con l&#39;inizializzazione di OpenGL. Il primo passo da fare in questa direzione è quello di impostare le caratteristiche dei pixel di cui è formata la nostra area di disegno. Quindi andremo a definire una nuova funzione che fa questo lavoro e visto che anche questa parte si riferisce all&#39;inizializzazione, la scriveremo dentro &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;init.cpp&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;GLvoid &lt;b&gt;SetGLPixelFormat&lt;/b&gt;(HWND hwnd, &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt; bits){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; GLuint pxFormat;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; HDC hDC;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; HGLRC hRC;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;/* definisce il formato dei pixel */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt;&lt;/b&gt; &amp;nbsp;PIXELFORMATDESCRIPTOR pfd = { &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;sizeof&lt;/span&gt;&lt;/b&gt;(PIXELFORMATDESCRIPTOR), &amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;/* dimensione struttura*/&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* numero della versione */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PFD_DRAW_TO_WINDOW | &lt;span style=&quot;color: #999999;&quot;&gt;/* supporta le finestre */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PFD_SUPPORT_OPENGL | &lt;span style=&quot;color: #999999;&quot;&gt;/* supporta opengl */ &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PFD_DOUBLEBUFFER, &lt;span style=&quot;color: #999999;&quot;&gt;/* supporta la doppia bufferizzazione */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PFD_TYPE_RGBA, &lt;span style=&quot;color: #999999;&quot;&gt;/* richiesto un fromato RGBA */ &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bits, &lt;span style=&quot;color: #999999;&quot;&gt;/* numero di bit per pixel */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* bit di colore ignorati */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* nessun buffer per la trasparenza */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* shift bit ignorato */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* nessun buffer di accumulazione */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* bit di accumulazione ignorati */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;16&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* buffer a 16 bit per la profondità */&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* nessun buffer per la matrice */ &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* nessun buffer ausiliario */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PFD_MAIN_PLANE, &lt;span style=&quot;color: #999999;&quot;&gt;/* disegno sul livello principale */&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #999999;&quot;&gt;/* riservato */ &amp;nbsp;&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt; &lt;span style=&quot;color: #999999;&quot;&gt;/* maschere di livello ignorate */ &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; };&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; hDC = GetDC(hwnd); &lt;span style=&quot;color: #999999;&quot;&gt;/* cattura l&#39;HDC della finestra principale */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; pxFormat = ChoosePixelFormat(hDC,&amp;amp;pfd); &lt;span style=&quot;color: #999999;&quot;&gt;/* sceglie il formato dei pixel */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; SetPixelFormat(hDC,pxFormat,&amp;amp;pfd); &lt;span style=&quot;color: #999999;&quot;&gt;/* imposta il formato dei pixel */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; hRC = wglCreateContext(hDC); &lt;span style=&quot;color: #999999;&quot;&gt;/* crea un contesto grafico */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; wglMakeCurrent(hDC,hRC); &lt;span style=&quot;color: #999999;&quot;&gt;/* lo imposta come corrente */&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Creata la funzione, dobbiamo aggiungere la sua definizione al file &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;functions.h&lt;/span&gt;, in modo che sia visibile a tutti i file del progetto, quindi aggiungiamo la seguente riga:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;GLvoid&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;SetGLPixelFormat&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(HWND hwnd,&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;bits);&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
A questo punto basta richiamarla nel file &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;main.cpp&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;SetGLPixelFormat(hwnd,bits); &lt;span style=&quot;color: #999999;&quot;&gt;/* imposta il formato dei pixel */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ShowWindow(hwnd,nCmdShow); &lt;span style=&quot;color: #999999;&quot;&gt;/* !!! generata dal ambiente di sviluppo */&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Dopo aver visualizzato la finestra procediamo con l&#39;inizializzazione di opengl e del modo in cui verranno visualizzate le figure disegnate con questa libreria. E anche questa volta creiamo una funzione esterna per fare questo lavoro, inoltre, definiamo un&#39;altra funzione, che si occuperà di impostare la prospettiva a seconda della dimensione della finestra. Entrambe le funzioni andranno scritte in &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;init.cpp&lt;/span&gt;&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt; &lt;b&gt;InitGL&lt;/b&gt;(GLvoid){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;/* imposta il colore di pulizia dello schermo */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glClearColor(&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.5f&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glClearDepth(&lt;span style=&quot;color: purple;&quot;&gt;1.0f&lt;/span&gt;); &lt;span style=&quot;color: #999999;&quot;&gt;/* la profondità della pulizia */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;/* abilita la scrittura sul buffer di profondità */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glEnable(GL_DEPTH_TEST);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; &lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* se tutto va bene termina con lo 0 */&lt;/span&gt; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;GLvoid &lt;b&gt;ResizeGLScene&lt;/b&gt;(GLsizei width, GLsizei height){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; height = height==&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;?&lt;span style=&quot;color: purple;&quot;&gt;1&lt;/span&gt;:height; &lt;span style=&quot;color: #999999;&quot;&gt;/* evita divisione per zero */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glViewport(&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;,width,height); &lt;span style=&quot;color: #999999;&quot;&gt;/* imposta la vista */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;/* seleziona la matrice della progettazione */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glMatrixMode(GL_PROJECTION);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glLoadIdentity(); &lt;span style=&quot;color: #999999;&quot;&gt;/* resetta la matrice */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;/* calcola la prospettiva con la profondità massima a 100 */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; gluPerspective(&lt;span style=&quot;color: purple;&quot;&gt;45.0f&lt;/span&gt;,(GLfloat)width/(GLfloat)height,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;color: purple;&quot;&gt;1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;100.0f&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;/* seleziona la matrice di visualizzazione delle figure */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glMatrixMode(GL_MODELVIEW);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glLoadIdentity(); &lt;span style=&quot;color: #999999;&quot;&gt;/* resetta la matrice */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Ovviamente al file functions.h dovremo aggiungere:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;InitGL&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(GLvoid);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;GLvoid&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ResizeGLScene&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(GLsizei width, GLsizei height);&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Come è possibile notare, in queste due funzioni per la prima volta abbiamo usato delle funzioni che appartengono alla libreria OpenGL. Vediamo in breve cosa rappresenta ognuna di queste funzioni:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glClearColor&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;specifica il colore che verrà utilizzato per cancellare l&#39;immagine disegnata precedentemente sullo schermo. I quattro parametri di tipo &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;GLfloat&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; possono assumere valori da 0.0f a 1.0f e rappresentano il colore espresso in RGBA, un formato che permette di definire anche la trasparenza di un colore.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glClearDepth&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;indica la profondità alla quale viene effettuata la pulizia dello schermo, cancellando tutto ciò che sta oltre a quella profondità. Bisogna tenere conto del fatto che OpenGL si prende la briga di occuparsi della visualizzazione delle figure nello spazio, per cui il programmatore deve soltanto indicare le coordinate di ogni figura e OpenGL deciderà quale parte della figura visualizzare e quale no, a seconda se viene coperta da un&#39;altra figura che ci copre la vista. Inoltre, si deve tenere a mente il fatto che se vogliamo indicare una profondità di 10.0f, dobbiamo indicarla come -10.0f, perché tutto ciò che vogliamo visualizzare si trova oltre lo schermo, cioè sulla parte negativa dell&#39;asse z.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glEnable(GL_DEPTH_TEST)&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;abilita l&#39;utilizzo del buffer di profondità. In genere la funzione &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;glEnable&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt; viene utilizzata per abilitare diverse funzionalità della libreria, come, ad esempio, l&#39;abilitazione della luminosità o della visualizzazione delle texture.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glViewport&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;viene utilizzata per impostare i parametri utilizzati per la trasformazione delle immagini di un ambiente tridimensionale in uno bidimensionale, per produrre la sensazione di avere un mondo 3D dietro lo schermo.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glMatrixMode()&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;seleziona una delle matrici utilizzate per la generazione dell&#39;immagine 3D desiderata. Le due matrici finora utilizzate sono la matrice di visualizzazione e la matrice della gestione delle figure dell&#39;ambiente tridimensionale. La prima, chiamata projection matrix viene utilizzata per produrre le immagini 2D partendo dall&#39;ambiente 3D, in modo da poterle visualizzare sullo schermo, che rappresenta, appunto, &amp;nbsp;un ambiente bidimensionale. La seconda, invece, chiamata modelview matrix che serve per definire il posizionamento delle figure in un ambiente 3D.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glLoadIdentity()&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;utilizzata molto spesso, perché permette di reimpostare la matrice sulla quale si sta lavorando ad una matrice identica, che rappresenta la situazione iniziale.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;gluPerspective&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;imposta i parametri della prospettiva da usare, il primo argomento indica il tipo di prospettiva a 45°, il secondo indica il rapporto larghezza/altezza, il terzo e il quarto indicano il minimo e il massimo della profondità, oltre la quale la figura sparisce.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Chiusa la parentesi, procediamo con il nostro programma. Sempre nel file &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;main.cpp&lt;/span&gt; subito dopo la visualizzazione della finestra facciamo una chiamata alla funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;InitGL&lt;/span&gt;, seguita dalla chiamata alla funzione&amp;nbsp;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ResizeGLScene&lt;/span&gt;, dopodiché scriviamo il codice generato da Dev C++, leggermente modificato, per integrarsi con OpenGL. Le modifiche da efettuare stanno nel ciclo di elaborazione dei messaggi. Vediamo il codice:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;InitGL();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ResizeGLScene(width,height);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;hDC = GetDC(hwnd); &lt;span style=&quot;color: #999999;&quot;&gt;/* ottiene l&#39;HDC della finestra */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt; done = &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;&lt;/b&gt;; &lt;span style=&quot;color: #999999;&quot;&gt;/* tiene aperto il ciclo */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt;&lt;/b&gt; (!done){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;/* cattura gli eventi della finestra */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (PeekMessage(&amp;amp;messages,NULL,&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0&lt;/span&gt;,PM_REMOVE)){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;/* se arriva il messaggio di chiusura */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (messages.message==WM_QUIT){&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; done = &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;&lt;/b&gt;; &amp;nbsp;&lt;span style=&quot;color: #999999;&quot;&gt;/* esce dal ciclo e chiude il programma */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TranslateMessage(&amp;amp;messages); &lt;span style=&quot;color: #999999;&quot;&gt;/* decodifica il messaggio */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DispatchMessage(&amp;amp;messages); &lt;span style=&quot;color: #999999;&quot;&gt;/* lo invia a&amp;nbsp;WindowProcedure&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp;*/&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;/b&gt;{ &lt;span style=&quot;color: #999999;&quot;&gt;/* se non ci sono messaggi */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #999999;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* disegna la scena da visualizzare */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; (DrawGLScene(keys,x,y,left_down)){ &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SwapBuffers(hDC); &lt;span style=&quot;color: #999999;&quot;&gt;/* scambia il buffer */ &lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Con questo abbiamo concluso la definizione della funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;WinMain&lt;/span&gt;, però ciclo di elaborazione dei messaggi abbiamo utilizzato la funzione &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DrawGLScene&lt;/span&gt;, che non abbiamo ancora definito, per cui andiamo subito a definirla. Visto che questa funzione ci serve per disegnare nella finestra andremo a definirla nel file &lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;draw.cpp&lt;/span&gt;, finora non utilizzato:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt; &lt;b&gt;DrawGLScene&lt;/b&gt;(&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;bool&lt;/b&gt;&lt;/span&gt; keys[], &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt; x, &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt; y, &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt; left_down){ &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glLoadIdentity(); &lt;span style=&quot;color: #999999;&quot;&gt;/* reimposta la matrice */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glTranslatef(&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;-5.0f&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glBegin(GL_QUADS);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; glVertex3f(&lt;span style=&quot;color: purple;&quot;&gt;-1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;glVertex3f(&lt;span style=&quot;color: purple;&quot;&gt;1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;glVertex3f(&lt;span style=&quot;color: purple;&quot;&gt;1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;-1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;glVertex3f(&lt;span style=&quot;color: purple;&quot;&gt;-1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;-1.0f&lt;/span&gt;,&lt;span style=&quot;color: purple;&quot;&gt;0.0f&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; glEnd();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;return true&lt;/span&gt;&lt;/b&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Come per le altre funzioni definite esternamente anche questa deve essere dichiarata in&amp;nbsp;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;functions.h&lt;/span&gt;&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DrawGLScene&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: blue; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;bool&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;keys[],&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;x,&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;y,&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;bool&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;left_down);&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Abbiamo creato un&#39;altra funzione, ma vediamo un attimo come è fatta:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;la seguente funzione della libreria OpenGL esegue la pulizia dello schermo alla profondità indicata. Viene fatta subito prima di disegnare un&#39;altra immagine.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glTranslatef&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;trasla l&#39;origine delle coordinate al punto indicato nelle coordinate, per cui ogni figura disegnata dopo questa istruzione verrà posizionata rispetto al nuovo origine. La funzione prende in input 3 parametri che indicano le coordinate x, y e z rispettivamente, che devono essere di tipo &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;. Esistono varie versioni di questa funzione:&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;glTranslatei&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;glTranslated&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;, che prendono in ingresso interi.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glBegin(GL_QUADS)&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;indica l&#39;inizio della definizione delle coordinate dei vertici di una figura, che in questo caso è una quadrica, ma possono essere linee, triangoli, poligoni, a seconda del valore passato alla funzione. In base alla figura che si vuole disegnare cambia anche il numero di vertici che dobbiamo definire.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glVertex3f&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;definisce un vertice della figura che viene disegnata. La funzione, analogamente a &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;glTranslatef&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;, prende in ingresso 3 parametri di tipo &lt;/span&gt;&lt;span style=&quot;background-color: #ffe599; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;, che rappresentano le coordinate del vertice rispetto all&#39;origine corrente. Anch&#39;essa può prendere in input più tipi di dati, a seconda dell&#39;ultima lettera del nome, che indica, appunto, il tipo dei dati.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;glEnd()&lt;/span&gt; - &lt;/span&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;indica la fine della definizione della figura.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Ormai siamo quasi arrivati alla fine, perché ci resta soltanto aggiungere qualche ramo allo switch di &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;WindowProcedure&lt;/span&gt;&lt;/span&gt;, che si trova in main.cpp, per gestire gli eventi di movimento del mouse, della pressione dei tasti e del ridimensionamento della finestra. Quindi aggiungiamo allo &lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;switch&lt;/span&gt;&lt;/span&gt; il seguente codice:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codice&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;case&lt;/span&gt;&lt;/b&gt; WM_SIZE:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #999999;&quot;&gt;/* ricalcola la prospettiva e la dimensione dell&#39;ambiente a seconda della dimensione della finestra */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; ResizeGLScene(LOWORD(lParam),HIWORD(lParam));&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;case&lt;/span&gt;&lt;/b&gt; WM_MOUSEMOVE:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; x = LOWORD(lParam); &lt;span style=&quot;color: #999999;&quot;&gt;/* memorizza la posizione orizzontale del mouse */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; y = HIWORD(lParam); &lt;span style=&quot;color: #999999;&quot;&gt;/* memorizza la posizione verticale del mouse */&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;break&lt;/b&gt;&lt;/span&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;case&lt;/span&gt;&lt;/b&gt; WM_KEYDOWN:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* imposta a true l&#39;elemento con il codice del tasto premuto */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; keys[wParam]=&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;true&lt;/b&gt;&lt;/span&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;case&lt;/b&gt;&lt;/span&gt; WM_KEYUP:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* imposta a false l&#39;elemento con il codice del tasto premuto */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; keys[wParam]=&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;case&lt;/span&gt;&lt;/b&gt; WM_LBUTTONDOWN:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* mette a true alla pressione del bottone sinistro del mouse */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; left_down = &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;true&lt;/b&gt;&lt;/span&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;case&lt;/span&gt;&lt;/b&gt; WM_LBUTTONUP:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #999999; font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/* mette a false al rilascio del bottone sinistro del mouse */&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; left_down = &lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;false&lt;/b&gt;&lt;/span&gt;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;break&lt;/span&gt;&lt;/b&gt;;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
Così abbiamo completato il programma, che deve soltanto disegnare una quadratica (quadrato nel nostro caso), e quindi possiamo eseguirlo, ottenendo il seguente risultato:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIrxKOWh9dR1KGCdFqaIqlVJdT_VWjQyn8E69_2cQVu7z4coG_KYy2sn6NyfiO8y9oUXx5RHeFdSx9_klwe9qWM12BH8KH-egq1oNwFPzUHehPFhHp5nLzymsu6bi09zNW9z8G0XCsbg/s1600/impostazione_opengl_out.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHIrxKOWh9dR1KGCdFqaIqlVJdT_VWjQyn8E69_2cQVu7z4coG_KYy2sn6NyfiO8y9oUXx5RHeFdSx9_klwe9qWM12BH8KH-egq1oNwFPzUHehPFhHp5nLzymsu6bi09zNW9z8G0XCsbg/s320/impostazione_opengl_out.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Qualcuno di voi si sarà chiesto perché fare tutto questo lavoro per avere soltanto un quadrato, quando è possibile disegnare direttamente sulla finestra? Ma la risposta è molto semplice, perché una volta inizializzata la libreria OpenGL possiamo disegnare facilmente diverse figure, avendo uno spazio tridimensionale e avendo a disposizione le funzioni necessarie per muovere, ruotare etc. le figure create, oltre che ad una notevole velocità del programma, dato che OpenGL ha accesso diretto all&#39;interfaccia hardware che si occupa della grafica.&lt;br /&gt;
&lt;br /&gt;
Download progetto Dev C++: &lt;a href=&quot;https://docs.google.com/open?id=0By2Ltnut7Px3OGQxZGRiM2UtNjc0Mi00N2MwLTg1NTktOGUyMGNlYjk5NzRm&quot; target=&quot;_blank&quot;&gt;impostazione_opengl.zip&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/6091495277426629031/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/opengl-in-cc-impostazione-progetto.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6091495277426629031'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/6091495277426629031'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/opengl-in-cc-impostazione-progetto.html' title='OpenGL in C/C++ - Impostazione progetto'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWPbEei9f9zqrcIZlOOoA2Y1huE1JuKClUyD_vG2v6Kj9CSYlC-mDfrRXnyMSSDryHakE5yEiqddHxdibrukmYeMGWyu-iAcHnfF2eioC1nynSUhYkG2FWgkpSuIXtYkEH9P_h7v1CfEU/s72-c/schermata_linker.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-1907138867675348380</id><published>2011-12-21T18:49:00.002+01:00</published><updated>2011-12-22T13:30:04.454+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="OpenGL in C/C++"/><title type='text'>OpenGL in C/C++ - Introduzione</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;OpenGL è una libreria di C/C++ sviluppata appositamente per lo sviluppo di applicazioni grafiche, che comprendono elementi di disegno bidimensionale che il disegno di oggetti in 3D. Questa libreria è molto conosciuta nel giro degli sviluppatori di videogiochi, perché tale libreria permette lo sviluppo di applicazioni adatte a girare su più piattaforme, cosa che non si può dire del DirectX, sviluppato per la scrittura di programmi grafici che girano sotto Windows.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Il vantaggio di usare questa libreria è dovuto al fatto che essa propone una serie di funzioni già pronte per gestire il disegno in 2D e in 3D. Inoltre, la libreria possiede delle funzioni vitali nello sviluppo dei videogiochi, quali la rotazione, il movimento degli oggetti creati e la gestione automatica della prospettiva in base alla posizione degli oggetti nello spazio. Non è da meno il fatto che per la visualizzazione dei frame OpenGL accede direttamente alla componente hardware che risponde della visualizzazione, incrementando notevolmente la velocità di elaborazione delle immagini e quindi anche la velocità delle vostre applicazioni.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Per avere una maggiore affluenza ho deciso di utilizzare Dev C++ per la scrittura degli esempi pubblicati negli articoli, perché è un ambiente di sviluppo gratuito e contiene già la libreria OpenGL. Nonostante ciò cercherò di mettere le informazioni necessarie per gli sviluppatori che usano Visual Studio, ampliando la spiegazioni con i link ai progetti degli esempi sviluppati in entrambi gli ambienti di sviluppo.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Gli articoli di questa categoria sono indirizzati ai programmatori che hanno una buona conoscenza di C/C++ e dello sviluppo delle applicazioni API in questi linguaggi,&amp;nbsp;in quanto verranno affrontati soltanto argomenti relativi alla libreria OpenGL e non al linguaggio di programmazione.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/1907138867675348380/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/opengl-in-cc-introduzione.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/1907138867675348380'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/1907138867675348380'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/opengl-in-cc-introduzione.html' title='OpenGL in C/C++ - Introduzione'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-3595553401846850456</id><published>2011-12-21T14:07:00.011+01:00</published><updated>2011-12-21T19:16:23.035+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>C/C++ - Lettura testo dalla tastiera</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Nel post&amp;nbsp;&lt;a href=&quot;http://code-power.blogspot.com/2011/12/cc-hello-world.html&quot; target=&quot;_blank&quot;&gt;precedente&lt;/a&gt;&amp;nbsp;ho spiegato come creare il nostro primo programma in C/C++, che scrive in output il famoso saluto &quot;Hello, World!&quot;, ma non abbiamo ancora visto come fare a leggere del testo dalla tastiera. Beh, non è una cosa molto difficile, perché basta importare la libreria che ci interessa e utilizzare la funzione per la lettura del tasto premuto.&lt;/span&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Il modo più semplice è quello di usare un name space introdotto con il C++ chiamato cin&amp;nbsp;che sta per c input, ovvero lettura dai dispositivi di input. Vediamo ora il codice che ci permette di fare questa lettura:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilkMzcrCWLE9K51OlD-WGc5pEuTKqea_6BAr88q3ExkTh-yBuHLpZu3GV8Yx-UNMTkgFsrDCMlqaI18ZBDIyr9dzT04gKFV-DzKzuDwJwQubhoEgoz8OYJ5Nka6cNLOeRFjDQnL_J66PM/s1600/lettura_da_tastiera.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilkMzcrCWLE9K51OlD-WGc5pEuTKqea_6BAr88q3ExkTh-yBuHLpZu3GV8Yx-UNMTkgFsrDCMlqaI18ZBDIyr9dzT04gKFV-DzKzuDwJwQubhoEgoz8OYJ5Nka6cNLOeRFjDQnL_J66PM/s1600/lettura_da_tastiera.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Come possiamo vedere la struttura generale dei programma resta uguale a quella del programma di &quot;Hello, World!&quot;, cambiando soltanto il corpo della funzione &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;main&lt;/span&gt;.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Da notare è che con &#39;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;//&lt;/span&gt;&#39; viene indicato l&#39;inizio di un commento su una riga e tutto ciò che sta dopo &#39;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;//&lt;/span&gt;&#39; fino alla fine della riga verrà ignorato dal compilatore. &amp;nbsp;Se, invece, vogliamo scrivere un commento su più di una riga dobbiamo indicare l&#39;inizzio e la fine del commento con &#39;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;/*&lt;/span&gt;&#39; e &#39;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;*/&lt;/span&gt;&#39; rispettivamente.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Vediamo in dettaglio cosa fa ognuna delle istruzioni del corpo della nostra funzione:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;char buff[255]&lt;/span&gt; - crea un array lungo 255 elementi di tipo &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;char&lt;/span&gt;. In altre parole viene riservata una locazione di memoria per la scrittura di contenuti di tipo &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;char&lt;/span&gt;(carattere), la cui lunghezza è, appunto, 255. E` importante sapere che in C/C++ gli array di caratteri vengono interpretati come stringhe e anche se sono stati creati nuovi tipi che rappresentano le stringhe, questo tipo di rappresentazione viene usata molto, soprattutto da quelli che sono agli inizi.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cout &amp;lt;&amp;lt; &quot;Digita qualcosa: &quot;&lt;/span&gt; - con questa istruzione viene scritto in output il testo che segue dopo &#39;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&#39;. Nell&#39;esempio di &quot;Hello, World!&quot; abbiamo visto come scrivere del testo sullo schermo utilizzando la funzione &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf&lt;/span&gt;, mentre qui ho deciso di mostrarvi come è possibile fare la stessa cosa, utilizzando le novità introdotte con l&#39;avvento di C++. In questo esempio è stato usato il name space &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cout&lt;/span&gt;, dichiarato con la 4° riga del codice, dicendo di utilizzare il name space &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;std&lt;/span&gt;(standard), che reindirizza con l&#39;operatore &#39;&amp;lt;&amp;lt;&#39; il flusso di dati in output, inviando tutto quello che sta dopo tale operatore. Il risultato è la scrittura sullo schermo del testo &quot;Digita qualcosa: &quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cin.getline(buff,255)&lt;/span&gt; - con questa istruzione, riusciamo a leggere una linea di testo inserito dalla tastiera, cioè il testo digitato fino alla pressione del tasto &#39;Invio&#39;. Come possiamo notare la variabile &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cin&lt;/span&gt; non è stata dichiarata da nessuna parte, nonostante ciò l&#39;abbiamo utilizzata, perché anche essa è un name space come &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cout&lt;/span&gt;, però per gestire il flusso in input, che nel nostro caso è il testo digitato sulla tastiera. Il punto messo dopo &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cin&lt;/span&gt; indica che esso è un oggetto, che ha degli metodi, o in altre parole su di esso possono essere effettuate delle operazioni, che nel nostro caso è la lettura di una linea dal prompt dei comandi. Il metodo &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;getline&lt;/span&gt; ha due argomenti di cui il primo indica la variabile di tipo stringa(nel nostro caso un array di caratteri) nella quale andare a scrivere la sequenza dei caratteri premuti sulla tastiera, mentre il secondo argomento indica la lunghezza della stringa.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cout &amp;lt;&amp;lt; &quot;Hai scritto: &quot; &amp;lt;&amp;lt; buff &amp;lt;&amp;lt; endl&lt;/span&gt; - anche in questo caso viene usato il name space cout per scrivere il output, però questa volta abbiamo più operatori &#39;&amp;lt;&amp;lt;&#39;, che come se fossero degli &#39;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;+&lt;/span&gt;&#39; per concatenare tutti i termini. Infatti, in output avremo prima il testo &quot;Hai scritto: &quot;, dopodiché seguirà il contenuto di &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;buff&lt;/span&gt;, in cui è memorizzato il testo scritto da noi e infine &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;endl&lt;/span&gt;, che non è altro che una costante che indica la fine della linea e porta il cursore a capo di una nuova.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Adesso se provate ad eseguire il vostro programma &lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;dovreste&lt;/span&gt; vedere il seguente output:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisl4tdKkulIDib-sVvauLLoRPsesOG4rITrfoW4fnYdB87vPwapiM0Ga2k3mUDOfyHXYs7u-VevlbSpGmTc3CCshvUN-x6M8jfzgwtrVLJV2niQkOBUQdsooVERUVAfXelDex7GreoUGI/s1600/lettura_da_tastiera_out.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisl4tdKkulIDib-sVvauLLoRPsesOG4rITrfoW4fnYdB87vPwapiM0Ga2k3mUDOfyHXYs7u-VevlbSpGmTc3CCshvUN-x6M8jfzgwtrVLJV2niQkOBUQdsooVERUVAfXelDex7GreoUGI/s1600/lettura_da_tastiera_out.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Il programma sembra essere coretto, però se provate a digitare più di 255 caratteri il testo digitato viene troncato a 255 caratteri. Certo, potremo aumentare la lunghezza dell&#39;array buff, però non possiamo sapere la lunghezza del testo che verrà inserito dall&#39;utente e poi facendo così andremo a sprecare memoria. Questo problema è dovuto al fatto che in C nel momento della dichiarazione di un array dobbiamo indicare la sua lunghezza. Il problema può essere risolto con l&#39;aiuto dei puntatori e lo vedremo più avanti, ma questo è un altro argomento.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Download progetto Dev C++&amp;nbsp;&lt;a href=&quot;http://www.mediafire.com/?nkghrgh4cuc18g9&quot; target=&quot;_blank&quot;&gt;lettura_tastiera.zip&lt;/a&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Non dimenticate del +1 :)&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/3595553401846850456/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/cc-lettura-testo-da-tastiera.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/3595553401846850456'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/3595553401846850456'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/cc-lettura-testo-da-tastiera.html' title='C/C++ - Lettura testo dalla tastiera'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEilkMzcrCWLE9K51OlD-WGc5pEuTKqea_6BAr88q3ExkTh-yBuHLpZu3GV8Yx-UNMTkgFsrDCMlqaI18ZBDIyr9dzT04gKFV-DzKzuDwJwQubhoEgoz8OYJ5Nka6cNLOeRFjDQnL_J66PM/s72-c/lettura_da_tastiera.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-2423546794495761039</id><published>2011-12-20T19:36:00.005+01:00</published><updated>2011-12-21T19:08:21.873+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>C/C++ - Hello, World!</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Nel post &lt;a href=&quot;http://code-power.blogspot.com/2011/12/c-introduzione.html&quot; target=&quot;_blank&quot;&gt;C/C++ - Introduzione&lt;/a&gt;&amp;nbsp;sono state spiegate a grande linee le caratteristiche di C/C++, ma non abbiamo ancora visto come scrivere il famoso &quot;Hello, World!&quot; in questi linguaggi, per cui procedo immediatamente con la spiegazione, ma prima di iniziare dovete procurarvi un compilatore, che tradurrà il vostro codice in programmi eseguibili. &lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Un ottimo IDE, cioè un ambiente di sviluppo, che&amp;nbsp;naturalmente&amp;nbsp;ha integrato anche un compilatore C++ è il Dev C++ scaricabile gratuitamente da&amp;nbsp;&lt;a href=&quot;http://www.bloodshed.net/devcpp.html&quot; target=&quot;_blank&quot;&gt;qui&lt;/a&gt;. Per chi vuole invece un ambiente di sviluppo più professionale può procurarsi il Visual Studio della Microsoft, che però non è gratuito.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Comunque, a prescindere dal ambiente di sviluppo il procedimento è molto simile e differisce solo in alcune situazioni, dovute alle divergenze tra le librerie dei due ambienti di sviluppo, ma per adesso non preoccupiamoci della cosa e procediamo con il nostro &quot;Hello, World!&quot;.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ho deciso di illustrare lo sviluppo dei programmi utilizzando Dev C++, ma ripeto il procedimento è molto simile anche per Visual Studio e in questo caso non ci sono divergenze nel codice. Quindi apriamo il nostro ambiente di sviluppo e andiamo in &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;File-&amp;gt;New-&amp;gt;Project&lt;/span&gt;&amp;nbsp;e subito dopo si apre una nuova finestra dove scegliamo &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Console Application&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;. Nella casella di testo in basso inserite il nome del progetto che volete creare e scegliete il linguaggio in quale volete scrivere il vostro programma (vi consiglio C++), dopodiché date l&#39;ok. L&#39;ambiente di sviluppo genera il seguente codice:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivAyuYWeL4d6_XGnDFpC4yBwaUlb07cbq-Y4bRRTvOJ8u50_D4dfK878XSN3CMQJT5gQh5oe-F1FHZV_HuGqd5F56UOcSAQsEKXKG4LGAYn5zrhZmLvvqYprMdWbXsT4J4pdRjEcVkJ60/s1600/gen_code.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivAyuYWeL4d6_XGnDFpC4yBwaUlb07cbq-Y4bRRTvOJ8u50_D4dfK878XSN3CMQJT5gQh5oe-F1FHZV_HuGqd5F56UOcSAQsEKXKG4LGAYn5zrhZmLvvqYprMdWbXsT4J4pdRjEcVkJ60/s1600/gen_code.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Se eseguito, questo programma sostanzialmente non fa nulla, ma nonostante ciò è un programma funzionante. Questo formato di programma di default è stato introdotto con l&#39;arrivo di C++.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Riassumendo con le prime due righe vengono caricate due librerie che contengono le funzioni già definite per poter eseguire alcune operazioni di base come la scrittura sull&#39;output oppure la lettura dei tasti premuti sulla tastiera.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;La 4° riga, invece, definisce una serie di nomi che potremo utilizzare per eseguire velocemente operazioni di input/output e altro.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Nella 6° riga viene fata la definizione della funzione funzione, chiamata &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;, che rappresenta il punto di entrata nel nostro programma e il nome di questa funzione deve essere necessariamente &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;. La prima parola di questa riga (&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;) indica che al termine della funzione deve essere restituito un valore intero, che indicherà il codice d&#39;uscita, dal quale il sistema operativo può capire se il programma è terminato con successo, oppure si è verificato un errore durante l&#39;esecuzione del programma. I due argomenti della funzione &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;argc&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt; e &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;argv&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt; non sono vitali, cioè si possono anche omettere, ma sono necessari nei casi in cui al programma vengono passati argomenti dalla linea di commando (Prompt dei comandi in Windows).&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Tutto ciò che è compreso tra &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt; e &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt; viene chiamato corpo della funzione e le istruzioni contenute nel corpo della funzione vengono eseguite dal alto verso il basso nel momento in cui viene fatta una chiamata a tale funzione. Quindi quando eseguite il vostro programma il sistema operativo non fa altro che chiamare quella funzione.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;L&#39;ottava riga del codice non fa altro che inviare un comando al prompt dei comandi di mettersi in pausa e attendere la pressione di un tasto prima di terminare il programma. Questa funzione fa parte della libreria &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;cstdlib.h&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;, per cui nella prima riga l&#39;abbiamo inclusa nel nostro progetto.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;La 9° riga rappresenta l&#39;uscita dal nostro programma, infatti con la parola chiave &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;return&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt; viene restituito un valore del tipo della funzione, dopodiché viene effettuata l&#39;uscita dalla funzione. La scritta &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;EXIT_SUCCESS&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp;identifica una costante intera di valore 0, che indica il termine del programma con successo.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Ma come abbiamo visto il programma non scrive nulla e noi vogliamo che scriva sull&#39;output &quot;Hello, World!&quot;. Per questo non dobbiamo far altro che aggiungere l&#39;istruzione &lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;printf(&quot;Hello, World!\n&quot;);&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&amp;nbsp;che scriverà sullo schermo il testo fra apici. Il carattere &#39;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;\n&lt;/span&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&#39; serve a spostare il cursore su una nuova riga,cosa che non viene fatto in automatico. Vediamo come cambia il codice del programma:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWgr1DO7PLJAkbDBEmhdL1EEITIxOkqGE9yB2urCaGliYZ6oXkKVcnU7u0xPk0bNdJfaBmUvSOPeUeo4pvDjkwW_6j9B7TAn_rAazaYQ3N5_ubnyDzS7F5bUeIiVXFJjECb8rEDzNdcv8/s1600/hello_world.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;182&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWgr1DO7PLJAkbDBEmhdL1EEITIxOkqGE9yB2urCaGliYZ6oXkKVcnU7u0xPk0bNdJfaBmUvSOPeUeo4pvDjkwW_6j9B7TAn_rAazaYQ3N5_ubnyDzS7F5bUeIiVXFJjECb8rEDzNdcv8/s320/hello_world.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;L&#39;istruzione per la scrittura del testo in output la mettiamo prima di mettere il prompt dei comandi in pausa. Per eseguire il programma basta premere F9, oppure andare in &lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Execute-&amp;gt;Compile &amp;amp; Run&lt;/span&gt;,&amp;nbsp;che compilerà il vostro codice, dopodiché lo eseguirà, producendo il seguente output:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1K41Ij4XooTtFDiunLk6macP2TSjFtXl7OmCz6SPN8dWAzP99i72n9cMrHNdldAbgLjG8PAyJIWL1u1UWyJ22GHk1_q-IiFWxINjv2wTbLskkYQQw2kydiJxJ_Ued6aNunMkzRC_-33k/s1600/hello_world_out.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;37&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1K41Ij4XooTtFDiunLk6macP2TSjFtXl7OmCz6SPN8dWAzP99i72n9cMrHNdldAbgLjG8PAyJIWL1u1UWyJ22GHk1_q-IiFWxINjv2wTbLskkYQQw2kydiJxJ_Ued6aNunMkzRC_-33k/s320/hello_world_out.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Con questo termina il nostro programma &quot;Hello, World!&quot;.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Download progetto Dev C++ &lt;a href=&quot;http://www.mediafire.com/?drjrb3zmmn4hjdl&quot; target=&quot;_blank&quot;&gt;hello_world.zip&lt;/a&gt;.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;Non dimenticate del +1 :)&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/2423546794495761039/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/cc-hello-world.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/2423546794495761039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/2423546794495761039'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/cc-hello-world.html' title='C/C++ - Hello, World!'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivAyuYWeL4d6_XGnDFpC4yBwaUlb07cbq-Y4bRRTvOJ8u50_D4dfK878XSN3CMQJT5gQh5oe-F1FHZV_HuGqd5F56UOcSAQsEKXKG4LGAYn5zrhZmLvvqYprMdWbXsT4J4pdRjEcVkJ60/s72-c/gen_code.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-1848641124073664504</id><published>2011-12-20T16:22:00.004+01:00</published><updated>2011-12-20T17:36:28.773+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C/C++"/><title type='text'>C/C++ - Introduzione</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;C è uno dei più conosciuti linguaggi di programmazione e come conseguenza anche il linguaggio nel quale sono stati scritti una grandissima parte dei programmi per i PC. Il suo successo è dovuto soprattutto al fatto che la Microsoft lo ha usato moltissimo per scrivere i programmi per i suoi primi sistemi operativi Windows.&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Il motivo per il quale il gigante ha deciso di sviluppare i suoi programmi utilizzando proprio C è che questo linguaggio ha la particolarità di essere un linguaggio di alto livello, ovvero un linguaggio di programmazione molto simile al linguaggio umano, ma nonostante ciò è possibile scendere di livello per arrivare quasi al livello macchina. Questa particolarità permette di sviluppare velocemente programmi di grandi dimensioni, avendo a tempo stesso l&#39;accesso diretto al hardware e avendo la possibilità di sviluppare praticamente qualunque tipo di programma.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Un&#39;altro punto di forza del C è la velocità dei programmi scritti in questo linguaggio di programmazione, visto che il compilatore traduce le istruzioni di C in istruzioni Assembler, che è il linguaggio più vicino al linguaggio macchina e anche se viene considerato un linguaggio in via di estinzione attualmente è ancora molto utilizzato per la scrittura dei programmi che richiedono prestazioni elevate.&lt;br /&gt;
Molti credono che C e C++ sono lo stesso linguaggio di programmazione, ma non è così, perché C++ è un linguaggio di programmazione basato su C, ma che permette la creazioni di strutture come classi e introduce alcuni tipi e automatizzazioni. In altre parole il C++ è un&#39;ottimizzazione di C, per cui è sempre preferibile usare C++ che C per la scrittura dei programmi, anche perché C++ può essere chiamato un linguaggio ad oggetti, che è una caratteristica dei linguaggi di programmazione attuali.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/1848641124073664504/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/c-introduzione.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/1848641124073664504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/1848641124073664504'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/c-introduzione.html' title='C/C++ - Introduzione'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7315093977193209605.post-820015033839702326</id><published>2011-12-16T13:18:00.119+01:00</published><updated>2011-12-30T00:29:30.086+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="F#"/><title type='text'>F# - Introduzione</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;b&gt;F#&lt;/b&gt; è un linguaggio di programmazione molto giovane, sviluppato e mantenuto dal gigante &lt;b&gt;Microsoft&lt;/b&gt;, che ha deciso di includerlo nella famiglia &lt;b&gt;.Net&lt;/b&gt; (Dot Net) con l&#39;uscita del ambiente di sviluppo &lt;b&gt;Visual Studio 2005&lt;/b&gt;. Il vantaggio di sviluppare applicazioni in &lt;b&gt;F#&lt;/b&gt; usando &lt;b&gt;Visual Studio&lt;/b&gt; sta nel fatto che la famiglia &lt;b&gt;.Net&lt;/b&gt; contiene un gruppo di linguaggi di programmazione (C++/C#/Visual Basic/F#), permettendo di scrivere il programma utilizzando più linguaggi di programmazione assieme. Questo permette di sviluppare diversi tipi di applicazioni, a partire da console application e arrivando alle semplici applicazioni &lt;b&gt;GUI&lt;/b&gt; e videogiochi &lt;b&gt;3d&lt;/b&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Ma questo non è l&#39;unico punto di forza di &lt;b&gt;F#&lt;/b&gt;, perché esso porta con il suo arrivo anche un altro stile di programmazione, chiamato &lt;b&gt;programmazione funzionale&lt;/b&gt;. Questo tipo di programmazione viene considerato più semplice rispetto alla &lt;b&gt;programmazione procedurale&lt;/b&gt;, che caratterizza i linguaggi di programmazione come C++&lt;b&gt;,&lt;/b&gt; C#, Java etc. Esso, infatti, permette di tradurre facilmente l&#39;algoritmo per la risoluzione di un problema in codice di un programma, perché richiede soltanto di indicare i passaggi da fare per arrivare alla soluzioni desiderata, mentre nella programmazione procedurale bisogna pensare anche al modo in cui eseguire ogni passo del algoritmo, che nella maggior parte dei casi complica notevolmente il programma, mettendo in serie difficoltà i programmatori che sono alle prime armi.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Ad ogni modo F# non è l&#39;unico linguaggi di programmazione funzionale esistente, infatti, esso è stato sviluppato sulla base di un altro, sviluppato nel &lt;b&gt;1985&lt;/b&gt; da&lt;b&gt; INRIA&lt;/b&gt; e chiamato &lt;b&gt;CaML&lt;/b&gt;, che però non ebbe lo stesso successo di F# a causa della richiesta di elevate prestazioni dei computer. Con il tempo i computer sono diventati sempre più potente e quindi è stato possibile l&#39;impiego di questo tipo di linguaggi nello sviluppo di applicazioni.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Per chi non ha la possibilità di procurarsi Visual Studio, può comunque scaricare l&#39;ambiente di sviluppo di CaML, che è gratuito e molto leggero e studiare il CaML invece di F#, dato che i due linguaggi sono molto simili. L&#39;ambiente di sviluppo di CaML lo potete scaricare da &lt;/span&gt;&lt;a href=&quot;http://caml.inria.fr/download.en.html&quot; style=&quot;font-family: inherit;&quot; target=&quot;_blank&quot;&gt;http://caml.inria.fr/download.en.html&lt;/a&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;, però dovete ricordare che CaML è più rigido per quanto riguarda le operazioni tra interi e tra float, perché quando vogliamo sommare due numeri interi usiamo l&#39;operatore &#39;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;+&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&#39;, mentre per sommare due numeri con virgola mobile dobbiamo usare l&#39;operatore &#39;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;.+&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&#39;, altrimenti l&#39;interprete ci segnalerà un errore.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://code-power.blogspot.com/feeds/820015033839702326/comments/default' title='Commenti sul post'/><link rel='replies' type='text/html' href='http://code-power.blogspot.com/2011/12/f-introduzione.html#comment-form' title='0 Commenti'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/820015033839702326'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7315093977193209605/posts/default/820015033839702326'/><link rel='alternate' type='text/html' href='http://code-power.blogspot.com/2011/12/f-introduzione.html' title='F# - Introduzione'/><author><name>Sergiu</name><uri>http://www.blogger.com/profile/17369687058913465805</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>