Hi, this might help you:

create-function: func [
    {create an interactively defined function}
] [
    func [x [any-type!]] load ask "What to do?: "
]

>>f: create-function
What to do?: x * x
>>f 4
== 16
>> probe :f
func [x [any-type!]][x * x]

(notice the Load instead of To-block)
Regards
    Ladislav

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 06, 2000 1:24 AM
Subject: [REBOL] Contexts Re:(2)


> Hi Elan,
>
> Yeah that works great ....
>
> however I want the user to be able to type in a string
containing the
> function .... which is then evaluated.
>
> I tried converting the string using to-block ....
>
> using text-fx: "x * x"  I got the message
>
> ** Script Error: * is not defined in this context.
> ** Where: x * x
>
>
> Cheers PHil
>
>
> REBOL [
>     Title: "Test function definition"
>     Date: 04-Jun-2000
>     File: %fx.r
>     Purpose: "Test function definition"
> ]
>
> ; define fx
> fx: function [x] []
> [
>     print x
>     bind block-fx 'x
>     print do block-fx
> ]
>
> ; Main line
> text-fx: "x * x"
>
> block-fx: to-block text-fx
>
> x: 100
>
> fx 2
> fx 3
>
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: 04 June 2000 22:14
> Subject: [REBOL] Contexts Re:
>
>
> > Hi PHil,
> >
> > I replaced text-fx by block-fx and bind block-fx to fx's local
context
> > before I do it:
> >
> > fx: function [x] [] [
> >     print x
> >     bind block-fx 'x
> >     print do block-fx
> > ]
> >
> > block-fx: [x * x]
> >
> > >> x: 100
> > == 100
> > >>
> > >> fx 2
> > 2
> > 4
> > >> fx 3
> > 3
> > 9
> >
> >
> > To the same thing with text-fx use:
> >
> >
> > fx: function [x] [] [
> >     print x
> >     block-fx: make block! text-fx
> >     bind block-fx 'REBOL
> >     bind block-fx 'x
> >     print do block-fx
> > ]
> >
> >
> > >> text-fx: "x * x"
> > == "x * x"
> > >> fx 3
> > 3
> > 9
> > >> fx 1
> > 1
> > 1
> > >> fx 2
> > 2
> > 4
> >
> > ;- Elan
> >
> >
> > ;- Elan >> [: - )]
> >
> >
>
>

Reply via email to