Hi Pete

Not sure exactly what you want, but here is a start.  Because you want the
arg of the factory function to become the name of an object, it is probably
best to require it to be a word.  The interpreter will then throw an error
if the arg is not a valid REBOL word before the function is called. This is
also consistent with your stated call syntax

>> logo-factory Logo1    ; the arg Logo1 is a word in this call, not a
string

We don't want the arg to be evaluated, so we need to quote it in the arg
list (there are other ways of accomplishing the goal, but this is a good
one).  The following function generates the named object and also shows how
to use the given arg in definitions local to the returned object.

>> logo-factory: func ['arg [word!]] [set arg make object! [name: arg]]
>> logo-factory logo1    ;note REBOL is case insensitive
>> probe logo1

make object! [
    name: 'logo1
]
>> logo1/name
== logo1
>> type? logo1/name
== word!

HTH
-Larry

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 17, 2000 8:36 AM
Subject: [REBOL] returning an object from a function, sort of


> hiall
>
> btw, I sent a message almost identical to this one from my home account
last
> night, and it isn't here. Is it because the list doesn't rec that other
account?
>
> anyway...
>
> I've got a function called logo-factory that accepts a string argument,
and
> should return an object referenced by a word = the passed string. ie., if
I type
>
> *logo-factory Logo1*
>
> I should get the same result as if I typed
>
> *Logo1: make object! [....]*
>
> I'm befuddled as to how to do this exactly -- I'm sure the answer is right
under
> my nose ;-)
>
> Here's sort of what I have so far:
>
> *
> logo-factory: func [
>     "Creates and returns a named logo object."
>     name [string!] "The name of the object to be created."
> ][
>     ????? make object! [
>         type: "text"
>         text: ""
>         pict: #{}
>         file: ""
>         altt: ""
>         switch-type: func [
>             "Toggles the logo object's type between 'text' and 'pict'."
>         ][
>             type: either type = "text" ["pict"]["text"]
>         ]
>     ]
> ]
> *
>
> Obviously, there's a lot missing here, like handling an argument string
which
> can't be used as a valid word, etc. Other functions like get-pict and
> write-html, etc., also need to be added.
>
> Any and all suggestions are welcome!
>
>
> --
> Pete Wason|"LWATPLOTG"|[EMAIL PROTECTED]|[EMAIL PROTECTED]|CUCUG|TA|PHX

Reply via email to