PAIP

Ex1.4 atomの出現回数

PAIPの解答そのまま。 PAIPの解答を見てcondのt節の後の式は改行しないで書く慣習であることに気づく。 ;;; exercise 1.4 [m] Write a function that counts the number of times an expression ;;; occurs anywarere whthin another expression. Example: (…

EX1.3 リスト中のatomの数を数える

car部のnilは空リストではなく、atom扱いで実装。 ;;; Exercise 1.3 [m] Write a function that counts the number of atoms in an expression. ;;; For example: (count-atoms '(a (b) c)) =>3. Notice that there is something of an ;;; ambiguity in thi…

Ex1.2 Powerを定義

PAIPのAnswerではexprを使っていたけど、powerの間違いかな。 ここは、O(n)の解答で。負の数にも対応したけど、小数を指定されると無限ループになる。 ;;; Exercise 1.2 [m] Write a function to exponentiate, or raise a number to an integer ;;; power. …

Ex1.1: Last Nameを返す

章の途中で定義したlast-nameを改造して、タイトル(っていうんか?)を取り扱えるようにする。 考えられるケースは取り扱えって言っても、どんな慣習があるんでしょう? 取りあえず例題のケースだけに対応。 ;;; Exercise 1.1 [m] Define a version of last…