Talk:Runtime evaluation: Difference between revisions

From Rosetta Code
Content added Content deleted
(invocation not evaluation)
Line 54: Line 54:


:Er, what? --[[User:Ledrug|Ledrug]] 19:22, 19 July 2011 (UTC)
:Er, what? --[[User:Ledrug|Ledrug]] 19:22, 19 July 2011 (UTC)

The task description states "Demonstrate your language's ability for programs to execute other programs in the language provided". That is "invocation" of another program, not "evaluation" of an expression. Looking through the solutions given, it looks like some solutions are about expressions and not about execution of another program, although I am not familiar with every language, so maybe I am misinterpreting the code given. [[User:Markhobley|Markhobley]] 19:53, 19 July 2011 (UTC)

Revision as of 19:53, 19 July 2011

Documenting calls

Note that you can add links to online documentation for functions/statements used, but in this case it should be easy to find the items used in the example, and links should be to an authoritative source such as documentation maintained by the language maintainers. I used this to shorten the Python entry. --Paddy3118 18:47, 3 June 2009 (UTC)

All facilities?

I've only shown off some of Tcl's capabilities in this area. Documenting them all would bulk out this page rather a lot, even with all the other language examples. Hopefully there's enough there to be interesting anyway… —Donal Fellows 20:51, 3 June 2009 (UTC)

If you want to do more, you can create the page Eval/Tcl and link to it under the header on the main task page. This has been done before, but before we had support for slashes Polymorphism#BASIC. --Mwn3d 20:54, 3 June 2009 (UTC)
More work than I feel like tonight. :-) I'll focus on just making sure that the task itself is done for now; the fancy stuff is probably better done as another (probably pretty major) task. —Donal Fellows 23:09, 3 June 2009 (UTC)

Joke solution for C

Requires gdb; eval expressions as you'd type in gdb prompt; code must be compiled with -g flag and without -O. <lang C>#include <stdio.h>

  1. include <sys/types.h>
  2. include <unistd.h>
  3. include <err.h>

char spid[100], pname[1024];

  1. define EVAL(a) call_gdb(a, __LINE__ + 1)

void call_gdb(char * command, int lineno) { if (fork()) { while (1); return; }

FILE *fp = fopen("cmds", "w"); fprintf(fp, "attach %s\nb %d\nret\n%s\n", spid, lineno, command); fclose(fp);

freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr);

execlp("gdb", pname, spid, "-x", "cmds", "-batch", "-q", 0); err(1, "Exec failure %s %s", pname, spid); }

int main(int argc, char **argv) { int a = 0, b = 1, c = 2; sprintf(spid, "%ld", (unsigned long) getpid()); sprintf(pname, "%s", argv[0]);

printf("before eval: a = %d\n", a); EVAL("set variable a = b + c"); printf("after eval: a = %d\n", a);

wait(0); return 0; }</lang>

Maybe we should rename this. It looks like many of the solutions are about evaluation of an expression at runtime, rather than invocation of another program. This is probably because we have used the term "evaluation" in the title. Maybe this would be better named as "Invoke another program". Markhobley 18:59, 19 July 2011 (UTC)

Er, what? --Ledrug 19:22, 19 July 2011 (UTC)

The task description states "Demonstrate your language's ability for programs to execute other programs in the language provided". That is "invocation" of another program, not "evaluation" of an expression. Looking through the solutions given, it looks like some solutions are about expressions and not about execution of another program, although I am not familiar with every language, so maybe I am misinterpreting the code given. Markhobley 19:53, 19 July 2011 (UTC)