Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Method specialization style question
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pascal Bourguignon  
View profile  
 More options Mar 26 2004, 3:41 pm
Newsgroups: comp.lang.lisp
From: Pascal Bourguignon <s...@thalassa.informatimago.com>
Date: 26 Mar 2004 21:42:42 +0100
Local: Fri, Mar 26 2004 3:42 pm
Subject: Re: Method specialization style question

Peter Seibel <pe...@javamonkey.com> writes:
> > You don't withdraw numbers, you withdraw money!

> Yeah, yeah. You are, of course, correct. However I'm not *really*
> writing a banking app. But I could reframe my question assuming an
> appropriate MONEY class with associated functions as:

>    (defmethod withdraw ((account account) amount)
>      (if (money>= (balance account) amount)
>        (cash-decrement (balance account) amount)
>        (error "Insufficient funds.")))

> vs

>    (defmethod withdraw ((account account) (amount money))
>      (if (money>= (balance account) amount)
>        (cash-decrement (balance account) amount)
>        (error "Insufficient funds.")))

But now we've progressed.

There may be several kind of "money". Not only devises that are all of
the same kind of fiat money.  From some account you can withdraw gold,
or shares.

You could have:
    (defclass value ())
    (defclass gold   (value)
        ((mass  :type integer :documentation "unit mg")))
    (defclass money (value)
        ((facial-value :type integer)
         (devise       :type devise)))

Then you would definitely want to do:

    (defmethod withdraw ((account account) (amount money))   ...)
    (defmethod withdraw ((account account) (amount gold))    ...)

(But actually, as it has been noted, since there are several kind of
withdrawals (atm, cashier, etc), you want to reify it).

--
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/


 
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.