[REBOL] Contexts Re:(3)
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 [: - )]
[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 [: - )]
[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 At 06:33 PM 6/4/00 +0100, you wrote: Hi all, can anyone help me with this simple question about contexts Consider the following rebol program REBOL [ Title: "Test function definition" Date: 04-Jun-2000 File: %fx.r Purpose: "Test function definition" ] ; define fx fx: function [x] [] [ print x print do text-fx ] ; Main line text-fx: "x * x" x: 100 fx 2 fx 3 even though I have passed the variable x into the function fx, when I "do" the string text-fx it used the value of x from the main line. How do I get the do function to take the value of x passed into the function. (I'm sure someone has told me how to this previously but I cant remember the answer :-(( ) Cheers PHil ;- Elan [: - )]