Re: [OPINION] - does language really matter if they all do the samething?

From: Paul Rubin (//phr.cx_at_NOSPAM.invalid)
Date: 02/16/04


Date: 16 Feb 2004 00:32:36 -0800

Dietrich Epp <dietrich@zdome.net> writes:
> My Lisp project related to an RPG and random generation of items.
> It had lots of code like the following:
>
> (defun random-sword-magic-power (quality)
> (choose-random-assoc
> quality (poor medium good)
> ((5 0 0) (glows-in-the-dark))
> ((3 3 0) (magically-silent))
> ((1 5 1) (elemental-power (select-random '(earth water air fire))))
> ((0 2 4) (magical-keen-edge))
> ((0 0 2) (append (random-sword-magic-power 'medium)
> (random-sword-magic-power 'medium)))))
> ...
> I'm not trying to say that all applications are like my application,
> and I'm not trying to say that my application can't be written in
> Python. I'm just saying that using macros, a paradigm that Python
> doesn't even come close to supporting, makes reading and writing
> functions like the above a lot easier. You don't even need to know
> that 'choose-random-assoc' is a macro, you just need to know how to
> use it. Heck, defun is a macro in Clisp.

I don't understand why choose-random-assoc needs to be a macro instead
of a function in the above example.

> I challenge anyone to come up with a better way to express the above
> function in Python. If I think it's better, I'll write "PYTHON RULZ"
> on my forehead and post a photo on the web.

This doesn't look too bad:

def random_sword_magic_power (quality):
  prob_list = [(5, 0, 0, power.glows_in_the_dark),
               (3, 3, 0, power.magically_silent),
               (1, 5, 1, power.elemental_power,
                           random.choice(('earth','water','air','fire))),
               (0, 2, 4, power.magical_keen_edge),
               (0, 0, 2, random_sword_magic_power('medium') +
                           random_sword_magic_power('medium'))]
  quality_level = ('poor', 'medium', 'good').index(quality)
  return [weighted_random_choice(quality_level, prob_list)]



Relevant Pages

  • Re: [OPINION] - does language really matter if they all do the samething?
    ... >> My Lisp project related to an RPG and random generation of items. ... I'm just saying that using macros, a paradigm that Python ... defun is a macro in Clisp. ... See my last posts on this thread where I missed that also and then ...
    (comp.lang.python)
  • Re: Python syntax in Lisp and Scheme
    ... >> Haven't some people implemented an entire class system as one huge macro? ... Then I discovered Python, ... > a given that any person who likes Scheme must inevitably dislike ...
    (comp.lang.python)
  • Re: Win32 python and excel macros
    ... Looking for a very quick bit on of advice on how to make some python ... I'm a newbie to both VBA and Python, ... The macro is called sub is CTP and the add-in file is CTP.XLA ...
    (comp.lang.python)
  • Re: merits of Lisp vs Python
    ... terms from the student's problem to produce a hint or annotation. ... Because the text is like a macro. ... > using Python, then it's because one doesn't much care about performance, ... iterations walking around in circles making your macro more clever, ...
    (comp.lang.python)
  • Re: Python syntax in Lisp and Scheme
    ... Python does not a have very good ... > macro capabilities, unfortunately. ... libraries, frameworks, etc, instantly available from Lisp or ... Scheme, you'd gain a LOT of kudos in the Lisp or Scheme ...
    (comp.lang.lisp)