1. Re: Minimal language (was: registration and requests)

Scott Murray writes:
[using only the minimal language...]
>>1.   var = 0
>>2.   var = var + 1
>>3.   goto label
>>4.   loop var times ... end loop

>  No conditional or boolean testing
You'd like to say:  if x then A... else B... end if ...
where 0 is false, non-zero is true.
How about:

     loop x times
          A...
          goto endif
     end loop
      B...
endif: ...

> You specifically stated adding 1, but implied that there
> could be no x = x + -1, meaning no negative numbers.
>  Addition and multiplication are easy, but I can't figure out
> subtraction or division,

In this language there are only integers >= 0.
Any mathematical problem can be expressed in some
manner using just the positive integers. (For negative integers,
have two variables, one holds the "sign", the other holds the
"magnitude". For floating-point, have vars that hold the fraction, a/b,
the exponent etc.)

Here's how to subtract one in this language. Note that
subtracting 1 from 0 is not allowed, so the following
code sets y to 0 when x is 0:

Calculate y = x - 1:

y = 0
z = 0
loop x times
    y = 0
    loop z times       (set y = z)
        y = y + 1
    end loop
    z = z + 1
end loop

Obviously there are some efficiency concerns here smile

Now that you can subtract 1, you can figure out how to subtract n,
and just as addition leads to multiplication, subtraction leads to
division.

Regards,
     Rob Craig
     Rapid Deployment Software
     http://members.aol.com/FilesEu/

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu