Hannah and Je together

Wednesday, 28 July 2010

The Art of LISP Programming 03

Filed under: Lang:English,Subj:GNU/Computer — Jemyoung Leigh @ 17:48
Tags: , , ,

The Boolean functions nand, nor, implies and iff are defined as follows:

  • p nand q = not (p and q)
  • p nor q = not (p or q)
  • p implies q = (not p) or q
  • p iff q = (p implies q) and (q implies p)

Write LISP functions to mimic these.

** Here goes my version of logical operators:

(defun jnot (x)
      (x NIL)
      (T T)
(defun jand (x y)
      (x y)
      (T x)
(defun jor (x y)
      (x x)
      (T y)
(defun jxor (x y)
      (x (jnot y))
      (T y)


(defun jnand (x y)
   (jnot (jand x y))


(defun jnor (x y)
   (jnot (jor x y))


(defun imply (x y)
   (jor (jnot x) y)


(defun iff (x y)
   (jand (imply x y) (imply y x))

The Art of LISP Programming 02

Filed under: Lang:English,Subj:GNU/Computer — Jemyoung Leigh @ 3:29
Tags: , ,

Question 1-5 are about a simple database for names and addresses. This takes the form of a list which we shall call directory, obtained by repeatedly applying cons to lists of the form (name address). In turn, name and address are atoms.

For example, with entries:

Name Address
Eeyore Gloomy-place
Piglet beech-tree
Owl chestnut

dddNaddsdme Address
Eeyore Gloomy-place
Piglet beech-tree
Owl chestnut

directory becomes:

( ( ( Eeyore Gloomy-place)
    ( Piglet Beech-Tree)
    (Owl Chestnut)
  1. Represent the above as a diagram.
  2. How would you set up directory as shown above?
  3. What combination of head and tail functions will return Piglet’s address?
  4. How would you add the list d4: ( Pooh Mr-Saunders ) to the end of the list?
  5. Does ( setq directory1 ( cons d4 directory ) ) add Pooh’s entry to the list?
  6. What does ttail, defined as follows, do? ( defun ttail ( x ) ( tail ( tail x ) ) ) What do you get when it is applied to directory?
  7. Set up four to the list (1 2 3 4). What combination of head and tail return the atoms 1, 2, 3, 4?
  8. Initialise fred with ( setq fred ‘( (1 2) (3 4) ) ) What combinations of head and tail returns atoms 1, 2, 3, 4?
  9. Initialise emily with ( setq emily ‘( (1 2) (3 4) (5 6 7) ) ) Which of the following produce error messages? Otherwise, what is retured?
    1. (head(head(head emily)))
    2. (head(head emily))
    3. (head emily)
    4. (tail(head emily))
    5. (head(tail(head(tail emily))))
  10. If num is (1 2 3), how can you obtain ((1 2 3)) using cons?

This book defines the head and tail as:

(defun head (x) (car x))
(defun tail (x) (cdr x))

(1) I don’t want to do it.


(setq name1 'eeyore)
(setq name2 'piglet)
(setq name3 'owl)
(setq addr1 'gloomy-place)
(setq addr2 'beech-tree)
(setq addr3 'chestnut)
(setq d1 (cons name1 addr1))
(setq d2 (cons name2 addr2))
(setq d3 (cons name3 addr3))
(setq dir (cons d1 d2))
(setq directory (cons dir d3))


(tail (tail (head directory)))


(setq name4 'pooh)
(setq addr4 'mr-saunders)
(setq d4 (cons name4 addr4))
(setq directory (cons directory d4))

(5) I don’t think so. It’s different.

(6) Chestnut before the d4 is added to directory, Mr-Saunders after the d4 is added to directory


(setq four '(1 2 3 4))
(head four)
(head (tail four))
(head (tail (tail four)))
(head (tail (tail (tail four))))


(head (head fred))
(head (tail (head fred)))
(head (head (tail fred)))
(head (tail (head (tail fred))))


  1. Error
  2. 1
  3. (1 2)
  4. (2)
  5. 4


(setq num '(1 2 3))
(cons num NIL)

Monday, 26 July 2010

The Art of LISP Programming 01

Filed under: Lang:English,Subj:GNU/Computer — Jemyoung Leigh @ 21:04
Tags: , ,

I am studying LISP using the book named “The Art of LISP Programming (1990)” printed in Great Britain, and I will post the Exercises of each chapter.

The funny thing is that this book was classified as “Fiction!”

  1. Define a function sq(x) which returns the square of x.
  2. Using sq, define a function diff(x y) which returns x^2-y^2.
  3. According to elementary algebra, x^2-y^2 = (x + y)(x – y). How do you write the right-hand side in LISP?
  4. Define a function called test(x y) which returns 0 if diff(x y) is equal to (x+y)(x-y).
  5. What is the biggest product of two integers which your LISP implementation will evaluate correctly? Why do you think this is?
  6. The ancient Babylonians computed products xy by using tables of squares and the identity:
4xy = (x + y)^2 - (x-y)^2                          (1)

which implies:

xy = ((x+y)^2 - (x-y)^2)/4                         (2)

Write a function forprod(x y) to evaluate the right-hand side of (1) using only sq and the arithmetic primitives. Use it to write a function babyprod(x y) that evaluates the right-hand side of (2). Write a function check(x y) that devides (babyprod x y) by xy, and use it to verify that (babyprod 12 13) = 156.

OK, here go my answers:


(defun sq (x)
(* x x)


(defun diff (x y)
(- (sq x) (sq y))


(* (+ x y) (- x y))


(defun test (x y)
(- (diff x y) (* (+ x y) (- x y)))

(5) I don’t know.


(defun forprod (x y)
(- (sq (+ x y)) (sq (- x y)))
(defun babyprod (x y)
(/ (forprod x y) 4)
(defun check (x y)
(/ (babyprod x y) (* x y))

Monday, 19 July 2010

Immigration Receipt

Today, I got a letter from Canadian Consulate in Buffalo. That was the receipt of my immigration application – I applied in February and got the receipt in almost at the end of July!

Anyway this is one big step forward and the sign that it moves on.

The medical check request form was included, and I made an appointment on August 17th.

오늘 버팔로에 있는 캐나다 영사관에서 편지가 왔는데, 열어보니 이민 신청서 접수증이었다. 2월에 신청했는데, 7월에 접수증이 나오다니 -_-;;

어째든, 큰 진전이고 또한 진행이 되긴 한다는 증거기도 하다.

영주권 신검 통지서도 같이 동봉되어 왔고, 바로 병원에 예약을 해서 8월 17일로 잡았다.

Wednesday, 14 July 2010

Discount for speed camera ticket

A friend of mine who lives in Neepawa got a speeding ticket taken in Winnipeg by a camera with the fine of $292.

She was driving 79km/h while the speed limit was 60km/h.

She wanted the discount but she made a mistake by pleading NOT GUILTY, so the provincial court took a trial date.

Today she came to Winnipeg and we went to the court together and cancelled the trial acknowledging that she was guilty. And I explained about the speeding ticket for her. So the $292 fine became $125. The discount rate is 57.2%!

Was it 10th time that I helped other Koreans to get discount for the tickets? I don’t know because I didn’t count at all. Sometimes for the speeding and sometimes for the signal violation.

I took my afternoon off – so I lost my money, and I spent whole afternoon. And she saved $167 because of me, and still there is nothing for me. I just lost my money and time – this kind of things are very usual when you help Koreans. But I am totally OK because I don’t expect anything when I help somebody.

니파와에 살고 있는 한 분이 위니펙에서 과속으로 카메라에 찍혀서 벌칙금을 받았다. 벌금이 292불이었다.

60km/h 속도 제한인 곳에서 79km/h로 달렸다.

원래는 할인을 받으려 했다는데, 실수를 해서 “무죄” 주장을 하게 되었고, 법정에서는 재판 날짜를 잡아버렸다.

오늘 그분이 위니펙에 와서 법원에 같이 가서, 일단 유죄를 인정해서 재판을 취소하고 판사에게 과속 사건에 대해 설명을 해줬다. 그래서 292불짜리 벌금을 125불로 깍아줬다. 할인율이 무려 57.2%나 된다!

교통 벌금을 깍아준게 이번에 10번째인지 몇번째인지 세지 않아서 정확히 모르겠다. 과속도 있었고 신호 위반도 있었다.

오늘 이것 때문에 오후를 쉬었기 때문에 급료가 깍인다. 그리고 오후 내내 시간을 썼다. 그리고 그분은 내 덕에 167불을 절약했다. 하지만, 나한테 돌아오는 건 아무 것도 없다. 난 그저 시간과 돈을 낭비했을 뿐. 한국분들을 도와줄 때는 거의 늘 이렇다. 하지만 내가 뭘 기대하면서 도와주는 게 아니기 때문에 괜찮다.

Wednesday, 7 July 2010

What a Day!

Last Saturday, July 3rd.

The Queen was here in Winnipeg!

You can see more at http://www.winnipegsun.com/queen/

I was watching children’s baseball game at Little Mountain Sportsplex near the Inkster and Sturgeon.

There was a so strong sunshine in the west burning my skin.

And a very clear rainbow in the east.

Most of the sky was covered with clouds.

And the very spot where I was, just pouring cats and dogs.

And in the North, I saw a fun of cloud in the shape of tornado. I thought that cloud just looked like a tornado, but actually that was one. There was Tornado Watch!

What a day, eh!

지난 토요일인 7월 3일.

여왕님이 위니펙에 방문하셨다!

자세한 것은 http://www.winnipegsun.com/queen/를 참조하길.

그날 저녁에 잉스터와 스터전 근처에 있는 리틀 마운튼 스포츠플렉스에서 어린이 야구 시합을 관람하고 있었는데,

서쪽에서는 아주 강한 햇빛이 피부를 태우고 있었고,

동쪽에는 꽤 선명한 무지개가 빛나고 있었고,

대부분의 하늘은 구름으로 덮여 있었고

내가 있던 바로 그 자리에는 비가 미친듯이 퍼부었다.

그리고 북쪽하늘에서는 토네이도처럼 생긴 구름이 있었다. 난 그저 구름이 토네이도 모양이라고만 생각했는데, 그게 실제 토네이도였다! 그날 토네이도 경보가 내렸었다!

와, 정말 대단한 날이다.

Create a free website or blog at WordPress.com.