1. eval() function
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Nov 01, 2005
- 608 views
- Last edited Nov 02, 2005
After my unsuccessful attempt at using OOEU's eval() function, I thought I would write my own that will work with the normal rds download. But it won't work!
constant EVAL_FILE_NAME = "tmp_evalfile.ex" constant EVAL_ERROR = -1 global function eval(sequence data) integer tmp_fn, ret sequence plat tmp_fn = open(EVAL_FILE_NAME, "w") if tmp_fn = -1 then puts(1, "Could not opne temporary eval file ... Sorry!") return EVAL_ERROR end if puts(tmp_fn, data) if platform() = DOS32 then plat = "ex" elsif platform() = WIN32 then plat = "exw" elsif (platform() = LINUX) or (platform() = FREEBSD) then plat = "exu" end if puts(1, plat & " " & EVAL_FILE_NAME & " > eval.out") ret = system_exec(plat & " " & EVAL_FILE_NAME, 0) system("DELE " & EVAL_FILE_NAME, 0) return ret end function
Can somebody help me? Thanks, Alex P.S. Matt Lewis - Sorry I haven't emailed you any source that is not workin, but my PC is being wiped and I am using another so until I get it back and read off backups etc I can't get it to you.
2. Re: eval() function
- Posted by "Juergen Luethje" <j.lue at gmx.de> Nov 01, 2005
- 576 views
- Last edited Nov 02, 2005
Alex Chamberlain wrote: > After my unsuccessful attempt at using OOEU's eval() function, > I thought would write my own that will work with the normal rds > download. > But it won't work! > > }}} <eucode> > constant EVAL_FILE_NAME = "tmp_evalfile.ex" > constant EVAL_ERROR = -1 > > global function eval(sequence data) > integer tmp_fn, ret > sequence plat > > tmp_fn = open(EVAL_FILE_NAME, "w") > if tmp_fn = -1 then > puts(1, "Could not opne temporary eval file ... Sorry!") > return EVAL_ERROR > end if > > puts(tmp_fn, data) > > if platform() = DOS32 then > plat = "ex" > elsif platform() = WIN32 then > plat = "exw" > elsif (platform() = LINUX) or (platform() = FREEBSD) then > plat = "exu" > end if > puts(1, plat & " " & EVAL_FILE_NAME & " > eval.out") > ret = system_exec(plat & " " & EVAL_FILE_NAME, 0) > system("DELE " & EVAL_FILE_NAME, 0) > return ret > end function > </eucode> {{{ > > Can somebody help me? When I try to run that program, I get the following error message: DOS32 has not been declared if platform() = DOS32 then ^ So at least you should write at the beginning of the program: include misc.e Also when you have opened a file, don't forget to close it! And you have mixed up some things. Besides the missing 'include' statement, the program can not work, because you are redirecting the wrong command, you never read the output of the temporary program, and the function returns the wrong value. Additionally it looks to me that system_exec() can not be used for output redirection. But redirecting the output is not necessary at all here. Make a clear concept, you need 4 steps: a) write a temporary program for evaluating the expression and writing the result to another temporary file b) run the temporary program (and delete the program file) c) read the content of the temporary result file, and convert it to a number (and delete the file) d) return this number (do *not* return the return value of system_exec()!) Now you have important hints. I'll not give you the complete program at the moment. Trying yourself is more fun! Regards, Juergen -- Have you read a good program lately?
3. Re: eval() function
- Posted by "Juergen Luethje" <j.lue at gmx.de> Nov 02, 2005
- 586 views
Me wrote: > Alex Chamberlain wrote: > >> After my unsuccessful attempt at using OOEU's eval() function, >> I thought would write my own that will work with the normal rds >> download. >> But it won't work! >> >> }}} <eucode> >> constant EVAL_FILE_NAME = "tmp_evalfile.ex" >> constant EVAL_ERROR = -1 >> >> global function eval(sequence data) >> integer tmp_fn, ret >> sequence plat >> >> tmp_fn = open(EVAL_FILE_NAME, "w") >> if tmp_fn = -1 then >> puts(1, "Could not opne temporary eval file ... Sorry!") >> return EVAL_ERROR >> end if >> >> puts(tmp_fn, data) >> >> if platform() = DOS32 then >> plat = "ex" >> elsif platform() = WIN32 then >> plat = "exw" >> elsif (platform() = LINUX) or (platform() = FREEBSD) then >> plat = "exu" >> end if >> puts(1, plat & " " & EVAL_FILE_NAME & " > eval.out") >> ret = system_exec(plat & " " & EVAL_FILE_NAME, 0) >> system("DELE " & EVAL_FILE_NAME, 0) >> return ret >> end function >> </eucode> {{{ >> >> Can somebody help me? > > > When I try to run that program, I get the following error message: > DOS32 has not been declared > if platform() = DOS32 then > ^ > So at least you should write at the beginning of the program: > include misc.e > > Also when you have opened a file, don't forget to close it! > > And you have mixed up some things. > Besides the missing 'include' statement, the program can not work, > because you are redirecting the wrong command, you never read the output > of the temporary program, and the function returns the wrong value. > Additionally it looks to me that system_exec() can not be used for > output redirection. But redirecting the output is not necessary at all > here. > > Make a clear concept, you need 4 steps: > a) write a temporary program for evaluating the expression and writing > the result to another temporary file > b) run the temporary program (and delete the program file) > c) read the content of the temporary result file, and convert it to > a number (and delete the file) > d) return this number (do *not* return the return value of > system_exec()!) > > Now you have important hints. I'll not give you the complete program at > the moment. Trying yourself is more fun! Here comes the second part of my reply, firstly some more remarks: It is often useful to write a function like this in a way, so that it is as versatile as possible, and useful for different types of programs. Now imagine a program with a nice looking GUI, and then a black console window pops up with the message: "Could not open temporary eval file ... Sorry!" Since this would look ugly, a versatile library function should not output such messages itself, but return a specific error code, and let the main program display the appropriate message (see code below). Your function returns -1 to indicate an error. But -1 can also be a valid result of the function, e.g. eval("-2*0.5") => -1. When eval() returns -1, how can the main program know whether this special -1 is a valid result or an error flag? Answer: It cannot! We must return error flags in a different way. From the top of my head three possibilities come to my mind: 1) Always return a sequence of 2 elements, where the first element is a special flag, and the second element is the desired value, in case there is no error. This way is used e.g. by the Euphoria functions get() (see below) and value(). 2) Always return an atom, and use a separate local or global error variable, which is set by eval() e.g. atom result integer error result = eval("1+1") if error then puts(1, "Can't calculate that.\n") else printf(1, "Result: %g\n", {result}) end if This is not working code, but I hope you'll get the idea. 3) Always return an atom for a valid result, and a sequence in case of an error (or vice versa, like gets() does). This method is used in the code below. In your code you used "DELE", I don't know that. On DOS and Windows it must be "DEL". If "DELE" is not a typo, but a valid Linux/FreeBSD command, you must change the code of the function, so that it uses the proper command according to the current platform. Like you did, I use 2 files. But my files both have the same extension, so I only need 1 command to delete them. This command is deliberately commented out currently. After running the code, you should look at the contents of the file "eval_prg.tmp". Then you probably will see what's going on.
include misc.e include get.e constant EVAL_PROG_NAME = "eval_prg.tmp", EVAL_RES_NAME = "eval_res.tmp", EVAL_WRITE_ERR = {1}, EVAL_READ_ERR = {2} global function eval (sequence expression) sequence plat, ret integer fn, sys -- write a temporary program for evaluating the expression and -- writing the result to another temporary file fn = open(EVAL_PROG_NAME, "w") if fn = -1 then return EVAL_WRITE_ERR end if printf(fn, "integer fn\n" & "fn = open(\"%s\", \"w\")\n" & "print(fn, %s)\n" & "close(fn)\n", {EVAL_RES_NAME, expression}) close(fn) -- run the temporary program if platform() = DOS32 then plat = "ex" elsif platform() = WIN32 then plat = "exw" elsif (platform() = LINUX) or (platform() = FREEBSD) then plat = "exu" end if sys = system_exec(plat & " " & EVAL_PROG_NAME, 0) -- read the content of the temporary result file, -- and convert it to a number fn = open(EVAL_RES_NAME, "r") if fn = -1 then return EVAL_READ_ERR end if ret = get(fn) close(fn) -- delete temporary files -- system("DEL *.tmp", 0) -- return the number from the temporary result file if ret[1] = GET_SUCCESS then return ret[2] else return EVAL_READ_ERR end if end function -- Demo object result sequence expression expression = "3*2.5" -- expression = "power(4,2)" result = eval(expression) if atom(result) then printf(1, "%s = %g\n", {expression, result}) elsif equal(result, EVAL_WRITE_ERR) then puts(1, "Could not write eval program ... Sorry!") elsif equal(result, EVAL_READ_ERR) then puts(1, "Could not read eval result ... Sorry!") end if puts(1, "\nPress Enter to continue ...") if getc(0) then end if
If you still have questions, just let us know. Regards, Juergen -- Have you read a good program lately?
4. Re: eval() function
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Nov 02, 2005
- 596 views
- Last edited Nov 03, 2005
Thanks Juergen - amazing mind! I don't think I made it clear that I need the script to evaluate full Euphoria programs! I have adapted your script to run it my way. --eval.e
include misc.e global constant EVAL_PROG_NAME = "eval_prg.tmp", EVAL_RES_NAME = "eval_res.tmp", EVAL_ERR_RET = -1, EVAL_WRITE_ERR = 1, EVAL_READ_ERR = 2 global integer EVAL_ERROR EVAL_ERROR = 0 global function eval (sequence script) sequence plat, ret integer tmp_fn -- , sys object line -- write a temporary program for evaluating the expression and -- writing the result to another temporary file tmp_fn = open(EVAL_PROG_NAME, "w") if tmp_fn = -1 then EVAL_ERROR = EVAL_WRITE_ERR return EVAL_ERR_RET end if puts(tmp_fn, script) close(tmp_fn) -- run the temporary program if platform() = DOS32 then plat = "ex" elsif platform() = WIN32 then plat = "exw" elsif (platform() = LINUX) or (platform() = FREEBSD) then plat = "exu" end if system(plat & " " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME, 0) -- read the content of the temporary result file, -- and convert it to a number tmp_fn = open(EVAL_RES_NAME, "r") if tmp_fn = -1 then EVAL_ERROR = EVAL_READ_ERR return EVAL_ERR_RET end if ret = {} while 1 do line = gets(tmp_fn) if atom(line) then exit end if ret &= line end while close(tmp_fn) -- delete temporary files system("DEL *.tmp", 0) return ret end function
--demo.ex
include eval.e include get.e sequence script object ret -- Define the script contents - any Euphoria code! script = "puts(1, \"This is this result of the demo eval script!\")" procedure handleReturn(object ret) puts(1, "The script output the following:\n" & ret) end procedure ret = eval(script) if atom(ret) then if EVAL_ERROR = 0 then handleReturn(ret) elsif EVAL_ERROR = EVAL_WRITE_ERR then puts(1, "Sorry, there was a write error whilst evaluating the script") elsif EVAL_ERROR = EVAL_READ_ERR then puts(1, "Sorry, there was a read error whilst evaluating the script") end if else handleReturn(ret) end if abort(wait_key()*0)
The only problem is that the Windows program doesn't like redirecting its input (can others please try it!) and it hasn't been run on Linux/FreeBSD yet. It work on DOS fine so there you go. On the web very soon, and is running up to my CGI interpretor. Thanks, Alex
5. Re: eval() function
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Nov 03, 2005
- 602 views
Does system() normally work to redirect output, for a Euphoria program, on Linux? Also, does it matter what the integer is as the second parameter? Thanks, Alex
6. Re: eval() function
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 03, 2005
- 583 views
- Last edited Nov 04, 2005
Alex Chamberlain wrote: > Does system() normally work to redirect output, > for a Euphoria program, on Linux? Yes, your system command can redirect output of a program to standard out, or standard error. > Also, does it matter what the integer is as the second parameter? On Linux, you should normally use 2. 0 and 1 are intended mainly for DOS graphics modes. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
7. Re: eval() function
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 03, 2005
- 576 views
- Last edited Nov 04, 2005
Robert Craig wrote: > Alex Chamberlain wrote: > > Does system() normally work to redirect output, > > for a Euphoria program, on Linux? > > Yes, your system command can redirect output of a program > to standard out, or standard error. I didn't say that very well. I should have said that a system command can redirect the standard output or standard error output (or standard input) of a program, even a Euphoria program. Here's a Linux example that does all 3:
system("mail < mail_commands > headers 2> /dev/null", 2)
I've never figured out how to redirect standard error on DOS or Windows. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
8. Re: eval() function
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Nov 03, 2005
- 573 views
- Last edited Nov 04, 2005
The problem I am now having in my server error logs is 'exu command not found' and 'DEL command not found'. Has anyone come across these before? Thanks, Alex
9. Re: eval() function
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 04, 2005
- 573 views
Alex Chamberlain wrote: > The problem I am now having in my server error logs is 'exu command not found' > and 'DEL command not found'. > Has anyone come across these before? On a Linux system, DEL doesn't exist. Use rm instead. Your CGI programs are not run under your user id. They are run by a system process that has a different user id and knows nothing about your EUDIR or PATH variables. You might have to place a copy of exu in your cgi-bin directory, or give the full absolute path to exu on your #! line. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
10. Re: eval() function
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Nov 04, 2005
- 580 views
Ok so I have sorted out the DEL, that was easy (Thanks Rob)! What about the exu it's in the cgi-bin? Thanks, Alex
11. Re: eval() function
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 04, 2005
- 582 views
Alex Chamberlain wrote: > Ok so I have sorted out the DEL, that was easy (Thanks Rob)! What about the > exu it's in the cgi-bin? Linux doesn't normally search in the current directory, so you probably need: #!./exu rather than #!exu Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com
12. Re: eval() function
- Posted by "Juergen Luethje" <j.lue at gmx.de> Nov 06, 2005
- 573 views
Hi Alex, sorry for the delay in replying, it took some time until I had a new idea. You wrote: > Thanks Juergen - amazing mind! I don't think I made it clear that > I need the script to evaluate full Euphoria programs! > I have adapted your script to run it my way. I see now, cool! [snipped the code] > The only problem is that the Windows program doesn't like redirecting > its input (can others please try it!) and it hasn't been run on > Linux/FreeBSD yet. It work on DOS fine so there you go. On the web very > soon, and is running up to my CGI interpretor. The problem on Windows seems to be, that the program now uses system() instead of system_exec(). However, I think it actually must do so, because system_exec() can't be used for redirection of output. But the disadvantage of system() is here, that -- at least on Windows -- the Eu program *does not wait* until system() has finished its work. So in function eval(), the program tries to read the contens of the file EVAL_RES_NAME, before they are (completely) written to the file!! My idea now is, that the *last lines* of the temporary program additionally create another temporary file, which is used as a flag. And in function eval() we add some code for waiting, until this file exists. If it exists, we know that system() has finished its work, all output is redirected, and we can continue with the main program. Also in the meantime we have learned from Rob, that on Linux it must be "rm" rather than "del". So here comes my current version of the program, which runs fine on DOS and Windows 98:
-----------------[ demo.ex ]----------------- include misc.e include file.e global constant EVAL_PROG_NAME = "eval_prg.tmp", EVAL_RES_NAME = "eval_res.tmp", FLAG_FILE_NAME = "eval_flg.tmp", EVAL_ERR_RET = -1, EVAL_WRITE_ERR = 1, EVAL_READ_ERR = 2 global integer EVAL_ERROR EVAL_ERROR = 0 global function eval (sequence script) sequence plat, del, ret integer tmp_fn object line -- write a temporary program for evaluating the script, -- and for creating a "flag" file tmp_fn = open(EVAL_PROG_NAME, "w") if tmp_fn = -1 then EVAL_ERROR = EVAL_WRITE_ERR return EVAL_ERR_RET end if puts(tmp_fn, script) puts(tmp_fn, "\n\ninteger fn\n" & "fn = open(\"" & FLAG_FILE_NAME & "\", \"w\")\n" & "print(fn,123)\n" & "close(fn)\n") close(tmp_fn) -- run the temporary program, -- and wait until it has finished! if platform() = DOS32 then plat = "ex" del = "del" elsif platform() = WIN32 then plat = "exw" del = "del" elsif (platform() = LINUX) or (platform() = FREEBSD) then plat = "exu" del = "rm" end if system(plat & " " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME, 2) while atom(dir(FLAG_FILE_NAME)) do end while -- read the content of the temporary result file tmp_fn = open(EVAL_RES_NAME, "r") if tmp_fn = -1 then EVAL_ERROR = EVAL_READ_ERR return EVAL_ERR_RET end if ret = {} while 1 do line = gets(tmp_fn) if atom(line) then exit end if ret &= line end while close(tmp_fn) -- delete temporary files system(del & " *.tmp", 2) return ret end function ---------------------------------------------
-----------------[ demo.ex ]----------------- include eval.e include get.e sequence script object ret -- Define the script contents - any Euphoria code! script = "puts(1, \"This is the result of the demo eval script!\")" procedure handleReturn(object ret) puts(1, "The script output the following:\n" & ret) end procedure ret = eval(script) if atom(ret) then if EVAL_ERROR = 0 then handleReturn(ret) elsif EVAL_ERROR = EVAL_WRITE_ERR then puts(1, "Sorry, there was a write error whilst evaluating the script") elsif EVAL_ERROR = EVAL_READ_ERR then puts(1, "Sorry, there was a read error whilst evaluating the script") end if else handleReturn(ret) end if abort(wait_key()*0) ---------------------------------------------
Working on this actually is fun. Regards, Juergen -- Have you read a good program lately?
13. Re: eval() function
- Posted by Alex Chamberlain <alex.chamberlain at tiscali.co.uk> Nov 06, 2005
- 571 views
- Last edited Nov 07, 2005
Ok here's my reply... --eval.e
include misc.e include file.e global constant EVAL_RAND_NUM = sprint(rand(999999)), EVAL_PROG_NAME = "eval_prg" & EVAL_RAND_NUM & ".tmp", EVAL_RES_NAME = "eval_res" & EVAL_RAND_NUM & ".tmp", EVAL_FLAG_NAME = "eval_flag" & EVAL_RAND_NUM & ".tmp", -- EVAL_BATCH_NAME = "eval_batch" & EVAL_RAND_NUM & ".bat", EVAL_ERR_RET = -1, EVAL_WRITE_ERR = 1, EVAL_READ_ERR = 2, EVAL_BATCH_ERR = 3 global integer EVAL_ERROR EVAL_ERROR = 0 global function eval (sequence script) sequence plat, ret, del integer tmp_fn object line, eu -- write a temporary program for evaluating the expression and -- writing the result to another temporary file tmp_fn = open(EVAL_PROG_NAME, "w") if tmp_fn = -1 then EVAL_ERROR = EVAL_WRITE_ERR return EVAL_ERR_RET end if -- puts(tmp_fn, "include get.e\n") puts(tmp_fn, script) puts(tmp_fn, "\n\ninteger eval_flag_fn\n" & "eval_flag_fn = open(\"" & EVAL_FLAG_NAME & "\", \"w\")\n" & "print(eval_flag_fn, 123)\n" & "close(eval_flag_fn)\n" -- & "abort(wait_key()*0)" ) close(tmp_fn) -- run the temporary program if platform() = DOS32 then plat = "ex" del = "DEL" elsif platform() = WIN32 then plat = "exwc" del = "DEL" elsif (platform() = LINUX) or (platform() = FREEBSD) then plat = "exu" del = "rm" end if eu = getenv("EUDIR") if equal(plat, "exu") and atom(eu) then system("./" & plat & " " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME, 2) -- elsif equal(plat, "exw") then -- tmp_fn = open(EVAL_BATCH_NAME, "w") -- if tmp_fn = -1 then -- EVAL_ERROR = EVAL_BATCH_ERR -- return EVAL_ERR_RET -- end if -- -- puts(tmp_fn, "@echo off\n") -- puts(tmp_fn, "exw " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME) -- -- close(tmp_fn) -- -- system(EVAL_BATCH_NAME, 2) else system(plat & " " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME, 2) end if while atom(dir(EVAL_FLAG_NAME)) do end while -- read the content of the temporary result file, -- and convert it to a number tmp_fn = open(EVAL_RES_NAME, "r") if tmp_fn = -1 then EVAL_ERROR = EVAL_READ_ERR return EVAL_ERR_RET end if ret = {} while 1 do line = gets(tmp_fn) if atom(line) then exit end if ret &= line end while close(tmp_fn) system(del & " *" & EVAL_RAND_NUM & ".tmp", 2) -- if equal(plat, "exw") then -- system("DEL " & EVAL_BATCH_NAME, 2) -- end if return ret end function
The demo remains unchange, but what has changed about eval.e? Well now the eval.e can be used by multiple scripts, or the same script running multiple times, at the same time as a random number is added to the file name. On Windows XP, redirection was not working. exw is not a console program, so I replaced the command to exwc (I even tried a batch file - code included)! And it works on Linux if exu is installed in the same directory instead of EUDIR. This idea of working together on the same script, even though its only two or three of us, is what I want to get over with my new website at euphoria.yourpixels.co.uk (I own yourpixels.co.uk). Please visit but do understand it is far off completion! Thanks, Alex
14. Re: eval() function
- Posted by Vincent <darkvincentdude at yahoo.com> Nov 06, 2005
- 555 views
- Last edited Nov 07, 2005
Alex Chamberlain wrote: > > Ok here's my reply... > > --eval.e > }}} <eucode> > include misc.e > include file.e > > global constant > EVAL_RAND_NUM = sprint(rand(999999)), > EVAL_PROG_NAME = "eval_prg" & EVAL_RAND_NUM & ".tmp", > EVAL_RES_NAME = "eval_res" & EVAL_RAND_NUM & ".tmp", > EVAL_FLAG_NAME = "eval_flag" & EVAL_RAND_NUM & ".tmp", > -- EVAL_BATCH_NAME = "eval_batch" & EVAL_RAND_NUM & ".bat", > EVAL_ERR_RET = -1, > EVAL_WRITE_ERR = 1, > EVAL_READ_ERR = 2, > EVAL_BATCH_ERR = 3 > > global integer EVAL_ERROR > > EVAL_ERROR = 0 > > global function eval (sequence script) > sequence plat, ret, del > integer tmp_fn > object line, eu > > -- write a temporary program for evaluating the expression and > -- writing the result to another temporary file > tmp_fn = open(EVAL_PROG_NAME, "w") > if tmp_fn = -1 then > EVAL_ERROR = EVAL_WRITE_ERR > return EVAL_ERR_RET > end if > > -- puts(tmp_fn, "include get.e\n") > puts(tmp_fn, script) > puts(tmp_fn, "\n\ninteger eval_flag_fn\n" > & "eval_flag_fn = open(\"" & EVAL_FLAG_NAME & "\", \"w\")\n" > & "print(eval_flag_fn, 123)\n" > & "close(eval_flag_fn)\n" > -- & "abort(wait_key()*0)" > ) > close(tmp_fn) > > -- run the temporary program > if platform() = DOS32 then > plat = "ex" > del = "DEL" > elsif platform() = WIN32 then > plat = "exwc" > del = "DEL" > elsif (platform() = LINUX) or (platform() = FREEBSD) then > plat = "exu" > del = "rm" > end if > > eu = getenv("EUDIR") > > if equal(plat, "exu") and atom(eu) then > system("./" & plat & " " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME, 2) > -- elsif equal(plat, "exw") then > -- tmp_fn = open(EVAL_BATCH_NAME, "w") > -- if tmp_fn = -1 then > -- EVAL_ERROR = EVAL_BATCH_ERR > -- return EVAL_ERR_RET > -- end if > -- > -- puts(tmp_fn, "@echo off\n") > -- puts(tmp_fn, "exw " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME) > -- > -- close(tmp_fn) > -- > -- system(EVAL_BATCH_NAME, 2) > else > system(plat & " " & EVAL_PROG_NAME & " > " & EVAL_RES_NAME, 2) > end if > > while atom(dir(EVAL_FLAG_NAME)) do > end while > > -- read the content of the temporary result file, > -- and convert it to a number > tmp_fn = open(EVAL_RES_NAME, "r") > if tmp_fn = -1 then > EVAL_ERROR = EVAL_READ_ERR > return EVAL_ERR_RET > end if > > ret = {} > while 1 do > line = gets(tmp_fn) > if atom(line) then > exit > end if > ret &= line > end while > close(tmp_fn) > > system(del & " *" & EVAL_RAND_NUM & ".tmp", 2) > > -- if equal(plat, "exw") then > -- system("DEL " & EVAL_BATCH_NAME, 2) > -- end if > > return ret > end function > </eucode> {{{ > > The demo remains unchange, but what has changed about eval.e? Well now the > eval.e > can be used by multiple scripts, or the same script running multiple times, > at the same time as a random number is added to the file name. On Windows XP, > redirection was not working. exw is not a console program, so I replaced the > command to exwc (I even tried a batch file - code included)! And it works on > Linux if exu is installed in the same directory instead of EUDIR. > > This idea of working together on the same script, even though its only two or > three of us, is what I want to get over with my new website at > euphoria.yourpixels.co.uk > (I own yourpixels.co.uk). Please visit but do understand it is far off > completion! <snip> Expression evaluation could be useful, you should post this on the archive. It looks like it works simular to my dynamic inclusion system, though mine has a sophisticated scanning system. Among other goodies, I plan to release another major update to it very soon that adds support for nested dynamic & conditional including, and automatic current file detection. In addition it will have an improvement with the scanning system, another example program, and slightly better documentation. Regards, Vincent
15. Re: eval() function
- Posted by cklester <cklester at yahoo.com> Nov 07, 2005
- 562 views
Alex Chamberlain wrote: > > This idea of working together on the same script, even though its only two or > three of us, is what I want to get over with my new website at > euphoria.yourpixels.co.uk > (I own yourpixels.co.uk). Please visit but do understand it is far off > completion! Alex, how are you getting the Euphoria code to run from the HTML? Have you instructed the HTML server to run Euphoria when it encounters a certain tag or what? Just curious, as my web sites are served by Euphoria as well, and I also call my programs Euphoria Server Pages (ESP)! :) -=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/