Changes between Version 1 and Version 2 of Tutorial2


Ignore:
Timestamp:
Dec 14, 2012, 1:19:05 PM (7 years ago)
Author:
schiptsov
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Tutorial2

    v1 v2  
    3636
    3737This is why in computer science we start counting from zero. Always. Just accept it. There is a deep reason for it.
    38    
    39 What if do not know the size of my sequence in advance? It means that I can't ask what is an element with offset 10, because there may be only 5 of them, or seven.
    4038
    41 If I would try to get a content of a byte at offset 10, it will be just random number, that happen to be in this byte, and have nothing to do with my structure.
     39What if I do not know the ''size of my sequence'' in advance? It means that I can't ask ''what is an element with offset 10'', because there might be only 5 of them, or 7.
    4240
    43 The answer is, I must have something special to mark the end-of-sequence. It must be an unique thing, which cannot be a part of sequence itself. Very difficult.
     41If I would try to get the content of a byte at offset 10, it will be just random number which happen to be in (a value of) this particular byte, and have nothing to do with the data in my structure.
    4442
    45 But, look, the base address of a sequence and the address of its first element are the same number. Offset 0 is the same as base address. So, why not use 0 to mark the end-of-sequence.
     43The answer is - I must have something special to mark the ''end-of-sequence''. It must be an ''unique identity'' which cannot be a part of sequence itself. Very difficult.)
    4644
    47 This means we can have any numbers in a sequence, except zero, anything but zero.
     45But, look, the ''base address'' of a sequence and the ''address of its first element'' are the same number - ''offset 0'' is the same as base address. So, why not use 0 to mark the ''end-of-sequence''?
    4846
    49 What a number can represent? Generally two things - an offset or a code for a something.
     47This means we can have any numbers in a sequence, ''except zero'', ''anything but zero''.
    5048
    51 Code, by the way, is just an abstract term, so, for example, an offset (of another number) is a code for it.
     49Lets ask another question. What a number can represent? Well, an ''offset'' or a ''code'' for  something (another number).
    5250
    53 Another word (a synonym) for an offset is an address.
     51Code, by the way, is just an abstract term, so, for example, an offset (of another number) is a ''code'' for it.
    5452
    55 So, for sequences of addresses (offsets) it is OK, because offset 0 is the same as base. For representing sequences of characters it is also fine, just avoid 0.
     53Another word (a ''synonym'') for an ''offset'' is an ''address''.
    5654
    57 The only problem is a sequence of an arbitrary numbers. Well, there is no such thing as an arbitrary-length sequence of arbitrary numbers, including zero. But it works for almost everything else - offsets, characters, etc.
     55So, for sequences of addresses (offsets) it is OK, because ''offset 0'' is the same as the ''base''. For representing ''sequences of codes'' it is also fine, just avoid 0.
    5856
    59 So, this is how zero became a universal marker for the end-of-sequence.
     57The only problem is a sequence of an arbitrary numbers. Well, there is no such thing as an arbitrary-length sequence of arbitrary numbers, including zero - it is too abstract. But it works for almost everything else - offsets, codes, etc.
    6058
    61 How do I know the length of an arbitrary-length sequence? I will count until I hit the end-of-sequence mark.
     59So, this is how zero became a universal marker for the end-of-sequence of codes.
     60
     61How do I know the length of an arbitrary-length sequence? I will count until I hit the ''end-of-sequence'' mark.
    6262
    6363This means I would check the content of each consecutive byte, until I got zero.
     64{{{
     65(define (length l)
     66  (if (null? l)
     67      0
     68      (+ 1 (length (cdr l)))))
     69}}}
     70This code is a premature enlightenment, but these ''rules'' and ''reasoning'' about the structure of the data are the essence of CS.)
    6471
    65 These rules about the structure of the data are the essence of CS.)
     72Now, what is ''the-empty-list''? It is a ''list-of-no-thing''. Just nothing. To represent ''no thing'' there is a ''symbol'' for it - ''zero''. 0. So, '() is just 0.
    6673
    67 What is the-empty-list? It is a list-of-no-thing. Or just nothing. To represent nothing there is a symbol for it - zero. 0. So, '() is just 0.
     74[wiki:/Tutorial4 Continue..]