[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: if vs. when vs. and: style question
From: |
Pascal J. Bourguignon |
Subject: |
Re: if vs. when vs. and: style question |
Date: |
Wed, 25 Mar 2015 08:12:01 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Rusi <rustompmody@gmail.com> writes:
> On Wednesday, March 25, 2015 at 8:10:18 AM UTC+5:30, Emanuel Berg wrote:
>> "Pascal J. Bourguignon" writes:
>>
>> > But then, why stop with +?
>> >
>> > You could use instead:
>> >
>> > (funcall (additive-operator (ring integer))
>> > (neutral-element (multiplicative-operator (ring
>> > integer))) 5) ; 6
>> >
>> > or something even more general?
>
> I find Pascal's example brilliant and hilarious.
> In this case though, I slightly err on your (Emanuel) side.
>
> When I see the 1+, I have a stop (like um... er...)
> Is that a number, an expression, a constant, a comment?
>
> Oh Oh.. Functions can start with digits (Yeah this is lisp...)
Indeed, it is clear that the names 1+ and 1- are ill-choosen.
Notably 1-!!!
(1- x) == (- x 1)
BUT
Those are actually fundamental operators, more fundamental than addition
and substration, both in a theoric way, and in practice with a lot of
processors.
They are the operators named succ(x) and pred(x) in pascal (which C
lacks as independent operators, but have combined with updating with the
pre- and post- complifications of ++x, x++, --x, and x--; C is THE crazy
language).
In axiomatic number/set theory, we only assume a number noted 0, and a
succ(x) operation that let us build a new number from any number x.
so 1 = succ(0) by definition. (= 1 (1+ 0))
You do not program it the other way around, defining 1+ from x and 1,
you define 1 from 1+ and 0!
And the proof, is that processors usually have an increment and a
decrement operation even while they may lack a general load operation
(working or any immediate word-sized number).
So when you write x:=512; you may actually obtain a "load #511; incr"
instruction sequence, ie. (1+ 511).
So write:
(defun succ (x) (1+ x))
(defun pred (x) (1- x))
or in elisp:
(defalias 'succ '1+)
(defalias 'pred '1-)
and use (succ x) instead of (1+ x) or (+ x 1).
(Remember that the only literal numbers allowed in a program source are
0 and 1; well, it's even better if you allow only 0 and (succ x)).
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
- if vs. when vs. and: style question, Marcin Borkowski, 2015/03/23
- RE: if vs. when vs. and: style question, Drew Adams, 2015/03/23
- Re: if vs. when vs. and: style question, Pascal J. Bourguignon, 2015/03/23
- Message not available
- Re: if vs. when vs. and: style question, Emanuel Berg, 2015/03/23
- Re: if vs. when vs. and: style question, Rusi, 2015/03/24
- Re: if vs. when vs. and: style question, Emanuel Berg, 2015/03/24
- Re: if vs. when vs. and: style question, Pascal J. Bourguignon, 2015/03/24
- Re: if vs. when vs. and: style question, Emanuel Berg, 2015/03/24
- Re: if vs. when vs. and: style question, Rusi, 2015/03/24
- Re: if vs. when vs. and: style question,
Pascal J. Bourguignon <=
- Re: if vs. when vs. and: style question, Rusi, 2015/03/25
- Re: if vs. when vs. and: style question, Stefan Monnier, 2015/03/25
- Re: if vs. when vs. and: style question now Unicode, Dan Espen, 2015/03/25
- Re: if vs. when vs. and: style question now Unicode, Rusi, 2015/03/25
- Re: if vs. when vs. and: style question now Unicode, Dan Espen, 2015/03/25
- Re: if vs. when vs. and: style question now Unicode, Rusi, 2015/03/25
- Re: if vs. when vs. and: style question now Unicode, Dan Espen, 2015/03/25
- Re: if vs. when vs. and: style question now Unicode, Emanuel Berg, 2015/03/28
- Re: if vs. when vs. and: style question now Unicode, Rusi, 2015/03/25
- Re: if vs. when vs. and: style question, Pascal J. Bourguignon, 2015/03/25