1. puzzling code

Hi, All.

While studying Matt Arriola's Crypt.ex code (Recent User Contibutions),
I found a line of code which I'm at a loss to understand.
Simulated code follows;

-- begin code

with trace
sequence bits
object dummy
trace(1)

bits = "11000111001111000011100110101011"

bits -= '0'    <--- what's this doing???

dummy = 21      -- has no meaning ... here just for the trace
-- end code

if you run the above which trace on,  and watch the display of
variables under the trace window, you'll see how the line
"bits -= '0' transforms the sequence bits. Can somebody explain
what's happening ?

Appreciate any help.

new topic     » topic index » view message » categorize

2. Re: puzzling code

> Hi, All.
>
> While studying Matt Arriola's Crypt.ex code (Recent User Contibutions),
> I found a line of code which I'm at a loss to understand.
> Simulated code follows;
>
> -- begin code
>
> with trace
> sequence bits
> object dummy
> trace(1)
>
> bits = "11000111001111000011100110101011"
>
> bits -= '0'    <--- what's this doing???
>
> dummy = 21      -- has no meaning ... here just for the trace
> -- end code
>
> if you run the above which trace on,  and watch the display of
> variables under the trace window, you'll see how the line
> "bits -= '0' transforms the sequence bits. Can somebody explain
> what's happening ?
>
> Appreciate any help.
it's subtracting the the value of '0'(48) from the `bits` sequence, making
each element the actual numeric value of number that is represented.
In short, it's a quick and crude form of value()

Chris

new topic     » goto parent     » topic index » view message » categorize

3. Re: puzzling code

I think joshua added the dummy variable so the value of bits would be
displayed before the trace facily terminated.

is there a reason why you didn't just write..
bits = {1,1,1,0,0,0,0,0,1,1,1,0,etc}

or was that just from joshua's demo code?

Chris

> thanks for showing an interest in my code! ;) i believe chris explained
> the thing with the binary code, but i forgot what that dummy object was
> for...probably just a relic. in fact, i don't remember even putting it
> in there!
>
> joshua goldberg wrote:
> > Hi, All.
> >
> > While studying Matt Arriola's Crypt.ex code (Recent User Contibutions),
> > I found a line of code which I'm at a loss to understand.
> > Simulated code follows;
> >
>
> *snip*
>
>
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu