if (a equals b) {
c = not d;
} else {
c = d + b;
}
You have this nested inner to outer logic where if is a function.
c = if(equals(a,b), not(d), plus(d,b))The first is definitely more readible [sic] and it reads like we think of the logic. No one thinks of if as a function that takes three arguments, and forcing you to work that way just makes you crazy. I suppose it is futile to argue with an admittedly crazy person, but perhaps being forced to work with conditionals has made me crazy as well. A closer translation of the original code would be this:
(if (equals a b)
(setq c (not d))
(setq c (+ d b)))
If these sorts of differences are a ``mind-bending puzzle'', perhaps the author should consider a career in the housekeeping or food-service industries.
Word cube is game in which players form words from the nine letters in a cube. Words must have four or more letters and must use the central letter from the cube; at least one word will use all nine letters in the cube. The player who forms the most words wins. Many newspapers publish a word cube on their puzzle page, and Stealthcopter publishes a word cube on line daily. Wikipedia describes word cubes under the caption “word polygon.” There are twelve words formed from the word cube at right: bonnie, bunion, coin, concubine, conic, cubic, ennui, icon, nice, nine, nuncio, and union.
Your task is to write a program that finds all matching words for a given word cube. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
The MSF beginner’s riders class that I took a month or so ago required shoes that covered the ankles and I ended up buying a pair of the Brahma Hutch II lace-less steel-toe boots from Walmart. Wearing now for a about a month I’ve been really impressed; they are comfortable, broke in really easily, and slip on and off pretty quickly. Perhaps the only downside for motorcycle-riding is that the steel-toe makes for awkward shifting and breaking. For that reason I’m looking at buying some real motorcycle boots pretty soon; in particular the TCX X-Five.
All in all for only $30USD this is a really nice boot.
After a good bit of research I decided to go with a Shoei RF1100. After a few hundred miles I’ve found it to be really nice; comfortable, a lot of air goes through it, and it doesn’t squeal when you are sitting behind a windshield like a couple of reviews that I had read suggested.
Perhaps the most bothersome discovery is the ridge on the top of my head that is going to force me to purchase some extra padding or something to level out the top of the helmet so it quits giving me a headache!
One “funny” thing I found in the owner’s manual was a warning that if you purchase the Matte Black helmet then you need to be extra, extra-careful about protecting its finish. Great!
We examined in a previous exercise a program that extracts a chronological listing of the exercises on the Programming Praxis website from the praxis.info file. We also discussed in a previous exercise a program that creates a permuted index. In today’s exercise we will combine those two programs into the program that is used to create the Permuted Table of Contents page at Programming Praxis.
The format of the praxis.info file was given in a previous exercise. The output from today’s program should look like this:
<table cellpadding="10">
<tr><td>129</td><td>20 Apr 2010</td><td align="right"> </td><td>145 Puzzle: Build and evaluate expressions using the digits one through nine and the simple arithmetic operators</td><td><a href="/2010/04/20/145-puzzle/">exercise</a> <a href="/2010/04/20/145-puzzle/2/">solution</a> <a href="http://programmingpraxis.codepad.org/SzbrJbjx">codepad</a></td></tr>
<tr><td>51</td><td>17 Jul 2009</td><td align="right">International Mathematical Olympiad: Three exercises from</td><td>1960s math competitions</td><td><a href="/2009/07/17/international-mathematical-olympiad/">exercise</a> <a href="/2009/07/17/international-mathematical-olympiad/2/">solution</a> <a href="http://programmingpraxis.codepad.org/JRGmt2wZ">codepad</a></td></tr>
...
</table>
Your task is to write a program that reads praxis.info and produces the permuted table of contents. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
(require (planet bzlib/shp:1:3)) (require "web.ss") will start the example site. The example site is still just trivial code right now - it will eventually be enhanced and separated into its own package. shp/api/add2, which contains the following:
;; -*- scheme -*- -p
(:api-args (a number?) (b number?))
(+ a b)a and b, and return the added result. To write an api script, you must use the :api-args expression, and then supply the arguments inside. The arguments can be specified in the following forms:
(:api-args a b) ;; both a & b are non-validating and you get what's passed in
(:api-args (a number?) (b string?)) ;; a expects a number, and b expects a string
(:api-args (a number? 3) (b number? 5)) ;; a & b both expect numbers, and both have default values if they are not passed in (a defaults to 3, and b defaults to 5).
GET /api/add2 HTTP/1.0
Content-Type: text/xml; charset=utf-8
<methodResponse>
<fault>
<value>
<string>required: a</string>
</value>
</fault>
</methodResponse>
a or b is passed in.
GET /api/add2?&a=50&b=90 HTTP/1.0
Content-Type: text/xml; charset=utf-8
<methodResponse>
<params>
<param>
<value>
<int>140</int>
</value>
</param>
</params>
</methodResponse>add2 script contains args of (a number?) and (b number?), which mean that both a & b expects a number input. So if we pass a non-number to the api
GET /api/add2?&a=not-a-number&b=also-not-a-number HTTP/1.0
<methodResponse>
<fault>
<value>
<string>invalid-conversion: "not-a-number"</string>
</value>
</fault>
</methodResponse>
POST /api/add2 HTTP/1.0
Content-Type: text/xml; charset=utf-8
<methodCall>
<methodName>add2</methodName>
<params>
<param><name>a</name><value><int>50</int></value></param>
<param><name>b</name><value><int>90</int></value></param>
</params>
</methodCall>
Content-Type: text/xml; charset=utf-8
<methodResponse>
<params>
<param>
<value>
<int>140</int>
</value>
</param>
</params>
</methodResponse>add2 is specified twice in the request - once in the path, and once in the methodName parameter in the payload. And if you were to use a bogus method name such such as add3 in the methodName parameter, you will see that it is being ignored - the path has precedence. methodName parameter will be ignored. add2 from the path, as follows:
POST /api HTTP/1.0 # notice - no add2 here
Content-Type: text/xml; charset=utf-8
<methodCall>
<methodName>add2</methodName>
<params>
<param><name>a</name><value><int>50</int></value></param>
<param><name>b</name><value><int>90</int></value></param>
</params>
</methodCall>/api/add2, just post to /api, and specify add2 in the methodName parameter. This is called partial path dispatch, for the lack of a better term for now. /api directory must not contain an index script, because otherwise the index script will be matched first prior to the partial dispatch kicking in. **. So for example, if we want to dispatch to /api/add2, we can dispatch as follows:
POST /api?**add2 HTTP/1.0 # note the **add2 key in the query string.
Content-Type: text/xml; charset=utf-8
<methodCall>
<methodName>add3</methodName><!-- note the wrong method name -->
<params>
<param><name>a</name><value><int>50</int></value></param>
<param><name>b</name><value><int>90</int></value></param>
</params>
</methodCall>** prefix will be stripped, and then appended to the path. And this rule, along with the direct dispatch, supersedes the method name in the xmlrpc payload. +, -, *, /, = submit buttons, you can theoretically have the following scripts:
/api/add
/api/subtract
/api/multiply
/api/divide
/api/equal **add, **subtract, **multiply, **divide, and **equal, and map the form's action to /api. SHP will do the dispatching for you correctly.
POST /api/add2 HTTP/1.0
Content-Type: text/json; charset=utf-8
{ a : 50 , b : 90 }
Content-Type: text/json; charset=utf-8
140 ~jsonp query string parameter as follows:
POST /api/add2?~jsonp=myCallback HTTP/1.0
Content-Type: text/json; charset=utf-8
{ a : 50 , b : 90 }
Content-Type: text/json; charset=utf-8
return myCallback( 140 ); Chris Aldrich reads a lot of good books. I enjoy hearing about what he has read lately and thought that it would be nice to share his thoughts so I offered that he could post here if he was interested (or until he blogged elsewhere or whatever). He said yes. His user-name is caldrich.