public inbox for xconq7@sourceware.org
 help / color / mirror / Atom feed
* Re: RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae)
@ 2004-06-22 17:43 Erik Sigra
  2004-06-23  4:21 ` Erik Sigra
  0 siblings, 1 reply; 6+ messages in thread
From: Erik Sigra @ 2004-06-22 17:43 UTC (permalink / raw)
  To: xconq7; +Cc: j.ruehle, xconq7

> So, I guess the choices for increment and decrement
> are:
> (++ n) (-- n)
> (inc n) (dec n)
> (1+ n) (1- n)
>
> Does anyone have any preferences (aside from those
> already stated)?

I like (+ n 1) and (- n 1) most. It is general and also works with for example 2. It is almost as short to write and already implemented.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae)
  2004-06-22 17:43 RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae) Erik Sigra
@ 2004-06-23  4:21 ` Erik Sigra
  0 siblings, 0 replies; 6+ messages in thread
From: Erik Sigra @ 2004-06-23  4:21 UTC (permalink / raw)
  To: xconq7; +Cc: j.ruehle, xconq7

> So, I guess the choices for increment and decrement
> are:
> (++ n) (-- n)
> (inc n) (dec n)
> (1+ n) (1- n)
>
> Does anyone have any preferences (aside from those
> already stated)?

I like (+ n 1) and (- n 1) most. It is general and also works with for example 2. It is almost as short to write and already implemented.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae)
  2004-06-23  6:02           ` Eric McDonald
@ 2004-06-23  6:17             ` Jim Kingdon
  0 siblings, 0 replies; 6+ messages in thread
From: Jim Kingdon @ 2004-06-23  6:17 UTC (permalink / raw)
  To: mcdonald; +Cc: xconq7

> As it turns out, my concern was somewhat justified, after I made the
> horrific discovery this evening that I had broken negative number
> tokenization a few days ago. I have now fixed this, _but it shows that
> even the simplest hacks can produce big bugs.

That's what you get for not writing any tests :-).

Unlike many parts of xconq, writing autotest-style tests for GDL
parsing is really easy.

I suppose if I feel like writing some xconq tests, I could start with
these, rather than proceeding directly to the nastier, harder to test
things like "make sure the AI knows how to use a transport".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae)
  2004-06-22 14:50         ` Jim Kingdon
@ 2004-06-23  6:02           ` Eric McDonald
  2004-06-23  6:17             ` Jim Kingdon
  0 siblings, 1 reply; 6+ messages in thread
From: Eric McDonald @ 2004-06-23  6:02 UTC (permalink / raw)
  To: Jim Kingdon; +Cc: xconq7

On Tue, 2004-06-22 at 08:50, Jim Kingdon wrote:
> > So, I guess the choices for increment and decrement are:
> > (++ n) (-- n)
> > (inc n) (dec n)
> > (1+ n) (1- n)
> 
> I'd say "1+" and "1-".  Dice specs contain a "d", so they don't look
> all *that* confusable to me.

I will add "1+" and "1-" at a later point. They need to be defined as
new operators, and it seems that they might work a bit differently than
the basic four.

With "+", the lengths of the list operands must be the same: 
  (+ 1 (2 3) (4 5))
But, it would seem reasonable that this constraint need not apply with
"1+" and "1-":
  (1+ (1 2 3) (4 5))
since each operand is operated on independently of the others. The
current structure of 'eval_arithmetic_expression' does not allow this
behavior to be easily integrated; I would have to write a new logic
branch in the function to deal with this.

For the time being, I will leave the increment and decrement
functionality out.

I did address Juergen's suggestion about reflection and negation:
 (+ 5)
now evaluates to 5, and 
 (- 5)
now evaluates to -5.

I also added the seemingly useless feature of "+" returning the additive
identity (0) and "*" returning the multiplicative identity (1), to
comply with Common Lisp.

As far as the dice spec argument goes, I admit that is was lame. I was
in a hurry to get out the door this morning when I wrote it. The real
reason for my reluctance with that notation is because I didn't want to
hack the "el cheapo" Lisp reader (as it is referred to in the comments
introducing it) again, if I didn't have to. As it turns out, my concern
was somewhat justified, after I made the horrific discovery this evening
that I had broken negative number tokenization a few days ago. I have
now fixed this, _but it shows that even the simplest hacks can produce
big bugs.

Eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae)
  2004-06-22 14:18       ` RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae) Eric McDonald
@ 2004-06-22 14:50         ` Jim Kingdon
  2004-06-23  6:02           ` Eric McDonald
  0 siblings, 1 reply; 6+ messages in thread
From: Jim Kingdon @ 2004-06-22 14:50 UTC (permalink / raw)
  To: mcdonald; +Cc: xconq7

> So, I guess the choices for increment and decrement are:
> (++ n) (-- n)
> (inc n) (dec n)
> (1+ n) (1- n)

I'd say "1+" and "1-".  Dice specs contain a "d", so they don't look
all *that* confusable to me.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae)
  2004-06-22  9:50     ` Juergen Ruehle
@ 2004-06-22 14:18       ` Eric McDonald
  2004-06-22 14:50         ` Jim Kingdon
  0 siblings, 1 reply; 6+ messages in thread
From: Eric McDonald @ 2004-06-22 14:18 UTC (permalink / raw)
  To: Juergen Ruehle; +Cc: xconq7

Hi Juergen,

On Tue, 2004-06-22 at 03:50, Juergen Ruehle wrote:

> Actually I would prefer the (Common) LISP version:

I guess I should have checked to see what Common Lisp did instead of
writing some code first.

>   (1+ 5) => 6
>   (1- 5) => 6

This seems fairly reasonable. However, GDL has dice specs which look
like mmdnn+oo. Doing something like "1+" looks like part of a dice spec.
This is not a problem from the tokenization point of view; it would
require another tokenizer hack, but that is manageable. I am more
concerned about confusion on the part of GDL users.

>   (+ 5) => 5
>   (- 5) => -5

I agree. One of the concerns that was in the back of mind was how to
easily negate a number. I think I will change the behavior of unary "+"
and "-" to what you just suggested.

> This avoids overloading of + and -, but that's just IMO.

Thanks for the feedback.

So, I guess the choices for increment and decrement are:
(++ n) (-- n)
(inc n) (dec n)
(1+ n) (1- n)

Does anyone have any preferences (aside from those already stated)?

  Regards,
    Eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-06-23  6:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-22 17:43 RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae) Erik Sigra
2004-06-23  4:21 ` Erik Sigra
  -- strict thread matches above, loose matches on Subject: below --
2004-06-21  6:50 GDL Notice: Arithmetic Operators / Quasi-Formulae Eric McDonald
2004-06-22  3:25 ` Eric McDonald
2004-06-22  6:19   ` Jim Kingdon
2004-06-22  9:50     ` Juergen Ruehle
2004-06-22 14:18       ` RFC: Increment and Decrement (was Re: GDL Notice: Arithmetic Operators / Quasi-Formulae) Eric McDonald
2004-06-22 14:50         ` Jim Kingdon
2004-06-23  6:02           ` Eric McDonald
2004-06-23  6:17             ` Jim Kingdon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).