[REBOL] webbanner.r help Re:(2)

2000-04-16 Thread norsepower

OK, so in the following function...

make-banner: func [/ad adnumber /local url img alt] [
set [url img alt] skip banner-db either ad [ 
adnumber - 1 * 6
][
random (length? banner-db) / 6
]   
rejoin [{a href="} url {"IMG SRC="} img {" ALT="} alt {" 
target"_blank"/a}]
]

...how does adnumber get its value and what is the purpose of the 
adnumber word?

you now have 18 entries in the
database, six records of length 3 each, and not 36 entries. But when 
you
call make-banner with the ad refinement, get
adnumber - 1 * 6

is 6 - 1 * 6 = 30. No wonder you get none.




[REBOL] webbanner.r help Re:(3)

2000-04-16 Thread icimjs

Hi Ryan,

you wrote:
OK, so in the following function...

make-banner: func [/ad adnumber /local url img alt] [
set [url img alt] skip banner-db either ad [ 
adnumber - 1 * 6
][
random (length? banner-db) / 6
]   
rejoin [{a href="} url {"IMG SRC="} img {" ALT="} alt {" 
target"_blank"/a}]
]

...how does adnumber get its value and what is the purpose of the 
adnumber word?


Function specification:

when you specify a refinement in a function - /ad - then you can associate
an argument with that refinement - adnumber. The make-banner function can
be called either without a refinement and without an argument, or with the
refinement /ad, in which case you must supply an argument for adnumber. The
argument adnumber is initialized to the value with which you call
make-banner, when you call make-banner with the /ad refinement:

make-banner ;- no refinement, no argument

make-banner/ad 6 ;- with refinement, with argument

The role of adnumber.

The function subtracts 1 from the adnumber and mutliplies the result with 3
(not 6 as in your example!).

The value 3 is the length of each record in the block. The adnumber which
is passed to make-banner is index of the first field of the record. Since
the function uses skip to locate the three fields it wants to use - url,
img alt - you must subtract 1 from the index. If the function is called
with the index 1, the first record in the block (consisting of three
fields) has to be displayed. The skip function will skip (adnumber = ) 1  *
3 (= record length) = 3 fields. That would position you at the second record. 
So you subtract 1 
(adnumber =) 1 - 1 * 3 (=record length)
1-1 * 3 = 0 * 3 = 0. You skip 0 fields and set [url img alt] will set the
three local variables to the first three fields in the block. The url word
will be set to the url of the site, the img will be set to the path of the
image that is to be displayed, and will set to the string which is
displayed while the image is being loaded, or continues to be displayed if
loading the image fails.

When you call make-banner/ad 2, you want to displaye the second record. 
2 - 1 * 3 = 1 * 3 = 3

The skip function will skip 3 fields and s

et will load the three local variables to the three fields beginning at the
fourth field, which is the url of the second Web site, followed the image
file's path, followed by the string that is displayed by the Web browser as
the alt string.

BTW, all arguments that precede any optional refinements are mandatory
arguments, arguments that follow refinements are associated with their
respective refinement, until another refinement is detected, or until the
/local word is detected which introduces words that are local to the function.

f: func [mandatory-arg-1 mandatory-arg-2 
/refinement refinement-arg
/local local-word] [ do-something-real-smart-here ]

This function may be called with two arguments

f arg-1 arg-2

or with two arguments, the refinement, and a third argument associated with
the refinement:

f/refinement mandator-arg-1 mandatatory-arg-2 refinement-arg

Hope this helps,


;- Elan  [: - )]




[REBOL] webbanner.r help Re:

2000-04-15 Thread icimjs

Hi Ryan,

you wrote:
Original (with three urls in the block)

adnumber - 1 * 3
random (length? banner-db) / 3
make-banner/ad 3]

My changes (with six urls in the block)

adnumber - 1 * 6
random (length? banner-db) / 6
make-banner/ad 6]


The 3 in adnumber - 1 * 3, that 3 does not stand for number of entries in
the database. It stands for the length of a database entry, i.e. each entry
in the database consists of three items:

   http://www.schonder.com  %/graphics/bannerads/schonder.gif
   "Papier-Schonder KG office supply and bookstore"


1. the url:  http://www.schonder.com  
2. the banner file: %/graphics/bannerads/schonder.gif
3. the accomapnying text: "Papier-Schonder KG office supply and bookstore"

You added 3 more companies, fine, you therefotr changed 3 to 6 in your call
to make-banner/ad 6, that's fine, but you now have 18 entries in the
database, six records of length 3 each, and not 36 entries. But when you
call make-banner with the ad refinement, get
adnumber - 1 * 6

is 6 - 1 * 6 = 30. No wonder you get none.




;- Elan  [: - )]