Re: Myster Tour

new topic     » goto parent     » topic index » view thread      » older message » newer message

On 11 Aug 2000, at 10:34, Paul Kerslake wrote:

> I think I've found out why I find programming so confusing. I understand the
> commands, the
> concepts of sequence and atom etc. It's those little numbers that get to me.
> Little
> numbers that palgue nearly all of the commands! Here's what I'm ranting about:
>
> THIS IS THE "SIMPLE.EX" FILE IN THE TUTORUAL
>
> function simple_sort(sequence x)          -- how does one use function? and
> what does
> simple_sort(sequence x) mean?

A function is like a procedure, only it returns something to the line that
called it. Like
this:
sorted_seq = simple_sort(unsorted_seq)

The program jumps to the simple_sort() line, and runs it, plugging in the
unsorted_seq
in my example for the x in the function line. When the function is done
processing, it
returns the processed sequence and plugs it into sorted_seq in my example. ( Why
we can do this, and not have a "goto" command is still beyond my feeble powers
of
comprehension. Functions and procedures are essentially "gosub"s.)

> object temp
>     for i = 1 to length(x) + 1 do                -- is length(x) the legnth of
>     simple_sort? if so, why not just for i=1 to length(simple_sort)

Because "simple_sort" is the name of the function, not the name of the var
holding the
seq to be sorted.

>         for j = i + 1 to length(x) do
>             if compare(x[j],x[i]) < 0 then     --    \
>                 -- swap x[j], x[i]                    --     \

Just what it says there, it swapped the j section of x and the i section.
Sections get
called slices and subsequences too.

>                 temp = x[j]                --                   ----   I need
>                 these ones

That's easy, "temp" is assigned the value of the j section of x.

>                 explained, I've got no idea what they mean x[j] = x[i]
>                 --                / x[i] = temp                --             
>                   /
>             end if
>         end for
>     end for
>     return x                        -- whats return do?

Understand it yet?

> end function
>
> Well, there's another batch of problems.........get it? Batch?
> heheheh..............erm...

Think of a procedure as a simple dos batch file. Think of a function as a
procedure that
can reply with a processed value or an error code.

Kat

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu