“Why Python Programmers Should Learn Python”
Referencing this Java article:
“Why Java Programmers Should Learn Python”
Posing this trivial programming problem:
The "Quicksilver Model Solution" presented to Java programmers was actually this (surprise!) Python code:Given the supplied library classes write some code in “quickSilver” to convert between word and decimal digits representations of positive integers less than 1001.
e.g. “five seven three” → 573
e.g. 672 → “six seven two”
Which resulted in a less than stellar review by the WPythonPSLP author on the WJavaPSLP authors "Model Solution" Python implementation...Code: Select all
class WordsFromNumber: def __init__(self,number): self.representationOf = number def wordsOf(self): lsd = self.representationOf % 10 msds = self.representationOf / 10 if msds == 0: return self.wordFor(self.representationOf) else: return WordsFromNumber(msds).wordsOf() + " " + \ self.wordFor(lsd) def wordFor(self,numeral): return ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"][numeral] class NumberFromWords: def __init__(self,words): self.representation = words def number(self): words = split("\\s",self.representation) return self.unpack(words) def unpack(self,words): if len(words) == 1: return self.numberFor(words[0]) else: lswi = len(words) - 1 lswi = words[lswi] msws = words[0:lswi] return self.numberFor(lsw) + 10 * self.unpack(msw) def numberFor(self,word): return {"zero" : 0, "one" : 1, "two" : 2, "three" : 3, "four" : 4, "five" : 5, "six" : 6, "seven" : 7, "eight" : 8, "nine" : 9}[word]
I have been amazed and awed to watch newLISP code questions being refactored on the newLISP Fan Club by it's clever members... (I SO miss lesser programmers being told to RTFM in those OTHER language groups ;) LOL
So this newLISP newbie thought it might be fun to see what you newLISP pros ;) can do to give the "newLiSP Model Solution" (or in Elica, etc.)...
-- xytroxon