tag:blogger.com,1999:blog-19260737118086535152024-03-13T08:34:05.186+01:00Learning LispA journey exploring Lisp languageThe Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-1926073711808653515.post-17880819648242131182018-11-26T14:28:00.000+01:002018-11-26T14:28:01.466+01:00<h2 style="text-align: justify;">
How do you specify a range of random numbers?</h2>
<div style="text-align: justify;">
<span style="font-size: small;">The Common Lisp function RANDOM takes two arguments: a limit and a random state. The first argument tells to the function that the generated random number could be one in the range of 0 <= n < limit, for example:</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: "Courier New", Courier, monospace;">CL-USER> (random 1000)</span></div>
<div style="text-align: justify;">
<span style="font-family: "Courier New", Courier, monospace;">860</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: "Courier New", Courier, monospace;"><span style="font-family: inherit;">or:</span></span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: "Courier New", Courier, monospace;">CL-USER> (random 1.0)</span></div>
<div style="text-align: justify;">
<span style="font-family: "Courier New", Courier, monospace;">0.2709539</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: "Courier New", Courier, monospace;"><span style="font-family: Georgia, "Times New Roman", serif;"><span style="font-size: small;">from these examples </span></span></span><span style="font-family: "Courier New", Courier, monospace;"><span style="font-family: Georgia, "Times New Roman", serif;"><span style="font-size: small;">we</span> clearly understand that limit could be an integer or float number. The second parameter passed to RANDOM is the random state, according to hyperspec <a href="http://clhs.lisp.se/Body/t_rnd_st.htm#random-state" target="_blank">http://clhs.lisp.se/Body/t_rnd_st.htm#random-state</a>) is an object which holds informations used by the random number generator inside the computer which are different from implementation to implementation.</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "Courier New", Courier, monospace;"><span style="font-family: inherit;"> </span> </span></div>
The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-41393437305527267332016-05-04T18:25:00.001+02:002021-03-15T23:40:05.780+01:00Know Your Tables?<br />
<div style="text-align: justify;">
<span style="font-family: inherit;">The <b>RANDOM</b> function has hundreds of uses in programming. Suppose, for example, you wanted a program to teach your eight-year-old son or brother his 9-times table. You could set it up like this:</span></div>
<br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;">(<span style="color: #38761d;">defun</span> table-guess () <br /> <span style="color: magenta;">"Let the boy guesses the table." </span><br /> (<span style="color: #38761d;">let</span> ((a 0))<br /> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;"><span style="background-color: white;">"What is 1 times 9? "</span></span>)<br /> (<span style="color: #38761d;">clear-input</span> *terminal-io*)<br /> (<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*)<br /> (<span style="color: #38761d;">when</span> (= a 9)<br /> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Correct~%"</span>))<br /> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"What is 2 times 9? "</span>)<br /> (<span style="color: #38761d;">clear-input</span> *terminal-io*)<br /> (<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*)<br /> (<span style="color: #38761d;">when</span> (<span style="color: #38761d;">=</span> a 18)<br /> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Correct~%"</span>))<br /> ...</span></span><br />
<br />
<br />
<div style="text-align: justify;">
...and so on. But this would give you a very long program - without even solving the problem of how the computer responds if one of this answer is wrong!</div>
<div style="text-align: justify;">
Use the <b>RANDOM</b> function, however, and you can produce a much more compact program that will not only ask all the right questions, but ask them in random order a much better way of teaching, as well as of programming.</div>
<div style="text-align: justify;">
Particularly when you are learning programming, it is always best to work out of the 'core' of a program before adding the frills. So first try these forms:</div>
<br />
<br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;">(<span style="color: #38761d;">let</span> ((n (<span style="color: #38761d;">1+</span> (<span style="color: #38761d;">random</span> 12)))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (a 0)) </span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"What is ~a times 9? "</span> n)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">when</span> (<span style="color: #38761d;">=</span> a (<span style="color: #38761d;">*</span> n 9))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Correct~%"</span>)))</span></span><br />
<br />
<div style="text-align: justify;">
this form is using <b>RANDOM</b> function in the same way as in the guessing game. The <b>LET</b> macro first set up two variables: one for the random number the computer selects and the other for user guessing. Then, with the same <b>LET</b> form, you tell the computer to pick a number - any integer number - between 1 and 12. (The <b>1+</b> function is necessary because the random numbers starts at 0 - a number not wanted for this job).</div>
<div style="text-align: justify;">
In the first <b>FORMAT</b> form you ask the player to multiply by 9 whichever number the computer has chosen this time. The <b>SETQ</b> special form actually take the console input and stores in the a variable. The <b>WHEN</b> macro warns the computer to multiply this number by 9, compare this with the player's answer and - if the latter is correct - print "Correct".</div>
<div style="text-align: justify;">
Execute this form and you will find that it works - once. You could make it continuous by modifying it as follows:</div>
<br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;">(<span style="color: #38761d;">loop</span> <span style="color: blue;">named</span> guess-table <span style="color: blue;">do</span></span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">let</span> ((n (<span style="color: #38761d;">1+</span> (<span style="color: #38761d;">random</span> 12)))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (a 0)) </span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"What is ~a times 9? "</span> n)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">when</span> (<span style="color: #38761d;">=</span> a (<span style="color: #38761d;">*</span> n 9))(</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Correct~%"</span>))))</span></span><br />
<br />
<div style="text-align: justify;">
...but why not do the job properly, as here:</div>
<br />
<br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;">(<span style="color: #38761d;">defun</span> guess-tables ()</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">let</span> ((player-name nil)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (n nil)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (a nil))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Hello. What is your name? "</span>)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">setq</span> player-name (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Hello, ~a, I have some questions for you~%" </span>player-name)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">sleep</span> 2)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">loop</span> <span style="color: blue;">named</span> game-loop <span style="color: blue;">do</span></span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">setq</span> n (<span style="color: #38761d;">1+</span> (<span style="color: #38761d;">random</span> 12)))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">loop</span> <span style="color: blue;">named</span> wrong-answer-loop <span style="color: blue;">do</span></span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"What is ~a times 9? "</span> n)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: blue;">if</span> (<span style="color: #38761d;">=</span> (<span style="color: #38761d;">*</span> n 9) a) <span style="color: blue;">do</span></span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Well done, ~a, here is the next one~%"</span> player-name)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">return-from</span> wrong-answer-loop)</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> <span style="color: blue;">else do</span></span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Sorry, please try again~%"</span>))</span></span><br />
<span style="font-size: small;"><span style="font-family: "courier new" , "courier" , monospace;"> (<span style="color: #38761d;">sleep</span> 1))))</span></span><br />
<br />
<div style="text-align: justify;">
the <b>SLEEP</b> function simply waste time, by making the computer 'count up to' a certain number before springing the next question on your unsuspecting infant. (How it does this is in Common Lisp Programming 2).</div>
<div style="text-align: justify;">
From the viewpoint of your eight-year-old, this function has one terrible disadvantage: it goes on and on without stopping. You can release him from this misery, like this: push CTRL, then C and when the interpreter drops in the debugger press Q.</div>
<div style="text-align: justify;">
From your viewpoint, on the oder hand, the program has a bonus feature: simply by changing the 9s in the function to 5s, 6s, 7s or whatever, you can test him on all his tables.</div>
<div style="text-align: justify;">
And because the computer does all the computations, you do not need to know any of the answers yourself!</div>
<div style="text-align: justify;">
Anyway to avoid the program to be changed for every table, let render the <b>GUESS-TABLES</b> function more general:</div>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;">(<span style="color: #38761d;">defun</span> guess-tables (base-number)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">let</span> ((player-name nil)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (n nil)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (a nil))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Hello. What is your name? "</span>)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">setq</span> player-name (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Hello, ~a, I have some questions for you~%"</span> player-name)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">sleep</span> 2)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">loop</span> <span style="color: blue;">named</span> game-loop <span style="color: blue;">do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">setq</span> n (<span style="color: #38761d;">1+</span> (<span style="color: #38761d;">random</span> 12)))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">loop</span> <span style="color: blue;">named</span> wrong-answer-loop <span style="color: blue;">do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"What is ~a times ~a? "</span> n base-number)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span style="color: blue;">if</span> (<span style="color: #38761d;">=</span> (<span style="color: #38761d;">*</span> n base-number) a) <span style="color: blue;">do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;">"Well done, ~a, here is the next one~%"</span> player-name)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">return-from</span> wrong-answer-loop)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span style="color: blue;">else do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">forma</span>t *terminal-io* <span style="color: magenta;">"Sorry, please try again~%"</span>))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">sleep</span> 1))))</span></span><br />
<br />
<div style="text-align: justify;">
Now would be fine if the computer could track down the number of guesses vs. the player's right answers:</div>
<div style="text-align: justify;">
</div><p>
<br />
</p><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;">(<span style="color: #38761d;">defun</span> guess-tables (base-number)</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">let</span> ((player-name nil)</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (correct-guesses 0) </span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (n nil)</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (a nil))</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io*</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span><span> <span> </span><span> </span></span></span>"Hello. What is your name? "</span>)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">setq</span> player-name (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;"> </span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span>"Hello, ~a, I have some questions for you~%"</span> </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span>player-name)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">sleep</span> 2)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">loop</span> <span style="color: blue;">named</span> game-loop</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span style="color: blue;">for</span> guess-count <span style="color: blue;">from</span> 1 </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: blue;"><span> </span><span> </span><span> </span>do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;"> </span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span>"~a correct guesses on ~a. Question #~a "</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span></span>correct-guesses </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span>(<span style="color: #38761d;">1-</span> guess-count) </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span>guess-count) </span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">setq</span> n (<span style="color: #38761d;">1+</span> (<span style="color: #38761d;">random</span> 12)))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">loop</span> <span style="color: blue;">named</span> wrong-answer-loop </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: blue;"><span> </span><span> </span><span> </span>do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">format</span> *terminal-io* </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> <span> </span></span>"What is ~a times ~a? "</span> </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>n</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>base-number)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span style="color: blue;"><span> </span>if</span> (<span style="color: #38761d;">=</span> (<span style="color: #38761d;">*</span> n base-number) a) <span style="color: blue;"> </span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: blue;"><span> </span><span> </span><span> </span>do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">format</span> *terminal-io* </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>"Well done, ~a, here is the next one~%"</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span></span>player-name)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span> (<span style="color: #38761d;">incf</span> correct-guesses) </span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">return-from</span> wrong-answer-loop)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span style="color: blue;"><span> </span>else</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: blue;"><span> </span><span> </span><span> </span>do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">format</span> *terminal-io*</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span style="color: magenta;">"Sorry, please try again~%"</span>))</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span> (<span style="color: #38761d;">sleep</span> 1))))</span></span></div><p>
<br />
(<span style="color: #38761d;">guess-tables</span> 2)<br />
<br />
</p><div style="text-align: justify;">
As you can see to advance towards the next question, the player must enter the correct answer, this is not the case. In fact if the player needs to end the game he/she has to enter CTRL+C and the Q keys. Let's modify again to prevent this:</div><p>
<br />
</p><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;">(<span style="color: #38761d;">defun</span> guess-tables (base-number)</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">let</span> ((player-name nil) </span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (correct-guesses 0) </span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (n nil)</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (a nil))</span></span></div><div style="text-align: left;">
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io* </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span>"Hello. What is your name? "</span>)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">setq</span> player-name (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;"> </span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span></span>"Hello, ~a, I have some questions for you~%"</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span></span>player-name)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">sleep</span> 2)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> (<span style="color: #38761d;">loop</span> </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: blue;"><span> </span><span> </span>named</span> game-loop</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span style="color: blue;"><span> </span><span> </span>for</span> guess-count <span style="color: blue;">from</span> 1</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span> <span style="color: blue;">do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">format</span> *terminal-io* <span style="color: magenta;"> </span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span>"~a correct guesses on ~a. Question #~a "</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> <span> </span></span></span>correct-guesses</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span>(<span style="color: #38761d;">1-</span> guess-count)</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span>guess-count)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">setq</span> n (<span style="color: #38761d;">1+</span> (<span style="color: #38761d;">random</span> 12)))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">format</span> *terminal-io* </span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span>"What is ~a times ~a? "</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span></span>n</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span>base-number)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">clear-input</span> *terminal-io*)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">setq</span> a (<span style="color: #38761d;">read</span> *terminal-io*))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">if</span> (<span style="color: #38761d;">=</span> (<span style="color: #38761d;">*</span> n base-number) a)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> <span> </span></span>(<span style="color: #38761d;">progn</span> </span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span><span> </span>(<span style="color: #38761d;">format</span> *terminal-io*</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>"Well done, ~a, here is the next one~%"</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> <span> </span><span> </span></span></span>player-name)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span><span> </span>(<span style="color: #38761d;">incf</span> correct-guesses))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span><span> </span>(<span style="color: #38761d;">format</span> *terminal-io*</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>"Sorry, wrong answer.~%"</span>)) </span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">sleep</span> 1)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span style="color: blue;"><span> <span></span></span>unless</span> (<span style="color: #38761d;">yes-or-no-p</span> <span style="color: magenta;">"Another game? "</span>)</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span style="color: blue;">do</span></span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span>(<span style="color: #38761d;">format</span> *terminal-io*</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span>"Bye ~a, you scored ~a on ~a correct answers.~%"</span></span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span><span> </span></span>player-name</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span>correct-guesses</span></span></div><div style="text-align: left;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><span> </span><span> </span><span> </span><span> </span><span> </span>guess-count)</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"> <span> </span><span> </span>(<span style="color: #38761d;">return-from</span> game-loop))))</span></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;"><br /></span></span>
<span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: small;">(<span style="color: #38761d;">guess-tables</span> 3)</span></span><span style="font-family: inherit; font-size: small;"><span style="font-family: inherit; font-size: xx-small;"><span style="font-size: xx-small;"><span style="font-family: inherit;"><span style="font-size: xx-small;"><span style="font-family: inherit;"><span style="font-size: xx-small;"><span style="font-family: inherit;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="color: cyan;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-size: xx-small;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="color: black;"><span style="color: cyan;"> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br />
</div><div class="code" style="text-align: justify;">
<span style="font-family: inherit; font-size: small;"><span style="font-family: inherit; font-size: xx-small;"><span style="font-size: xx-small;"><span style="font-family: inherit;"><span style="font-size: xx-small;"><span style="font-family: inherit;"><span style="font-size: xx-small;"><span style="font-family: inherit;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="color: cyan;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: "courier new" , "courier" , monospace;"><span style="font-family: inherit;"><span style="color: black;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"><span style="font-family: inherit;"> </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div>
The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0Rome, Italy41.9027835 12.49636550000002441.524646 11.850918500000024 42.280921 13.141812500000025tag:blogger.com,1999:blog-1926073711808653515.post-56112897382151840182015-03-31T17:34:00.002+02:002016-05-04T14:27:17.635+02:00What if Village People guys were CL programmers???<br />
<br />
-Login <br />
-CL hotline hyperspec<br />
-What's your credit card number?<br />
-69667113<br />
-Your ip address?<br />
-7.51.61.77<br />
-What's your preferred programming language?<br />
-I just wanna code in a very hot way<br />
-We'll ssh you back<br />
<br />
Sexp over the net<br />
Sexp over the net<br />
Sexp over the net<br />
Sexp over the net<br />
<br />
Well I just want to code<br />
Lately I smile with emacs mode<br />
Lately dsl is never down<br />
lately I never frown<br />
At home or in the car<br />
don't matter where you are<br />
Don't wanna be a weasel<br />
you just pick up CL REPL<br />
<br />
Sexp over the net<br />
You know I like it<br />
Sexp over the net<br />
You know I code it<br />
Sexp over the net<br />
Come on and give it to me baby<br />
Sexp over the net<br />
<br />
When I want to write a database I don't have to go SQL<br />
I don't need to read books if I'm feeling lazy<br />
I can lie there in my bed writing code in my REPL<br />
I just touch my keys and I go crazy<br />
<br />
Sexp over the net<br />
In the morning<br />
Sexp over the net<br />
In the afternoon<br />
Sexp over the net<br />
Sometimes late in the evening<br />
Sexp over the net<br />
<br />
This is the part I hate<br />
why do they make you use Basic?<br />
Here's where the rage rise<br />
Enough to cross my eyes<br />
<br />
They can be short or long<br />
<br />
they can be with numbers or strings.<br />
I don't care not at all<br />
long as they go in the net<br />
<br />
Sexp over the net<br />
It's so fulfilling<br />
Sexp over the net<br />
They're always willing<br />
Sexp over the net<br />
Don't break connection baby<br />
Sexp over the net.<br />
<br />
-M-x slime<br />
-Connected! Hacks and glory await!<br />
-M-x slime<br />
-Connected. Take this REPL, brother, and may it serve you well.<br />
-M-x slime<br />
-Connected. May the source be with you!<br />
<br />
Sexp over the net<br />
My.... is my....<br />
Sexp over the net<br />
my eyes<br />
Sexp over the net<br />
I need a REPL<br />
<br />
It's coding that you need<br />
satisfaction guaranteed<br />
It won't cost that much for you to start programming lisp<br />
It's a very small amount on your time account<br />
Come on let your fingers do the walking<br />
<br />
Sexp over the net<br />
Sexp over the net<br />
Sexp over the net<br />
Sexp over the net<br />
Sexp over the net<br />
They're always willing<br />
Sexp over the net<br />
It's so fulfilling<br />
Sexp over the net<br />
Come on and give it to me baby<br />
Sexp over the net<br />
<br />
If you are feelin' a geek and after all who's not?<br />
Right now I've got a cure to help your feature<br />
All that you need's a slime and just a little time<br />
A pay dsl on the street can help you beat the heat<br />
<br />
Sexp over the net<br />
You know I like it The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-44850061965158958632015-01-14T18:36:00.005+01:002021-03-16T12:52:07.259+01:00Think of a number... Any number.<style type="text/css">
<!--
.code {
color: #00ff00;
background-color: #000000;
text-align: justify;
}
.cl-function {
/* font-lock-cl-function-face */
color: #1e90ff;
font-weight: bold;
}
.cl-special-operator {
/* font-lock-cl-special-operator-face */
color: #8a2be2;
font-weight: bold;
}
.cl-system-class {
/* font-lock-cl-system-class-face */
color: #20b2aa;
font-weight: bold;
}
.cl-type {
/* font-lock-cl-type-face */
color: #3cb371;
font-weight: bold;
}
.slime-repl-input {
/* slime-repl-input-face */
font-weight: bold;
}
.slime-repl-inputed-output {
/* slime-repl-inputed-output-face */
color: #ff0000;
}
.slime-repl-output {
/* slime-repl-output-face */
color: #7cfc00;
}
.slime-repl-prompt {
/* slime-repl-prompt-face */
color: #00ffff;
}
.slime-repl-result {
}
.string {
/* font-lock-string-face */
color: #da70d6;
}
.comint-highlight-input {
/* comint-highlight-input */
font-weight: bold;
}
.comint-highlight-prompt {
/* comint-highlight-prompt */
color: #00ffff;
}
.comment {
/* font-lock-comment-face */
color: #ff0000;
}
-->
</style>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjneoNFIsSLtdnhgnM29dHfJ9-Gtpve1LvFP5JA8bhdVcIZRX7Q9zEqk-QN3lQPMaeRaWTLQxePETZGMoYG9W6l4m0e4-1UmnHmsGWGuO0hTHZ2c72nfytwueXtJdBSgtd57DMvu1Xc3V6/s1600/IMG_2325.JPG" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;">
<img border="0" height="213" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjneoNFIsSLtdnhgnM29dHfJ9-Gtpve1LvFP5JA8bhdVcIZRX7Q9zEqk-QN3lQPMaeRaWTLQxePETZGMoYG9W6l4m0e4-1UmnHmsGWGuO0hTHZ2c72nfytwueXtJdBSgtd57DMvu1Xc3V6/s1600/IMG_2325.JPG" width="320" />
</a>
</div>
<div style="text-align: justify;">
Learning to program it's not an easy task: there are several aspects to consider, for example which language and system. One could even start learn programming for the <a href="http://en.wikipedia.org/wiki/Embedded_system" target="_blank">embedded</a> world directly in assembly or choose to master WEB development with <a href="http://en.wikipedia.org/wiki/JavaScript" target="_blank">javascript</a>. Anyway we think that the learning process is more efficient when it's carried out with practical examples so let's start!</div>
<div style="text-align: justify;">
</div>
<h3 style="text-align: justify;">
</h3>
<h3 style="text-align: justify;">
Guessing the number.</h3>
<div style="text-align: justify;">
The easiest of all computer games to program is the one in which the computer choose randomly from a set of integer numbers and the user tries to guess it. To start programming without installing anything on the computer you can use <a href="http://iplwcl.informatimago.com/" target="_blank">this site</a> and follow its instruction to setup an user account. After you logged in you face the <a href="http://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop" target="_blank">REPL</a> with input point represented by a "?"</div>
<div style="text-align: justify;">
</div>
<h4 style="text-align: justify;">
</h4>
<h4 style="text-align: justify;">
The random function.</h4>
<div style="text-align: justify;">
All Common Lisp implementations have a <a href="http://www.lispworks.com/documentation/lw60/CLHS/Body/f_random.htm" target="_blank">random</a> number generation function to allow people invent such games and others. As described in the <a href="http://www.lispworks.comhttp//www.lispworks.com/documentation/HyperSpec/Front//documentation/HyperSpec/Front/" target="_blank">hyperspec</a> the function random is:</div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
(random limit &optional random-state)</div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
It returns a number equal to zero or less than the limit parameter which could be integer or float. According to the book <a href="https://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/cltl2.html" target="_blank">"Common Lisp the Language, 2nd Edition"</a> (pag. 391) the random-state is an object used to maintain the state of the <a href="http://en.wikipedia.org/wihttp://en.wikipedia.org/wiki/Pseudorandom_number_generatorki/Pseudorandom_number_generator" target="_blank">pseudo-random-number generator</a> and is altered as a side effect of the random operation. Its default value is *random-state*. The random-state type is implementation-dependent; it means that it is possible to print out an object of this type and then read back but this may or may not work correctly in another implementation. Let's go on and enter from REPL:</div><div style="text-align: justify;"> </div>
<div style="text-align: justify;">
</div>
<div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;">(</span><span style="color: #6aa84f;">defparameter</span> <span style="color: orange;">*generator-random-state*</span> </span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"><span> </span><span> </span><span> </span><span> </span>(</span>make-random-state t<span style="color: cyan;">))</span> </span>
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;">(</span><span style="color: #6aa84f;">defparameter </span><span style="color: orange;">*minimum-guess-number*</span> 1 </span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span>"The smallest integer to choose from."</span><span style="color: cyan;">)</span> </span>
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;">(</span><span style="color: #6aa84f;">defparameter</span> <span style="color: orange;">*maximum-guess-number*</span> 10 </span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: magenta;"><span> </span><span> </span><span> </span><span> </span>"The greatest integer to choose from."</span><span style="color: cyan;">)</span></span>
<span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;">(</span><span style="color: #6aa84f;">defun </span><span style="color: blue;">generate-integer</span> <span style="color: cyan;">(</span>minimum-value maximum-value<span style="color: cyan;">)</span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: magenta;"> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: magenta;"><span> </span>"Gen</span></span><span style="font-family: "Courier New",Courier,monospace;"><span style="color: magenta;">erate a random number inside a span."</span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: magenta;"><span> </span></span></span><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;">(</span>+ minimum-value <span style="color: cyan;"> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"><span> <span> </span></span>(</span>random <span style="color: cyan;">(</span>1+ <span style="color: cyan;">(</span>- maximum-value minimum-value<span style="color: cyan;">))</span> </span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: orange;"><span> </span><span> </span><span> </span><span> </span>*generator-random-state*</span><span style="color: cyan;">)))</span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"> </span></span>
</div>
<div style="text-align: justify;">
So what have we done here is create a new function named GENERATE-INTEGER along with the special variable *generator-random-state*. Useful programs are often made of functions, called in a particular sequence, that accept zero, one or more parameters and returns single or more values. There's no a privileged function, like in other languages, where to start a program, since code execution is made by calling functions from REPL or from other functions. We entered another kind of form (defun ...) which is a "special form" the evaluation of this won't execute code in the sense of the function itself, but instruct the interpreter how to form our function. If we enter from REPL:</div>
<div style="text-align: justify;">
</div>
<div style="text-align: justify;">
<div class="code"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"> </span></span></div><div class="code"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;">(</span><span style="color: #6aa84f;">loop </span> </span></div><div class="code"><span style="font-family: "Courier New",Courier,monospace;"><span> </span>repeat 10</span></div><div class="code"><span style="font-family: "Courier New",Courier,monospace;"><span> </span>do</span>
<span style="font-family: "Courier New",Courier,monospace;"> <span> </span><span style="color: cyan;">(</span>format <span style="color: orange;">*terminal-io*</span> </span></div><div class="code"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: #a64d79;"><span> </span><span> </span><span> </span><span> </span>"~a "</span> <span style="color: cyan;"> </span></span></div><div class="code"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"><span> </span><span> </span><span> </span><span> </span>(</span>generate-integer 1 6<span style="color: cyan;">)))</span></span>
</div>
<br />
We obtain for example:</div>
<div style="text-align: justify;">
<span style="font-family: "Courier New",Courier,monospace;">6 4 1 6 3 4 3 3 5 4</span><br />
<br />
now let's move toward a proper user interface for a game and enter two more functions:<br />
<br />
<div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;">(</span><span style="color: #6aa84f;">defun</span> <span style="color: blue;">guess-an-integer</span> <span style="color: cyan;">(number-of-attempts)</span></span><span> </span></span></div><div class="code" style="margin-left: 40px; text-align: left;"><span style="font-family: courier;"><span><span style="color: magenta;"><span></span><span> </span>"Ask for the secret number for a limited number of times."</span></span></span></div><div class="code" style="margin-left: 40px; text-align: left;"><span style="font-family: courier;"><span><span style="color: magenta;"><span></span></span></span><span><span style="color: cyan;">(</span><span style="color: #6aa84f;">let</span> <span style="color: cyan;">((</span>secret-number <span style="color: cyan;">(</span>generate-integer <span style="color: cyan;">*minimum-guess-number*</span></span></span></div><div class="code" style="margin-left: 440px; text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;">*maximum-guess-number*)))</span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"> </span></span>
<span> <span> </span><span style="color: cyan;">(</span><span style="color: #6aa84f;">unless</span> <span style="color: cyan;">(</span>loop </span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span> </span><span> </span><span> </span><span> <span> </span></span>named <span style="color: cyan;">try-loop</span> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span> </span><span> </span><span> </span><span> </span><span> </span>for <span style="color: cyan;">i</span> from 1 upto <span style="color: cyan;">number-of-attempts</span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"><span> </span><span> </span><span> </span><span> </span></span><span> </span>do</span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span> </span><span> </span><span> </span><span> <span> </span><span> </span></span></span><span><span style="color: cyan;"><span></span>(</span>format <span style="color: orange;">*terminal-io*</span> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: #a64d79;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> <span> </span><span> </span></span>"try number ~a, insert a number from ~a to ~a: "</span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: #a64d79;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span></span><span style="color: cyan;">i</span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"><span style="color: orange;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>*minimum-guess-number*</span> <span style="color: orange;"> </span></span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"><span style="color: orange;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span></span> <span> </span>*maximum-guess-number*</span>)</span></span>
<span> <span style="color: cyan;"><span> </span><span> <span> </span><span> </span><span> </span><span> </span><span> </span><span> </span></span>(</span>finish-output <span style="color: cyan;"><span style="color: orange;">*query-io*</span>)</span> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"><span></span><span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span></span>(</span><span style="color: #6aa84f;">let</span> <span style="color: cyan;">((</span>guess <span style="color: cyan;">(</span>read <span style="color: orange;">*query-io*</span><span style="color: cyan;">)))</span> </span>
<span> <span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span style="color: cyan;"><span></span>(</span><span style="color: #6aa84f;">when</span> <span style="color: cyan;">(</span>= guess secret-number<span style="color: cyan;">)</span></span><span> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span> </span><span> </span><span> </span><span style="color: cyan;"><span><span> <span> </span><span> </span><span> </span><span> </span></span></span>(</span>format <span style="color: orange;">*terminal-io*</span> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: #a64d79;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>"Bingo! You did it in ~a attempts.~%"</span><span style="color: cyan;"> </span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>i)</span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> <span> </span><span> </span></span></span></span><span><span></span><span style="color: cyan;">(</span><span style="color: #6aa84f;">return-from</span> <span style="color: cyan;">try-loop t))))</span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: courier;"><span><span style="color: cyan;"><span></span><span></span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span>(</span>format <span style="color: orange;">*terminal-io*</span></span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="font-family: courier;"><span style="color: orange;"><span> </span><span> </span><span> </span><span> </span><span> </span><span> </span><span> <span> </span><span> </span></span></span><span style="color: #a64d79;">"I'm sorry you loose!~%"</span></span><span style="color: cyan;"><span style="font-family: courier;">))))</span> </span></span></div><div class="code" style="text-align: left;"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;"> <br /></span></span></div>
and:
<br />
<pre class="code"><span style="font-family: "Courier New",Courier,monospace;"><span style="color: cyan;">(</span><span style="color: #6aa84f;">defun</span> <span style="color: blue;">play-repeatedly</span> <span style="color: cyan;">()</span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: magenta;">"Play the guessing game repeatedly until user type exit."</span> </span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span><span style="color: #6aa84f;">let</span> <span style="color: cyan;">((number-of-attempts</span> nil<span style="color: cyan;">))</span> </span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span><span style="color: #6aa84f;">loop</span> named <span style="color: cyan;">guess-game-loop</span> do</span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>format <span style="color: orange;">*terminal-io*</span> <span style="color: #a64d79;">"How many attempts would you like to try? (type 'exit' to exit): "</span><span style="color: cyan;">)</span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>finish-output <span style="color: cyan;"><span style="color: orange;">*query-io*</span>)</span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>setq <span style="color: cyan;">number-of-attempts</span> <span style="color: cyan;">(</span>read <span style="color: cyan;">*query-io*)) </span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>cond</span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">((</span>and <span style="color: cyan;">(</span>symbolp <span style="color: cyan;">number-of-attempts)</span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>string-equal 'exit <span style="color: cyan;">number-of-attempts))</span> </span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>return-from <span style="color: cyan;">guess-game-loop))</span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">((</span>typep <span style="color: cyan;">number-of-attempts</span> 'integer<span style="color: cyan;">)</span> </span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>if <span style="color: cyan;">(</span>< <span style="color: cyan;">number-of-attempts</span> 1<span style="color: cyan;">)</span></span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>format <span style="color: orange;">*standard-output*</span> <span style="color: #a64d79;">"Only positive number or zero to exit!~%"</span>)</span>
<span style="font-family: "Courier New",Courier,monospace;"> <span style="color: cyan;">(</span>guess-an-integer <span style="color: cyan;">number-of-attempts)))))))</span></span></pre>
Now the important thing to understand is that in Common Lisp programs are made of functions: we defined three of them for our guessing game, GENERATE-INTEGER, GUESS-AN-INTEGER and PLAY-REPEATEDLY. The latter must be evaluated to actually play the game.<br />
<br />
<h4>
Using variables.</h4>
In the code above we used variable to hold particular values useful in the program for particular computations. However there is no need to declare the type of object that a variable will hold. The object/value carries information to perform type check during runtime. Assigning a variable a new value changes what
object the variable refers to but has no effect on the previously
referenced object/values. If a variable refers to a
mutable object, that reference could be used to modify the object itself, then this modification will be visible to any code that has a reference to
the same mutable object. Practically a variable name refers to a place in memory that actually holds the value/object, when the reference between the two is created it is called a "binding", through it it's possible to operate on a mutable object or value. In our case multiple bindings are created during runtime, for example in the call of GENERATE-INTEGER where parameters a and b are binded to 1 and 6 respectively. In the let special form in PLAY-REPEATEDLY function, the symbol number-of-attempts is binded to nil.<br />
<br />
<h4>
The (read) special form.</h4>
The program will ask the player how many attempts he has left to guess the secret number. Having generated this value, the next step is to instruct the computer to accept the player guess. To enter the number of attempts and the attempt itself we used the special form (<a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_rd.htm" target="_blank">read</a>). For now you could think at read as a command to make the computer waits until some data is provided by external means, in this case the keyboard. The value entered is then placed in the memory referred by the symbol guess, due to the let form in GUESS-AN-INTEGER. The reader must understand that there are a lot of way to enter a number from outside a program just using the read special form, but enter data from the keyboard is the fastest and most natural way to interact with the user, which is now a player, that runs the program. Generally speaking the read form could take data from streams and perform several interesting operations on them as a plus. For now just play and have fun:<br />
<br />
<span face="Verdana,sans-serif">(play-repeatedly)</span><br />
<span face="Verdana,sans-serif"><span style="color: cyan;"> </span></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg94MKl-SW-Pty422rCzgpd1VoRKm2CWn4YrVA6_1exblbTkJK11oNwVBdEMG8d-TYj5wffedEMb1MUUj60SDLhDSwOaM65LrFcoDZZN4joNdgdWTnaXTjMBsCrY_ZwQAK0QWdfojeiSlGG/s1600/DSC06345-b.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg94MKl-SW-Pty422rCzgpd1VoRKm2CWn4YrVA6_1exblbTkJK11oNwVBdEMG8d-TYj5wffedEMb1MUUj60SDLhDSwOaM65LrFcoDZZN4joNdgdWTnaXTjMBsCrY_ZwQAK0QWdfojeiSlGG/s1600/DSC06345-b.jpg" width="320" /></a></div>
</div>
<span class="ansi0 bgAnsi15"></span>The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0Rome, Italy41.9027835 12.49636550000002441.524646 11.850918500000024 42.280921 13.141812500000025tag:blogger.com,1999:blog-1926073711808653515.post-91818296006930920672013-11-15T23:27:00.000+01:002013-11-16T00:04:36.970+01:00<h2>
Let's dance!</h2>
<h2>
S-B-C-L!</h2>
Young geek, there's no need to feel down.<br />
I said, young geek, pick yourself off the ground.<br />
I said, young geek, 'cause you're in a new old language<br />
There's no need to be unhappy.<br />
<br />
Young geek, there's a language you can use.<br />
I said, young geek, when you're short on your code.<br />
You can use that, and I'm sure you will find<br />
Many ways to have a good time.<br />
<br />
It's fun to program with the s-b-c-l.<br />
It's fun to program with the s-b-c-l.<br />
<br />
It has everything for you geek to code,<br />
You can hang out with the emacs mode ...<br />
<br />
It's fun to program with the s-b-c-l.<br />
It's fun to program with the s-b-c-l.<br />
<br />
You can get working code, you can have a program,<br />
You can do whatever you feel ...<br />
<br />
Young geek, are you listening to me?<br />
I said, young geek, what do you want to be?<br />
I said, young geek, you can make real your dreams.<br />
But you got to know this one thing!<br />
<br />
No geek does it all by himself.<br />
I said, young geek, put your pride on the shelf,<br />
And just program, with the s.b.c.l.<br />
I'm sure it can help you today.<br />
<br />
It's fun to program with the s-b-c-l.<br />
It's fun to program with the s-b-c-l.<br />
<br />
It has everything for you geek to enjoy,<br />
You can hang out with emacs mode ...<br />
<br />
It's fun to program with the s-b-c-l.<br />
It's fun to program with the s-b-c-l.<br />
<br />
You can get woking code, you can have a program,<br />
You can do whatever you feel ...<br />
<br />
Young geek, I was once in your shoes.<br />
I said, I was down and out with the bugs.<br />
I felt no geek cared if I were alive.<br />
I felt the whole hard disk was so tight ...<br />
<br />
That's when someone came up to me,<br />
And said, young geek, take a walk up the GNU.<br />
There's a program there called the s.b.c.l.<br />
It can start you back on your way.<br />
<br />
It's fun to program with the s-b-c-l.<br />
It's fun to program with the s-b-c-l.<br />
<br />
It has everything for you geek to enjoy,<br />
You can hang out with emacs mode ...<br />
<br />
S-b-c-l ... you'll find it in the s-b-c-l.<br />
<br />
Young geek, young geek, there's no need to feel down.<br />
Young geek, young geek, get yourself off the bugs.<br />
<br />
S-b-c-l ... you'll find it in the s-b-c-l.<br />
<br />
Young geek, young geek, there's no need to feel down.<br />
Young geek, young geek, get yourself off the bugs.<br />
<br />
S-b-c-l ... just use the s-b-c-l.<br />
<br />
Young geek, young geek, are you listening to me?<br />
Young geek, young geek, what do you wanna be?<br />
<br />
<h2>
Fernando </h2>
Can you hear the beeps Fernando?<br />
I remember long ago another language not like this<br />
In the slime session Fernando<br />
You were humming to yourself and softly strumming your keyboard<br />
I could hear the distant console beep coming from above<br />
<br />
They were closer now Fernando<br />
Every keystroke seemed to last eternity<br />
I was so afraid Fernando<br />
We were young and full of bugs and none of us prepared to code<br />
And I'm not ashamed to say<br />
The bad c/c++ code almost made me cry<br />
<br />
There was repl in emacs that night<br />
The parens were green, Fernando<br />
They were blinking there for you and me<br />
For programming, Fernando<br />
Though I never thought we could code<br />
There's no brace left<br />
If I hade to do the same again<br />
I would, my geek, Fernando<br />
If I hade to do the same again<br />
I would, my geek, Fernando<br />
<br />
Now we're old and geek Fernando<br />
And since many programs I have done for live<br />
Can you hear the beeps Fernando?<br />
Do you still recall what the Meta dot means?<br />
I can see it in your eyes<br />
How proud you were to write macros<br />
<br />
That was something in the air that night<br />
The parens were higlights, Fernando<br />
They were blinking over here and over there<br />
For programming, Fernando<br />
<br />The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-73565825645739310032012-09-11T16:58:00.001+02:002012-11-14T23:32:52.069+01:00Radio kills the video star.<h2>
<b>A little project involving USB.</b></h2>
<h3>
<b>a simple Common Lisp program to send data from PC to an homemade board based on pic18lf2455 via USB hid interface.The friend Pascal. J. Bourguignon provided the with-open-usb macro.</b></h3>
<h3>
<b></b></h3>
This simple project starts from the need to provide a way to send and receive data over a custom board based on pic18lf2455. The application uses the microchip USB stack firmware for pic18 microcontrollers series and could take a bunch of commands to perform different operations such like: read digital signals timing and configure a digital radio chip (CC110L from TI). The main Lisp application has got three files:<br />
<br />
<ul>
<li>usb.asd;</li>
<li>usb.lisp;</li>
<li>package.lisp;</li>
<li>README.txt</li>
</ul>
<br />
For this project I used Quicklisp 2012081400, Quickproject, SBCL 1.0.57, Emacs 23 and Slime from Wheezy distro. The Lisp program could:<br />
<br />
<ul>
<li>Lit/unlit 3 different LEDs on board;</li>
<li>Capture digital RF signals timings from main antenna;</li>
<li>Control digital radio CC110L micro from TI;</li>
<li>handle USB communication;</li>
<li>read a two keys pad. </li>
</ul>
<br />
Here a tipical session on the SBCL REPL.<br />
<br />
<br />
<!-- Created by htmlize-1.36 in css mode. -->
<html>
<head>
<title>*slime-repl sbcl*</title>
<style type="text/css">
<!--
body {
color: #221f1e;
background-color: #ffffff;
}
.slime-repl-input {
/* slime-repl-input-face */
font-weight: bold;
}
.slime-repl-inputed-output {
/* slime-repl-inputed-output-face */
color: #ff0000;
}
.slime-repl-output {
/* slime-repl-output-face */
color: #8b2252;
}
.slime-repl-prompt {
/* slime-repl-prompt-face */
color: #a020f0;
}
.slime-repl-result {
}
a {
color: inherit;
background-color: inherit;
font: inherit;
text-decoration: inherit;
}
a:hover {
text-decoration: underline;
}
</style></head></html>
<br />
<pre>; SLIME 2012-05-25
<span class="slime-repl-prompt">CL-USER> </span><span class="slime-repl-input">(ql:quickload "usb")</span>
<span class="slime-repl-output">To load "usb":
Load 1 ASDF system:
usb
; Loading "usb"
............
</span><span class="slime-repl-result"><span class="slime-repl-inputed-output">("usb")</span></span><span class="slime-repl-result">
</span><span class="slime-repl-prompt">CL-USER> </span><span class="slime-repl-input">(usb::send-command usb::*ccp1-on-command* :listen 4 :debug t)</span>
<span class="slime-repl-output">Found device Vendor ID: 0x04D8, Product ID: 0x003C
Device opened.
Configuration 1 set.
Interface 0 claimed.
AltInterface 0 set.
Sending:
0x77 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Receiving:
0x77 0x3C 0x00 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0x77 0x3C 0x01 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0x77 0x3C 0x02 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0x77 0x3C 0x03 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
</span><span class="slime-repl-result"><span class="slime-repl-inputed-output">(#8m( 119 60 0 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#8m( 119 60 1 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#8m( 119 60 2 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#8m( 119 60 3 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255))</span></span><span class="slime-repl-result">
</span><span class="slime-repl-prompt">CL-USER> </span></pre>
-->
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
in this session the CCP1 is activated via a specific command, the program then fetches three timings packets (64 bytes each) over the USB, the first packet is the response to the command. In this case there are all timeouts (data = 0xffff). In this other session the program do the same with a 30 MHz RF signal captured from the antenna.<br />
<br />
<br />
<!-- Created by htmlize-1.36 in css mode. -->
<html>
<head>
<title>*slime-repl sbcl*</title>
<style type="text/css">
<!--
body {
color: #221f1e;
background-color: #ffffff;
}
.slime-repl-input {
/* slime-repl-input-face */
font-weight: bold;
}
.slime-repl-inputed-output {
/* slime-repl-inputed-output-face */
color: #ff0000;
}
.slime-repl-output {
/* slime-repl-output-face */
color: #8b2252;
}
.slime-repl-prompt {
/* slime-repl-prompt-face */
color: #a020f0;
}
.slime-repl-result {
}
a {
color: inherit;
background-color: inherit;
font: inherit;
text-decoration: inherit;
}
a:hover {
text-decoration: underline;
}
</style></head></html>
<br />
<pre><span class="slime-repl-prompt">CL-USER> </span><span class="slime-repl-input">(usb::send-command usb::*ccp1-on-command* :listen 4 :debug t)</span>
<span class="slime-repl-output">Found device Vendor ID: 0x04D8, Product ID: 0x003C
Device opened.
Configuration 1 set.
Interface 0 claimed.
AltInterface 0 set.
Sending:
0x77 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Receiving:
0x77 0x02 0x01 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
0x77 0x3C 0x00 0x00 0x82 0x03 0x03 0x00 0x07 0x00 0x28 0x00 0x48 0x00 0x3E 0x00
0x34 0x00 0x2B 0x00 0x28 0x00 0xC0 0x01 0x04 0x00 0x0C 0x00 0x39 0x00 0x3C 0x00
0x36 0x00 0x2E 0x00 0x27 0x00 0x26 0x00 0x22 0x00 0x22 0x00 0x20 0x00 0x1F 0x00
0x1D 0x00 0x1D 0x00 0x1D 0x00 0x1D 0x00 0x81 0x03 0x02 0x00 0x05 0x00 0x21 0x00
0x77 0x3C 0x01 0x00 0x4D 0x00 0x3A 0x00 0x31 0x00 0xD6 0x01 0x02 0x00 0x06 0x00
0x1E 0x00 0x8E 0x00 0x43 0x00 0x2C 0x00 0x26 0x00 0x26 0x00 0x24 0x00 0x1F 0x00
0x20 0x00 0x1E 0x00 0x1D 0x00 0x1D 0x00 0x1D 0x00 0x1D 0x00 0x72 0x03 0x04 0x00
0x0A 0x00 0x43 0x00 0x4C 0x00 0x39 0x00 0x2F 0x00 0x2A 0x00 0xCF 0x01 0x02 0x00
0x77 0x3C 0x02 0x00 0x10 0x00 0x20 0x00 0x2D 0x00 0x33 0x00 0x3E 0x00 0x4B 0x00
0xBA 0x03 0x03 0x00 0x0A 0x00 0x23 0x00 0x39 0x00 0x4B 0x00 0x62 0x00 0x11 0x02
0x02 0x00 0x06 0x00 0x1B 0x00 0x47 0x00 0x61 0x00 0x52 0x00 0x3C 0x00 0x33 0x00
0x15 0x00 0x26 0x00 0x24 0x00 0x22 0x00 0x1F 0x00 0x1E 0x00 0x85 0x03 0x02 0x00
</span><span class="slime-repl-result"><span class="slime-repl-inputed-output">(#8m( 119 2 1 0 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#8m( 119 60 0 0 130 3 3 0 7 0 40 0 72 0 62 0 52 0 43 0 40 0 192 1 4 0 12 0 57 0 60 0 54 0 46 0 39 0 38 0 34 0 34 0 32 0 31 0 29 0 29 0 29 0 29 0 129 3 2 0 5 0 33 0)
#8m( 119 60 1 0 77 0 58 0 49 0 214 1 2 0 6 0 30 0 142 0 67 0 44 0 38 0 38 0 36 0 31 0 32 0 30 0 29 0 29 0 29 0 29 0 114 3 4 0 10 0 67 0 76 0 57 0 47 0 42 0 207 1 2 0)
#8m( 119 60 2 0 16 0 32 0 45 0 51 0 62 0 75 0 186 3 3 0 10 0 35 0 57 0 75 0 98 0 17 2 2 0 6 0 27 0 71 0 97 0 82 0 60 0 51 0 21 0 38 0 36 0 34 0 31 0 30 0 133 3 2 0))</span></span><span class="slime-repl-result">
</span><span class="slime-repl-prompt">CL-USER> </span><span class="slime-repl-input">(usb::send-command usb::*ccp1-off-command* :listen 1 :debug t)</span>
<span class="slime-repl-output">Found device Vendor ID: 0x04D8, Product ID: 0x003C
Device opened.
Configuration 1 set.
Interface 0 claimed.
AltInterface 0 set.
Sending:
0x77 0x02 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Receiving:
0x77 0x02 0x01 0x00 0x1A 0x00 0x4A 0x00 0x73 0x00 0xB7 0x00 0x74 0x03 0x09 0x00
0x39 0x00 0x9B 0x00 0x70 0x02 0x02 0x00 0x08 0x00 0x60 0x00 0xCC 0x00 0x6D 0x00
0x4A 0x00 0x35 0x00 0x2F 0x00 0x2A 0x00 0x24 0x00 0x8A 0x03 0x02 0x00 0x04 0x00
0x18 0x00 0x6F 0x00 0x59 0x00 0x42 0x00 0xEF 0x01 0x04 0x00 0x05 0x00 0x0D 0x00
</span><span class="slime-repl-result"><span class="slime-repl-inputed-output">(#8m( 119 2 1 0 26 0 74 0 115 0 183 0 116 3 9 0 57 0 155 0 112 2 2 0 8 0 96 0 204 0 109 0 74 0 53 0 47 0 42 0 36 0 138 3 2 0 4 0 24 0 111 0 89 0 66 0 239 1 4 0 5 0 13 0))</span></span><span class="slime-repl-result">
</span><span class="slime-repl-prompt">CL-USER> </span></pre>
-->
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
Program could redirect output into a file and perform never ending sampling.<br />
<br />
<a href="http://blogname.blogspot.com/feeds/posts/default?alt=rss">The RSS Feed</a><br />
<br />
<ul>
</ul>
The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-14342964198509690332011-12-13T23:24:00.000+01:002011-12-13T23:24:48.542+01:00Playing with a TS7200.<a href="http://www.embeddedarm.com/products/board-detail.php?product=TS-7200">Technologic Systems</a> TS-7200 is a PC104 form factor SBC board based on <a href="http://www.cirrus.com/en/products/ep9302.html">Cirrus Logic EP9302</a>. This is an ARM 9 microcontroller based on ARM920T core plus a bunch of less and more useful peripherals. This piece of hardware would be very funny to use and experiment on if you're gonna install a linux distro on it. First of all, as you can see on the previous sites I wrote, the system come with<br />
<br />
<li>200MHz ARM9 CPU </li><br />
<li>PC/104 expansion bus </li><br />
<li>32MB SDRAM</li><br />
<li>8MB NOR Flash</li><br />
<li>1 10/100 Ethernet </li><br />
<li>2 USB 2.0 (12 Mbit/s max) </li><br />
<li>1 Compact Flash socket </li><br />
<li>2 COM ports </li><br />
<li>20 DIO lines </li><br />
<li>2 12-bit ADC </li><br />
<li>Watchdog timer, SPI bus </li><br />
<li>Matrix Keypad and text LCD support </li><br />
<li>Redboot bootloader (installed)</li><br />
<li>TS-linux busybox (installed)</li><br />
<br />
<br />
now you can forget the TS-linux stuff on it and install your own linux distro and boot it from a CF. My system has got a 4 GB Sandisk CF (30 MB/s) with Debian Lenny on it.The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-65069037905149785062011-11-09T22:17:00.000+01:002011-11-09T22:17:13.911+01:00<div style="text-align: center;"><span style="font-weight: bold;">Qt 4.6 tutorial in Lisp</span></div><div style="text-align: center;"><br />
</div><div style="text-align: justify;"><span style="font-weight: bold;"></span>;;<br />
;; first qt tutorial<br />
;;<br />
<br />
(defpackage :qt-tutorial1<br />
(:use :cl :qt)<br />
(:export :main))<br />
<br />
(in-package :qt-tutorial1)<br />
(named-readtables:in-readtable :qt)<br />
<br />
(defvar *qapp*)<br />
<br />
(defun main ()<br />
(let ((hello-button (#_new QPushButton "Hello world!")))<br />
(#_resize hello-button 100 30)<br />
(#_show hello-button)))</div>The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-55391569454428243962011-08-07T12:30:00.000+02:002011-08-07T12:30:35.020+02:00A new simulation: Maxim MAX770-MAX773 Figure 2a step up converter, here a simulation results<br />
<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmRQjZd4Zc1eIVyobooQRPH85PWSDSQTrXGTT86Ec050fNC_EhrJmLPNjCegA4HS0FkNip_QNCQ8Kll6-7-KB-V58kRsqwd3D90FROSkvpVGQFOmmYMWA_2xlxnpvYoO9ei-M3i1MgNQM/s1600/test_stepup_01_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUmRQjZd4Zc1eIVyobooQRPH85PWSDSQTrXGTT86Ec050fNC_EhrJmLPNjCegA4HS0FkNip_QNCQ8Kll6-7-KB-V58kRsqwd3D90FROSkvpVGQFOmmYMWA_2xlxnpvYoO9ei-M3i1MgNQM/s320/test_stepup_01_1.png" width="320" /></a></div>The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-22012311277191821122011-07-30T11:04:00.004+02:002011-07-30T12:44:30.284+02:00Running slime from emacs<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxhyWyS4-KsCZJW8FEnyEZLQBJs9vKJARKzLMB8c-uSTVcOjEm2kdANp0g85bP5Eox7bBPob2tzN9xJ0aiW2TNWO3Y1M2Y1ohEbfcA6fYZ2We6ezhHFX4LtHF3UehVfzLFT5yRKwKqpO9p/s1600/gvesta_01.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="282" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxhyWyS4-KsCZJW8FEnyEZLQBJs9vKJARKzLMB8c-uSTVcOjEm2kdANp0g85bP5Eox7bBPob2tzN9xJ0aiW2TNWO3Y1M2Y1ohEbfcA6fYZ2We6ezhHFX4LtHF3UehVfzLFT5yRKwKqpO9p/s320/gvesta_01.jpeg" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFlnwIPANa1pU4rIh4kXRsPe5WVBnr2Mv9lnF9ySLLuusnd1dZsKDA381kYozOIqIdEuc6_UnvaeM7IzSPM4hUv0Wodk3ElUHwK0K0rBBAChOoLE9PnnQkcBmShms44811TrRwTITRjEL_/s1600/gvesta_03a.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="248" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFlnwIPANa1pU4rIh4kXRsPe5WVBnr2Mv9lnF9ySLLuusnd1dZsKDA381kYozOIqIdEuc6_UnvaeM7IzSPM4hUv0Wodk3ElUHwK0K0rBBAChOoLE9PnnQkcBmShms44811TrRwTITRjEL_/s320/gvesta_03a.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia6zyZq9STvFVmAB0EKGEYvObpHXnjMzwC01F0QBYC0mMpMBre7oGCuKY1Ickbn4s3MX-Upr2utjo_QTFj_-qFpyvELVN2r04AW8-JBK_Rjj_NeJ-jMf3H3EdDRYCx0nGPIipi10CxAjGX/s1600/gvesta_04a.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="278" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia6zyZq9STvFVmAB0EKGEYvObpHXnjMzwC01F0QBYC0mMpMBre7oGCuKY1Ickbn4s3MX-Upr2utjo_QTFj_-qFpyvELVN2r04AW8-JBK_Rjj_NeJ-jMf3H3EdDRYCx0nGPIipi10CxAjGX/s320/gvesta_04a.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2rR-v-ZY5JTaQ2O6-2ZNCtbEyqDz35z5SmRJObikkN08_lVZpb_qYtoJQ6jyP76G2EENVd5NxNjjWuUE3LtUK_Ho1Pyv-4dFZU6iWhjXz_UJ4OzGtiP6VqJ_qXk2osK057tdHC6DBGCgk/s1600/gvesta_02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="298" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2rR-v-ZY5JTaQ2O6-2ZNCtbEyqDz35z5SmRJObikkN08_lVZpb_qYtoJQ6jyP76G2EENVd5NxNjjWuUE3LtUK_Ho1Pyv-4dFZU6iWhjXz_UJ4OzGtiP6VqJ_qXk2osK057tdHC6DBGCgk/s320/gvesta_02.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAL_hA5joPLzLRSGgUTytrAoJNx33Sn25_66kVZ6Xc7wxcRef6fysCsc_3M1PMeKVe0106pXtXN82x_ju_BgXzuTuIXVUbIaQzuIzvFhsXH2c-NGDxcGLcOuCAdmZ1SphW1zyYADipvTLG/s1600/gvesta_02a.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br />
</a></div>The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-38831077548333623552011-06-23T10:59:00.000+02:002011-06-23T10:59:12.725+02:00Finally a simulation!<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS8_gdKrHKsUhX2XJY0hOMW3GkoQd4H4kigFQjk7Q5TLqyvnuLJ7vCl3H5cy4p_E4oHVzj2DnmJ0fqxw9d564hpVXK9qZrOyNN5W_0IZF0vus4Vwgyqy0pY3PGePXepBbtHUJUm7Q4MYll/s1600/test_t3b3_05_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS8_gdKrHKsUhX2XJY0hOMW3GkoQd4H4kigFQjk7Q5TLqyvnuLJ7vCl3H5cy4p_E4oHVzj2DnmJ0fqxw9d564hpVXK9qZrOyNN5W_0IZF0vus4Vwgyqy0pY3PGePXepBbtHUJUm7Q4MYll/s320/test_t3b3_05_1.png" width="320" /></a></div>This is a simulation about a three-phase transformer feeding an AC/DC converter.The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-74110239550838440492011-05-05T19:52:00.001+02:002011-05-05T19:53:11.025+02:00After all they are only circuits<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrLMy6t7i8BDkHN0ldUU6Ugn3R8XPJ0ojeBdg9N2TLtk_lkXwqXh8vgsDeJt6RK3NB0I3QAS7ahcu2VW17tQn5VLA95Y6cqRYzixpwaxE27jw6aXswY8ajUq80lj8XSQvEOJoI9NZ4DaeH/s1600/lisplogo_flag2_256.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrLMy6t7i8BDkHN0ldUU6Ugn3R8XPJ0ojeBdg9N2TLtk_lkXwqXh8vgsDeJt6RK3NB0I3QAS7ahcu2VW17tQn5VLA95Y6cqRYzixpwaxE27jw6aXswY8ajUq80lj8XSQvEOJoI9NZ4DaeH/s1600/lisplogo_flag2_256.png" /></a></div>On <a href="http://code.google.com/p/circuit">circuit-simulator</a> an almost complete software to deal with electrical circuits e.g.: diode, switches, generators and so on at the cheap price of nothing. Docs for this program are still in development as the google code wiki page.The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-55039498926833032412011-01-25T21:03:00.002+01:002011-01-27T19:37:41.879+01:00Here it is the starting project;; G26 communication protocol<br />
<br />
(<b>defpackage</b> :g26<br />
(:<i>use</i> :<i>common-lisp</i>))<br />
<br />
(<b>in-package</b> :g26)<br />
<br />
(<b>defclass</b> g26-message ()<br />
((logical-channel :<i>initarg</i> :logical-channel<i>)</i><br />
(command-code :<i>initarg</i> :command-code)<br />
(data-length :<i>initarg</i> :data-length)<br />
(data :<i>initarg</i> :data)<br />
(crc-code :<i>initarg</i> :crc-code)))<br />
<br />
(<b>defparameter</b> *crc-table*<br />
(<b>make-array</b> 256 <br />
:<i>element-type</i> '<i>unsigned-word</i> <br />
:<i>initial-contents</i><br />
'(#x0000 #x1021 #x2042 #x3063 #x4084 #x50A5 #x60C6 #x70E7<br />
#x8108 #x9129 #xA14A #xB16B #xC18C #xD1AD #xE1CE #xF1EF<br />
#x1231 #x0210 #x3273 #x2252 #x52B5 #x4294 #x72F7 #x62D6<br />
#x9339 #x8318 #xB37B #xA35A #xD3BD #xC39C #xF3FF #xE3DE <br />
#x2462 #x3443 #x0420 #x1401 #x64E6 #x74C7 #x44A4 #x5485<br />
#xA56A #xB54B #x8528 #x9509 #xE5EE #xF5CF #xC5AC #xD58D<br />
#x3653 #x2672 #x1611 #x0630 #x76D7 #x66F6 #x5695 #x46B4<br />
#xB75B #xA77A #x9719 #x8738 #xF7DF #xE7FE #xD79D #xC7BC<br />
#x48C4 #x58E5 #x6886 #x78A7 #x0840 #x1861 #x2802 #x3823<br />
#xC9CC #xD9ED #xE98E #xF9AF #x8948 #x9969 #xA90A #xB92B <br />
#x5AF5 #x4AD4 #x7AB7 #x6A96 #x1A71 #x0A50 #x3A33 #x2A12 <br />
#xDBFD #xCBDC #xFBBF #xEB9E #x9B79 #x8B58 #xBB3B #xAB1A <br />
#x6CA6 #x7C87 #x4CE4 #x5CC5 #x2C22 #x3C03 #x0C60 #x1C41 <br />
#xEDAE #xFD8F #xCDEC #xDDCD #xAD2A #xBD0B #x8D68 #x9D49 <br />
#x7E97 #x6EB6 #x5ED5 #x4EF4 #x3E13 #x2E32 #x1E51 #x0E70 <br />
#xFF9F #xEFBE #xDFDD #xCFFC #xBF1B #xAF3A #x9F59 #x8F78 <br />
#x9188 #x81A9 #xB1CA #xA1EB #xD10C #xC12D #xF14E #xE16F <br />
#x1080 #x00A1 #x30C2 #x20E3 #x5004 #x4025 #x7046 #x6067 <br />
#x83B9 #x9398 #xA3FB #xB3DA #xC33D #xD31C #xE37F #xF35E <br />
#x02B1 #x1290 #x22F3 #x32D2 #x4235 #x5214 #x6277 #x7256 <br />
#xB5EA #xA5CB #x95A8 #x8589 #xF56E #xE54F #xD52C #xC50D <br />
#x34E2 #x24C3 #x14A0 #x0481 #x7466 #x6447 #x5424 #x4405 <br />
#xA7DB #xB7FA #x8799 #x97B8 #xE75F #xF77E #xC71D #xD73C <br />
#x26D3 #x36F2 #x0691 #x16B0 #x6657 #x7676 #x4615 #x5634 <br />
#xD94C #xC96D #xF90E #xE92F #x99C8 #x89E9 #xB98A #xA9AB <br />
#x5844 #x4865 #x7806 #x6827 #x18C0 #x08E1 #x3882 #x28A3 <br />
#xCB7D #xDB5C #xEB3F #xFB1E #x8BF9 #x9BD8 #xABBB #xBB9A <br />
#x4A75 #x5A54 #x6A37 #x7A16 #x0AF1 #x1AD0 #x2AB3 #x3A92 <br />
#xFD2E #xED0F #xDD6C #xCD4D #xBDAA #xAD8B #x9DE8 #x8DC9 <br />
#x7C26 #x6C07 #x5C64 #x4C45 #x3CA2 #x2C83 #x1CE0 #x0CC1 <br />
#xEF1F #xFF3E #xCF5D #xDF7C #xAF9B #xBFBA #x8FD9 #x9FF8 <br />
#x6E17 #x7E36 #x4E55 #x5E74 #x2E93 #x3EB2 #x0ED1 #x1EF0)))<br />
<br />
(<b>defparameter</b> *qload*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x00<br />
:command-code #x01<br />
:data-length #x0b<br />
:data (make-array 11 :element-type 'unsigned-byte :initial-element 0)<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *status-general*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x10<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter </b>*status-motors*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x11<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *status-tray1*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x12<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *status-tray2*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x13<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *status-tray3*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x14<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter </b>*status-processes*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x15<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *status-peltier*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x16<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter </b>*status-photometer*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x17<br />
:data-length #x01<br />
:data (make-array 1 :element-type 'unsigned-byte :initial-element 0)<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *status-outputs*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x18<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *status-tray1*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x04<br />
:command-code #x12<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *version-message*<br />
(<b>make-instance</b> 'g26-message <br />
:logical-channel #x80 <br />
:command-code #x19<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *operator-go*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x10<br />
:command-code #x20<br />
:data-length #x00<br />
:data nil<br />
:crc-code #x0000))<br />
<br />
(<b>defparameter</b> *operator-kill*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x10<br />
:command-code #x21<br />
:data-length #x01<br />
:data (make-array 1 :element-type 'unsigned-byte :initial-element 0)<br />
:crc-code #xffff))<br />
<br />
(<b>defparameter</b> *ack-message*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x20<br />
:command-code #x80<br />
:data-length #x01<br />
:data (make-array 1 :element-type 'unsigned-byte :initial-element 0)<br />
:crc-code #xffff))<br />
<br />
(<b>defparameter</b> *nak-message*<br />
(<b>make-instance</b> 'g26-message<br />
:logical-channel #x20<br />
:command-code #x83<br />
:data-length #x01<br />
:data (make-array 1 :element-type 'unsigned-byte :initial-element 0)<br />
:crc-code #xffff))<br />
<br />
;; open a serial port-like device<br />
<br />
(<b>defun</b> open-serial-port (tty-name)<br />
(<b>unless</b> (<b>stringp</b> tty-name)<br />
(<b>error</b> "open-serial-port: wrong device name."))<br />
(<i>sb-posix</i><b>:open</b> tty-name (<b>logior</b> <i>sb-posix</i>:O-RDWR <i>sb-posix</i>:O-NOCTTY <i>sb-posix</i>:O-NONBLOCK <i>sb-posix</i>:O-NDELAY)))<br />
<br />
<br />
;; close a special file<br />
<br />
(<b>defun</b> close-serial-port (fd)<br />
(<b>when</b> (< fd 0) <br />
(<b>error </b>"close-serial-port: wrong file descriptor value."))<br />
(<i>sb-posix</i>:<b>fcntl</b> fd <i>sb-posix</i>:F-SETFL 0)<br />
(<i>sb-posix</i>:<b>close</b> fd))<br />
<br />
<br />
(<b>defun</b> get-serial-port-config (fd)<br />
(<b>when</b> (< fd 0)<br />
(<b>error</b> "get-serial-port-config: wrong file descriptor value."))<br />
(<i>sb-posix</i>:<b>tcgetattr</b> fd))<br />
<br />
<br />
(<b>defun</b> set-serial-port-config (fd config &key iflag oflag cflag lflag)<br />
(<b>when</b> (< fd 0)<br />
(<b>error </b>"set-serial-port-config: serial port not open."))<br />
(<b>cond</b><br />
((<b>not</b> (<b>eql</b> iflag <b>nil</b>)) (<b>setf </b>(<i>sb-posix</i>:<b>termios-iflag</b> config) iflag))<br />
((<b>not</b> (<b>eql</b> oflag <b>nil</b>)) (<b>setf</b> (<i>sb-posix</i>:<b>termios-oflag</b> config) oflag))<br />
((<b>not</b> (<b>eql</b> cflag <b>nil</b>)) (<b>setf</b> (<i>sb-posix</i>:<b>termios-cflag</b> config) cflag))<br />
((<b>not</b> (<b>eql</b> lflag <b>nil</b>)) (<b>setf</b> (<i>sb-posix</i>:<b>termios-lflag</b> config) lflag)))<br />
(<i>sb-posix</i>:<b>tcsetattr</b> fd <i>sb-posix</i>:TCIFLUSH config)<br />
config)<br />
<br />
;<br />
; g26 message to unsigned byte array<br />
;<br />
<br />
(defun message-to-array (message)<br />
(<b>unless</b> (<b>null</b> message)<br />
(<b>let</b> ((message-body (<b>make-array</b> (+ (<b>slot-value</b> message 'data-length) 5) :element-type '<i>unsigned-byte</i> :<i>initial-element</i> 0)))<br />
(<b>setf</b> (<b>aref</b> message-body 0) (<b>slot-value</b> message 'logical-channel))<br />
(<b>setf</b> (<b>aref </b>message-body 1) (<b>slot-value</b> message 'command-code))<br />
(<b>setf</b> (<b>aref</b> message-body 2) (<b>slot-value</b> message 'data-length))<br />
(<b>replace</b> message-body <b>(slot-value</b> message 'data) :<i>start1</i> 3)<br />
(<b>setf </b>(<b>aref</b> message-body (+ (<b>slot-value</b> message 'data-length) 3)) (<b>logand</b> (<b>slot-value</b> message 'crc-code) #xff))<br />
(<b>setf</b> (<b>aref</b> message-body (+ (<b>slot-value</b> message 'data-length) 4)) (<b>logand</b> (<b>ash</b> (<b>slot-value</b> message 'crc-code) -8) #xff))<br />
message-body)))<br />
<br />
;<br />
; unsigned byte array to g26 message<br />
;<br />
<br />
(<b>defun</b> array-to-message (message-body)<br />
(<b>unless</b> (<b>null</b> message-body)<br />
(<b>when</b> (<b>arrayp</b> message-body)<br />
(<b>when</b> (> (<b>length</b> message-body) 4)<br />
(<b>let</b> ((message (<b>make-instance</b> 'g26-message)))<br />
(<b>setf</b> (<b>slot-value</b> message 'logical-channel) (<b>aref </b>message-body 0))<br />
(<b>setf </b>(<b>slot-value</b> message 'command-code) (<b>aref</b> message-body 1))<br />
(<b>setf</b> (<b>slot-value</b> message 'data-length) (<b>aref</b> message-body 2))<br />
(<b>setf</b> (<b>slot-value</b> message 'data) (<b>make-array</b> (<b>aref</b> message-body 2) :<i>element-type</i> '<i>unsigned-byte</i>))<br />
(<b>replace</b> (<b>slot-value</b> message 'data) message-body :<i>start2</i> 3)<br />
(<b>setf</b> (<b>slot-value </b>message 'crc-code) (<b>logior</b> (<b>aref </b>message-body (+ (<b>aref </b>message-body 2) 3)) (<b>ash</b> (<b>aref</b> message-body (+ (<b>aref </b>message-body 2) 4)) 8)))<br />
message)))))<br />
<br />
;<br />
; receive g26 message<br />
;<br />
<br />
(<b>defun</b> get-message (fd)<br />
(<b>when</b> (<b>null</b> fd)<br />
(<b>error</b> "get-message: serial port not open."))<br />
(<b>let</b> ((message-body (<b>make-array</b> 261 :<i>element-type</i> '<i>unsigned-byte</i> :<i>initial-element</i> 0)))<br />
(<b>when</b> (= (<b>read-sequence</b> message-body fd) 3)<br />
(<b>when</b> (= (<b>read-sequence</b> message-body fd :<i>start</i> 3) (+ (<b>aref</b> message-body 2) 2))<br />
(crc16 (<b>subseq</b> message-body 0 (- (<b>length</b> message-body) 2)))<br />
(<b>let</b> ((message (array-to-message message-body)))<br />
message)))))<br />
<br />
;<br />
; send a message to g26<br />
;<br />
<br />
(<b>defun</b> send-message (fd message)<br />
(<b>when</b> (<b>null</b> fd)<br />
(<b>error</b> "send-message: serial port not open."))<br />
(<b>when</b> (<b>null</b> message)<br />
(<b>error</b> "send-message: wrong message.")) <br />
(<b>let</b> ((message-body (message-to-array message)))<br />
(<b>loop</b> <b>for</b> i <b>from</b> 0 <b>below</b> (<b>length</b> message-body) <b>do</b><br />
(<b>write-byte</b> (<b>aref</b> message-body i) fd))<br />
(<b>length</b> message-body)))<br />
<br />
;<br />
; start it all<br />
;<br />
<br />
(<b>defun</b> start-communication (serial-port-name)<br />
(<b>let </b>((serial-port-descriptor (open-serial-port serial-port-name)))<br />
(<b>when</b> (< serial-port-descriptor 0) <br />
(<b>error</b> "start-communication: serial port not open."))<br />
(<b>let</b> ((serial-port-config (get-serial-port-config serial-port-descriptor)))<br />
(<b>setf </b>(<i>sb-posix</i>:<b>termios-cflag</b> serial-port-config) (<b>logior</b> <i>sb-posix</i>:b115200 <i>sb-posix</i>:PARENB <i>sb-posix</i>:PARODD))<br />
(set-serial-port-config serial-port-descriptor serial-port-config)<br />
<br />
;<br />
; let's communicate with g26<br />
;<br />
<br />
(<b>let</b> ((serial-port-stream (<i>sb-sys</i>:<b>make-fd-stream</b> serial-port-descriptor :<i>element-type</i> '<i>unsigned-byte</i>)))<br />
<br />
(send-message serial-port-stream *status-general*)<br />
(close serial-port-stream)<br />
(close-serial-port serial-port-descriptor)))))<br />
<br />
;<br />
; crc16 calculation<br />
;<br />
<br />
(<b>defun</b> crc16 (buffer)<br />
(<b>unless</b> (<b>null</b> buffer)<br />
(<b>when</b> (<b>arrayp</b> buffer)<br />
(<b>let</b> ((crc-value 0))<br />
(<b>loop</b> <b>for</b> i <b>from</b> 0 <b>below </b>(<b>length</b> buffer) <b>do</b><br />
(<b>setf </b>crc-value (<b>logand</b> (<b>logxor</b> (<b>aref</b> *crc-table* (<b>logxor</b> (<b>ash</b> crc-value -8) (<b>aref</b> buffer i))) (<b>ash</b> crc-value 8)) #xffff)))<br />
crc-value))))<br />
<br />
<br />
Thanks to smart people on #lisp: Xach, stassat, H4ns and the others :)<br />
G26 it's a smart robot that performs biological/chemical manipulations on human fluids.The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-82293534655433306092011-01-17T18:02:00.002+01:002011-01-17T18:02:54.277+01:00Starting the project!!!In a few days I'll come back to work on Lisp to control the little robot. More details in the near future!The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-9442905444140023142011-01-09T17:37:00.003+01:002011-01-09T20:07:22.285+01:00The squire of GOTOs.<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"><b>SULU</b>: Captain, how far do we go along with this charade?</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"><b>KIRK</b>: Until we can think our way out. Meanwhile, we accept his hospitality. <br />
<b> MCCOY</b>: You should taste his food. Straw would taste better than his meat, and water a hundred times better than his brandy. Nothing has any taste at all. <br />
<b>SPOCK</b>: It may be unappetizing, Doctor, but it is very logical. <br />
<b> MCCOY</b>: There's that magic word again. Does your logic find this fascinating, Mister Spock? </span><br />
<br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"></span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"><a name='more'></a></span><br />
<br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;">let's use a class to specify robot to PC and PC to robot binary message:</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"> </span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;">(<b>defclass</b> g26-message ()</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"> ((logical-channel :<i>initarg</i> :logical-channel)</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"> (command-code :<i>initarg</i> :command-code)</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"> (data-length :<i>initarg</i> :data-length)</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"> (data :<i>initarg</i> :data)</span><br />
<span style="font-family: Arial,Helvetica,sans-serif; font-size: x-small;"> (crc-code :<i>initarg</i> :crc-code)))</span>The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-76495503187634816742011-01-03T20:16:00.001+01:002011-01-07T20:58:49.328+01:00A nasty piece of work robot!In which I'm trying to write a Lisp program to control an industrial robot...<br />
I warn you to read on: I'm a perfect noob in the complex lisp world or better Lisp (to say Common Lisp), the informations that I'll dare to write on this blog have to be carefully weighted. I'm waiting for you to write down your comments and hints on my humble (and I hope useful) work. Thank you!!!<br />
<br />
<a name='more'></a><br />
In the c language (and lesser in the c++) the interaction with OS could occur at very low level. In systems like Linux one could take advantages of this to have the full control of the hardware. In the following example I'll show you a simple robot connected via serial port to a stand-alone PC system. PC sends commands to robot that executes them and sends back some informations to PC. The communication protocol is based on binary packets assembled like this:<br />
<ol><li>copy the old device configuration;</li>
<li>modify the current device configuration;</li>
<li>write the new device configuration;</li>
<li>required device I/O;</li>
<li>write old device configuration;</li>
<li>close device. </li>
</ol><ol></ol>today I'd like to introduce my small functions to achieve 1, 2, 3, 4, 6 and 7:<br />
<br />
(<b>defun</b> open-serial-port (tty-name)<br />
(<b>if</b> (<b>stringp</b> tty-name)<br />
(<b>sb-posix:open</b> tty-name<br />
(<b>boole boole-ior</b> (<b>boole boole-ior</b> <i>sb-posix:O-RDWR sb-posix:O-NOCTTY</i>) <i>sb-posix:O-NONBLOCK</i>) <i>sb-posix:O-NDELAY</i>)<br />
(<b>error</b> "Wrong device name.")))<br />
<br />
(<b>defun</b> close-serial-port (fd)<br />
(<b>if</b> (>= fd 0)<br />
(<b>progn</b><br />
(<b>sb-posix:fcntl</b> fd <i>sb-posix:F-SETFL</i> 0)<br />
(<b>sb-posix:close</b> fd))<br />
(<b>error</b> "Wrong file descriptor value.")))<br />
<br />
(<b>defun</b> get-serial-port-config (fd)<br />
(<b>if</b> (>= fd 0)<br />
(<b>sb-posix:tcgetattr</b> fd)<br />
(<b>error</b> "Wrong file descriptor value.")))<br />
<br />
(<b>defun</b> set-serial-port-config (config &optional iflag oflag cflag lflag)<br />
(<b>if</b> (<b>not</b> (<b>eql</b> config nil))<br />
(<b>progn</b><br />
(<b>cond</b><br />
((<b>not</b> (<b>eql</b> iflag nil)) (<b>setf</b> (<b>sb-posix:termios-iflag</b> config) iflag))<br />
((<b>not</b> (<b>eql</b> oflag nil)) (<b>setf</b> (<b>sb-posix:termios-oflag</b> config) oflag))<br />
((<b>not</b> (<b>eql</b> cflag nil)) (<b>setf</b> (<b>sb-posix:termios-cflag</b> config) cflag))<br />
((<b>not</b> (<b>eql</b> lflag nil)) (<b>setf</b> (<b>sb-posix:termios-lflag</b> config) lflag)))<br />
config)<br />
(<b>error</b> "Wrong configuration.")))<br />
<br />
<br />
I'd like to thanks: <br />
<a href="http://ryepup.unwashedmeme.com/blog/2009/09/28/talking-usb-serial-to-my-arduino-from-lisp-sbcl-on-linux/">Ryan's Tech Blog</a><br />
<a href="http://www.sbcl.org/">SBCL Site</a><br />
<ol></ol>The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0tag:blogger.com,1999:blog-1926073711808653515.post-71146733929465425512011-01-02T23:21:00.003+01:002011-01-07T21:05:24.301+01:00Some books to know Lisp and...Here there's a list about books dealing with <b>Lisp</b>:<br />
<br />
<ul><li>Common Lisp the Language, 2nd Edition - G. L. Steele </li>
</ul><ul><li>Guida all'uso del linguaggio LISP - C. Queinnec</li>
</ul><ul><li>Practical Common Lisp - P. Seibel</li>
</ul><ul><li>Land of LISP - C. Barsky</li>
</ul><ul><li>The Algorithm Design Manual - S. Skiena</li>
</ul><ul><li>Intelligenza artificiale: un approccio moderno (volume 1 e 2) - S. Russel, P. Norvig</li>
</ul><br />
<a name='more'></a><br />
Here there's a list about books dealing with <b>electrical machinery</b> models and numerical analysis algorithms:<br />
<br />
<ul><li>Numerical Recipes in c - a.a.v.v.</li>
</ul><ul><li>Numerical Solution of Initial-Value Problems in Differential-Algebraic Equations - K. E. Brennan, S. L. Campbell, L. R. Petzold</li>
</ul><ul><li>Computer Methods for Ordinary Differential Equations and Differential-Algebraic Equations - U. Ascher, L. R. Petzold</li>
</ul><ul><li>Metodi dell'analisi numerica - G. Pesamosca</li>
</ul><ul><li>Algoritmi dell'algebra lineare: appunti dalle lezioni - L. Gori, G. Pesamosca</li>
</ul><ul><li>Elettrotecnica I e II - M. D'Amore</li>
</ul><ul><li>Analisys of Electric Machinery and Drive Systems - P. C. Krause, O. Wasynczuk, S. D. Sudhoff</li>
</ul><ul><li>Macchine Elettriche - A. E. Fitzgerald, C. Kingsley Jr., A. Kusko</li>
</ul>The Lisper Weaselhttp://www.blogger.com/profile/00111815135525017058noreply@blogger.com0