1. Myster Tour

------=_NextPart_000_0005_01C0037F.AE1ADD60
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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?=20
object temp
    for i =3D 1 to length(x) + 1 do                -- is length(x) the =
legnth of simple_sort? if so, why not just for i=3D1 to =
length(simple_sort)
        for j =3D i + 1 to length(x) do
            if compare(x[j],x[i]) < 0 then     --    \
                -- swap x[j], x[i]                    --     \
                temp =3D x[j]                --                   ----   =
I need these ones explained, I've got no idea what they mean
                x[j] =3D x[i]                    --                /
                x[i] =3D temp                --                /
            end if
        end for
    end for
    return x                        -- whats return do?
end function

Well, there's another batch of problems.........get it? Batch? =
heheheh..............erm...
Thanks

-Thomas   (Yes, it is right to those who asked!)

------=_NextPart_000_0005_01C0037F.AE1ADD60
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I think I've found out why I find =
programming so=20
confusing. I understand the commands, the concepts of sequence and atom =
etc.=20
It's those little numbers that get to me. Little numbers that palgue =
nearly all=20
of the commands! Here's what I'm ranting about:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>THIS IS THE "SIMPLE.EX" FILE IN THE=20
TUTORUAL</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>function simple_sort(sequence=20
x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- how =
does&nbsp;one=20
use function? and what does simple_sort(sequence x)&nbsp;mean? =
<BR>object=20
temp<BR>&nbsp;&nbsp;&nbsp; for i =3D 1 to length(x) + 1 =
do&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- is length(x) =
the=20
legnth of simple_sort? if so, why not just for i=3D1 to=20
length(simple_sort)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for j =
=3D i + 1=20
to length(x)=20
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
if=20
compare(x[j],x[i]) &lt; 0 then&nbsp;&nbsp;&nbsp;&nbsp;=20
-- swap x[j], x[i]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
temp =3D x[j]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
I&nbsp;need these ones explained, I've got no idea what they=20
;&nbsp;&nbsp;&nbsp;&nbsp;=20
x[j] =3D x[i]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
bsp;&nbsp;&nbsp;&nbsp;=20
x[i] =3D temp&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
end=20
if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end =
for<BR>&nbsp;&nbsp;&nbsp;=20
end for<BR>&nbsp;&nbsp;&nbsp; return x&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; --=20
whats return do?<BR>end function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Well, there's another batch of =
problems.........get=20
it? Batch? heheheh..............erm...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-Thomas&nbsp;&nbsp; (Yes, it is right =
to those who=20

------=_NextPart_000_0005_01C0037F.AE1ADD60--

new topic     » topic index » view message » categorize

2. Re: Myster Tour

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 message » categorize

3. Re: Myster Tour

------=_NextPart_000_0056_01C00397.A9E9F100
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Paul, sounds like you need to RTFM. smile

In lieu of that, here's this:
  function simple_sort(sequence x)          -- how does one use =
function? and what does simple_sort(sequence x) mean?=20

  A function returns a value, whereas a procedure does not. So, you =
would use this function this way:

      aValue =3D simple_sort( aSequence)

  where aSequence is a sequence, or list, of values, whether string =
types or other...

  The (sequence x) part simply tells the programmer what data the =
function needs in order to work properly. In this case, =
simple_sort(sequence x) is looking to receive a sequence, which it will =
refer to as 'x,' because it's reason for being is to take unsorted =
sequences and sort them.

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

  Here, the function "length" is providing a value for the "for" =
statement. Why it needs to add one to it would take more investigating =
than I have time for right now.

          for j =3D i + 1 to length(x) do
              if compare(x[j],x[i]) < 0 then     --    \
                  -- swap x[j], x[i]                    --     \
                  temp =3D x[j]                --                   ---- =
  I need these ones explained, I've got no idea what they mean
                  x[j] =3D x[i]                    --                /
                  x[i] =3D temp                --                /
              end if
          end for

  The brackets are simply pointing to a value in the sequence (or =
array).

  If we have a sequence composed of five elements, called janitor:

      janitor =3D { 1 , "B" , { 1 , "CB" } , xray , "plunk" }

  then element 5, accessed as follows:

      vVar =3D janitor[5]

  vVar would be "plunk".

      return x                        -- whats return do?

  Returns the value to the calling program, indicating that the function =
is done processing.


------=_NextPart_000_0056_01C00397.A9E9F100
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2722.2800" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Paul, sounds like you need to RTFM. smile</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size=3D2>In lieu of that, here's this:</FONT></DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2>function simple_sort(sequence=20
  x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- how =
does&nbsp;one=20
  use function? and what does simple_sort(sequence x)&nbsp;mean? =
</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>A function returns a value, whereas a =
procedure does=20
  not. So, you would use this function this way:</STRONG></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; aValue&nbsp;=3D =
simple_sort(=20
  aSequence)</FONT></STRONG></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>where aSequence is a sequence, or list, of =
values,=20
  whether string types or other...</STRONG></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>The (sequence x) part simply tells the =
programmer=20
  what data the function needs in order to work properly. In this case,=20
  simple_sort(sequence x) is looking to receive a sequence, which it =
will refer=20
  to as 'x,' because it's reason for being is to take unsorted sequences =
and=20
  sort them.</STRONG></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; for i =3D 1 to =
length(x) + 1=20
  do&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  -- is length(x) the legnth of simple_sort? if so, why not just for =
i=3D1 to=20
  length(simple_sort)</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>Here, the function "length" is providing a =
value for=20
  the "for" statement. Why it needs to add one to it would take more=20
  investigating than I have time for right now.</STRONG></FONT></DIV>
  <DIV><FONT face=3DArial =
  for j =3D i + 1 to length(x)=20
  =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
if=20
  compare(x[j],x[i]) &lt; 0 then&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
  -- swap x[j], x[i]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  =
  temp =3D x[j]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp;=20
  =
  I&nbsp;need these ones explained, I've got no idea what they=20
  =
;&nbsp;&nbsp;&nbsp;&nbsp;=20
  x[j] =3D x[i]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  =
bsp;&nbsp;&nbsp;&nbsp;=20
  x[i] =3D temp&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp;=20
  =
/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
end=20
  if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end for</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>The brackets are simply pointing to a =
value in the=20
  sequence (or array).</STRONG></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>If we have a sequence composed of five =
elements,=20
  called janitor:</STRONG></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; janitor =3D { 1 , "B" , =
{ 1 , "CB"=20
  } , xray , "plunk" }</FONT></STRONG></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>then element 5, accessed&nbsp;as=20
  follows:</STRONG></FONT></DIV>
  <DIV><FONT size=3D2><STRONG></STRONG></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>&nbsp;&nbsp;&nbsp; vVar =3D=20
  janitor[5]</STRONG></FONT></DIV>
  <DIV><FONT size=3D2><STRONG></STRONG></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>vVar would be =
"plunk".</STRONG></FONT></DIV>
  <DIV><FONT face=3DArial size=3D2><BR>&nbsp;&nbsp;&nbsp; return =
x&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; -- whats return do?</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2><STRONG>Returns the value to the calling program, =
indicating=20
  that the function is done processing.</STRONG></FONT><FONT =
face=3DArial=20

------=_NextPart_000_0056_01C00397.A9E9F100--

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

4. Re: Myster Tour

------=_NextPart_000_0051_01C00389.D5AD9660
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Thomas

A function takes some code and puts it in a package so that it can be =
used many times within a program. Procedures do the same. The difference =
between functions and procedures is that you get a value back from a =
function, and you just do something with a procedure.

So in your example:
function simple_sort(sequence x)         =20
is, obviously the start of the function. The keyword "function" lets the =
system know that a function follows. The name simple_sort gives the name =
of the function and the stuff in brackets is the data that you want the =
function to work with. This data is generally called a parameter, or =
parameters if there are more than one. The sequence keyword says =
declares what kind of data the parameter is, and the x is the name of =
the data for use within the function.

Mud, right?

Maybe it clarifies a bit when you see how to use it.

Say you have a sequence with some data in it:
a=3D{1,3,2,3,6,5} that you want to sort into numerical order.

If you want to use the function simple_sort you just do this

sequence a, b
a=3D{1,3,2,3,6,5}=20
b=3Dsimple_sort(a) -- this is a function call - a goes to simple_sort =
and b recieves the sorted data returned by simple_sort.
A function call says (in polite English) please put the result of the =
sort operation done on "a" into "b"

Notice that the data that you send is called "a" from the calling =
program, but is called "x" within the function. That's because "X" is a =
local variable, that only exists for the time that the function is =
actually processing your data, and then disappears again.

The "return" that you asked about is just the command that tells the =
function what data to send back to the calling program.

The main difference between a function and a procedure is that the =
procedure doesn't have the "return". A procedure looks like a simple =
command, because it doesn't need to recieve a value back.

In polite english, a procedure just says - Please do something. Say you =
want to draw a dot on the screen. You make a procedure called Makedot. =
Makedot needs to know where on the screen, and what colour to use, so it =
needs to have 3 atoms as the parameters.=20

procedure Makedot(atom xposition, atom yposition, atom colour)
    pixel(colour, {xposition, yposition})
end procedure

See? - no return

To call it you just write

Makedot(100, 100, 5)

No recieving variable, and no equals sign - just an instruction to do =
something.

You ask:=20
"for i =3D 1 to length(x) + 1 do                -- is length(x) the =
legnth of simple_sort? if so, why not just for i=3D1 to =
length(simple_sort)"
A couple of points here:
Length is a function - you need to pass it data, which is contained in =
the sequence x. So "lenght(x)" is requesting the length of the data =
sequence x. simple_sort isn't data - it's a function. I'm not sure if =
it's useful for you to know how big the function is when you want to =
know the length of the data sequence that you passed to it.

But notice that there is no variable recieves the value returned by the =
function length - the value just gets plugged into the upper limit of =
your loop.=20

Say I have a function that doubles a number:

function dub(atom a)
    return (a+a)
end function

I can call it like this

atom a, b
a=3D1
b=3Ddub(a)

Guess what the value of b is.

But say you wanted to multiply by 4. Then you could write:

b=3Ddub(a)+dub(a)

or you could write

b=3Ddub(dub(a))

Enough for now - I'll write about sequence subscripts later.

Bye
Martin



  ----- Original Message -----=20
  From: Paul Kerslake=20
  To: EUPHORIA at LISTSERV.MUOHIO.EDU=20
  Sent: Friday, August 11, 2000 10:34 AM
  Subject: Myster Tour


  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

  -- how does one use function? and what does simple_sort(sequence x) =
mean?=20
  object temp
      for i =3D 1 to length(x) + 1 do                -- is length(x) the =
legnth of simple_sort? if so, why not just for i=3D1 to =
length(simple_sort)
          for j =3D i + 1 to length(x) do
              if compare(x[j],x[i]) < 0 then     --    \
                  -- swap x[j], x[i]                    --     \
                  temp =3D x[j]                --                   ---- =
  I need these ones explained, I've got no idea what they mean
                  x[j] =3D x[i]                    --                /
                  x[i] =3D temp                --                /
              end if
          end for
      end for
      return x                        -- whats return do?
  end function

  Well, there's another batch of problems.........get it? Batch? =
heheheh..............erm...
  Thanks

  -Thomas   (Yes, it is right to those who asked!)

------=_NextPart_000_0051_01C00389.D5AD9660
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi Thomas</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>A function takes some code and puts it in a package =
so that it=20
can be used many times within a program. Procedures do the same. The =
difference=20
between functions and procedures is that you get a value back from a =
function,=20
and you just do something with a procedure.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>So in your example:</FONT></DIV>
<DIV><FONT size=3D2>function simple_sort(sequence=20
x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV><FONT size=3D2>is, obviously the start of the function. The keyword =

"function" lets the system know that a function follows. The name =
simple_sort=20
gives the name of the function and the stuff in brackets is the data =
that you=20
want the function to work with. This data is generally called a =
parameter, or=20
parameters if there are more than one. The sequence keyword says =
declares what=20
kind of data the parameter is, and the x is the name of the data for use =
within=20
the function.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Mud, right?</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Maybe it clarifies a bit when you see how to use=20
it.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Say you have a sequence with some data in =
it:</FONT></DIV>
<DIV><FONT size=3D2>a=3D{1,3,2,3,6,5} that you want to sort into =
numerical=20
order.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>If you want to use the function simple_sort you just =
do=20
this</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>sequence a, b</FONT></DIV>
<DIV><FONT size=3D2>a=3D{1,3,2,3,6,5} </FONT></DIV>
<DIV><FONT size=3D2>b=3Dsimple_sort(a) -- this is a function call - a =
goes to=20
simple_sort and b recieves the sorted data returned by =
simple_sort.</FONT></DIV>
<DIV><FONT size=3D2>A function call says (in polite English) please put =
the result=20
of the sort operation done on "a" into "b"</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Notice that the data that you send is called "a" =
from the=20
calling program, but is called "x" within the function. That's because =
"X" is a=20
local variable, that only exists for the time that the function is =
actually=20
processing your data, and then disappears again.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The "return" that you asked about is just the =
command that=20
tells the function what data to send back to the calling =
program.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>The main difference between a function and a =
procedure is that=20
the procedure doesn't have the "return". A procedure looks like a simple =

command, because it doesn't need to recieve a value back.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>In polite english, a procedure just says - Please do =

something. Say you want to draw a dot on the screen. You make a =
procedure called=20
Makedot. Makedot needs to know where on the screen, and what colour to =
use, so=20
it needs to have 3 atoms as the parameters. </FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>procedure Makedot(atom xposition, atom yposition, =
atom=20
colour)</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; pixel(colour, {xposition,=20
yposition})</FONT></DIV>
<DIV><FONT size=3D2>end procedure</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>See? - no return</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>To call it you just write</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Makedot(100, 100, 5)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>No recieving variable, and no equals sign - just an=20
instruction to do something.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>You ask: </FONT></DIV>
<DIV><FONT size=3D2>"for i =3D 1 to length(x) + 1 do&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- is length(x) =
the=20
legnth of simple_sort? if so, why not just for i=3D1 to=20
length(simple_sort)"</FONT></DIV>
<DIV><FONT size=3D2>A couple of points here:</FONT></DIV>
<DIV><FONT size=3D2>Length is a function - you need to pass it data, =
which is=20
contained in the sequence x. So "lenght(x)" is requesting the length of =
the data=20
sequence x. simple_sort isn't data - it's a function. I'm not sure if =
it's=20
useful for you to know how big the function is when you want to know the =
length=20
of the data sequence that you passed to it.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>But notice that there is no variable recieves the =
value=20
returned by the function length - the value just gets plugged into the =
upper=20
limit of your loop. </FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Say I have a function that doubles a =
number:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>function dub(atom a)</FONT></DIV>
<DIV><FONT size=3D2>&nbsp;&nbsp;&nbsp; return (a+a)</FONT></DIV>
<DIV><FONT size=3D2>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I can call it like this</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>atom a, b</FONT></DIV>
<DIV><FONT size=3D2>a=3D1</FONT></DIV>
<DIV><FONT size=3D2>b=3Ddub(a)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Guess what the value of b is.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>But say you wanted to multiply by 4. Then you could=20
write:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>b=3Ddub(a)+dub(a)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>or you could write</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>b=3Ddub(dub(a))</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Enough for now - I'll write about sequence =
subscripts=20
later.<BR></FONT></DIV>
<DIV><FONT size=3D2>Bye<BR>Martin<BR></DIV></FONT>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dpaulk at UNISERVE.COM href=3D"mailto:paulk at UNISERVE.COM">Paul =
Kerslake</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3DEUPHORIA at LISTSERV.MUOHIO.EDU=20
  =
</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, August 11, 2000 =
10:34=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Myster Tour</DIV>
  <DIV><BR></DIV>
  <DIV><FONT face=3DArial size=3D2>I think I've found out why I find =
programming so=20
  confusing. I understand the commands, the concepts of sequence and =
atom etc.=20
  It's those little numbers that get to me. Little numbers that palgue =
nearly=20
  all of the commands! Here's what I'm ranting about:</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>THIS IS THE "SIMPLE.EX" FILE IN THE=20
  TUTORUAL</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>-- how does&nbsp;one use function? =
and what does=20
  simple_sort(sequence x)&nbsp;mean? <BR>object =
temp<BR>&nbsp;&nbsp;&nbsp; for i=20
  =3D 1 to length(x) + 1 do&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; -- is length(x) the legnth of=20
  simple_sort? if so, why not just for i=3D1 to=20
  length(simple_sort)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for =
j =3D i +=20
  1 to length(x)=20
  =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
if=20
  compare(x[j],x[i]) &lt; 0 then&nbsp;&nbsp;&nbsp;&nbsp;=20
  =
  -- swap x[j], x[i]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  =
  temp =3D x[j]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp;=20
  =
  I&nbsp;need these ones explained, I've got no idea what they=20
  =
;&nbsp;&nbsp;&nbsp;&nbsp;=20
  x[j] =3D x[i]&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  =
bsp;&nbsp;&nbsp;&nbsp;=20
  x[i] =3D temp&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; --&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp;=20
  =
/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
end=20
  if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end =
for<BR>&nbsp;&nbsp;&nbsp;=20
  end for<BR>&nbsp;&nbsp;&nbsp; return x&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
  &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp; --=20
  whats return do?<BR>end function</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Well, there's another batch of=20
  problems.........get it? Batch? =
heheheh..............erm...</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>-Thomas&nbsp;&nbsp; (Yes, it is right =
to those=20

------=_NextPart_000_0051_01C00389.D5AD9660--

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

Search



Quick Links

User menu

Not signed in.

Misc Menu