Newsgroups: comp.lang.lisp
From: Rainer Joswig <jos...@lisp.de>
Date: Fri, 26 Sep 2008 21:19:59 +0200
Local: Fri, Sep 26 2008 3:19 pm
Subject: Re: Lisp Design Patterns
In article
<b4441692-2db8-46b2-893e-10b26d424...@l42g2000hsc.googlegroups.com>, vttoonses <vttoon...@gmail.com> wrote: I don't really think in those object-oriented design patterns > On Sep 26, 1:21 pm, Bakul Shah <bakul+use...@bitblocks.com> wrote: > > Rainer Joswig wrote: > > > That's not a 'design pattern'. That's architecture. > > Concise, funny & profound (meaning: exactly my sentiments!). > Actually, I was trying to ask a general question and provide some > "This is how I would normally construct my application at a macro of the GoF book. I've seen Java developers doing it. I don't. See for example this Python code from class Pizza: def __init__(self): def getPrice(self): class HamAndMushroomPizza(Pizza): class DeluxePizza(Pizza): class SeafoodPizza(Pizza): class PizzaFactory: pizzaPrice = PizzaFactory().createPizza(Pizza.HAM_MUSHROOM_PIZZA_TYPE).getPrice() That's so ugly. Amazingly ugly. Probably there are Imagine (for a moment) you would write that in Lisp: (defclass pizza () (defclass ham-and-mushroom-pizza (pizza) (defclass deluxe-pizza (pizza) (defclass seafood-pizza (pizza) (defmethod make-pizza ((type (eql 'gimme-some-ham-and-mushroom-pizza))) (defmethod make-pizza ((type (eql 'gimme-some-deluxe-pizza))) (defmethod make-pizza ((type (eql 'gimme-some-seafood-pizza))) (defun give-me-some-pizza (what) (pizza-price (give-me-some-pizza 'give-me-some-ham-and-mushroom-pizza)) Arrrrrrrrrrrrrrrrrrrrrrrrggghhh!!!!! Then you think let's get rid of the methods: (defclass pizza () (defclass ham-and-mushroom-pizza (pizza) (defclass deluxe-pizza (pizza) (defclass seafood-pizza (pizza) (defparameter *pizza-assoc-list* (defun give-me-some-pizza (what) But then you think WTF, WTF, WTF: (defclass pizza () (defmacro defpizza (name price) (defpizza ham-and-mushroom-pizza 8.50) (defun make-pizza (class) (pizza-price (make-pizza 'ham-mushroom-pizza)) Pass the class name directly. If you want to do something If you would really need numbers for classes, then you would just lookup (defclass pizza () (defparameter *number-to-pizza-table* (make-hash-table)) (defmacro defpizza (name &key price number) (defpizza ham-and-mushroom-pizza :price 8.50 :number 0) (defun make-pizza (number) (pizza-price (make-pizza 2)) Suddenly the code gets a whole lot more descriptive. How would you name a pattern from where you would derive The important thing is not the technical solution What you NEED to learn is to live with the flexibility of Lisp You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||