Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,4 +1,5 @@
Demonstrate your language's ability for programs to execute code written in the language provided at runtime. Show us what kind of program fragments are permitted (e.g. expressions vs. statements), how you get values in and out (e.g. environments, arguments, return values), if applicable what lexical/static environment the program is evaluated in, and what facilities for restricting (e.g. sandboxes, resource limits) or customizing (e.g. debugging facilities) the execution.
Demonstrate your language's ability for programs to execute code written in the language provided at runtime.
Show us what kind of program fragments are permitted (e.g. expressions vs. statements), how you get values in and out (e.g. environments, arguments, return values), if applicable what lexical/static environment the program is evaluated in, and what facilities for restricting (e.g. sandboxes, resource limits) or customizing (e.g. debugging facilities) the execution.
You may not invoke a separate evaluator program, or invoke a compiler and then its output, unless the interface of that program, and the syntax and means of executing it, are considered part of your language/library/platform.

View file

@ -0,0 +1,35 @@
# procedure to call the Algol 68G evaluate procedure #
# the environment of the evaluation will be the caller's environment #
# with "code", "x" and "y" defined as the procedure parameters #
PROC ev = ( STRING code, INT x, INT y )STRING: evaluate( code );
BEGIN
INT i := 1;
INT j := 2;
REAL x := 4.2;
REAL y := 0.7164;
# evaluates "i + j" in the current environment #
print( ( evaluate( "i + j" ), newline ) );
# evaluates "x + y" in the environment of the procedure body of ev #
print( ( ev( "x + y", i, j ), newline ) );
# evaluates "x + y" in the current environment, so shows a different #
# result to the previous call #
print( ( evaluate( "x + y" ), newline ) );
# prints "code" because code is defined in the environment of the #
# call to evaluate (in ev) although it is not defined in this #
# environment #
print( ( ev( "code", 1, 2 ), newline ) );
# prints "code + codecode + code" - see above #
print( ( ev( "code + code", 1, 2 ), newline ) )
END
# if this next call was executed, a runtime error would occur as x and y #
# do not exist anymore #
# ;print( ( evaluate( "x + y" ), newline ) ) #

View file

@ -0,0 +1 @@
eval["length = 1234 feet + 2 inches"]

View file

@ -1,4 +1,4 @@
def context = new B inding()
def context = new Binding()
context.startYear = 2008
context.endYear = 2121
def years3 = new GroovyShell(context).evaluate('''

View file

@ -1,4 +1,4 @@
def years4 = new GroovyShell( new B inding(startYear: 2008, endYear: 2121) ).evaluate('''
def years4 = new GroovyShell( new Binding(startYear: 2008, endYear: 2121) ).evaluate('''
(startYear..endYear).findAll {
Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun"
}

View file

@ -1,4 +1,4 @@
def binding = new B inding(startYear: 2008, endYear: 2121)
def binding = new Binding(startYear: 2008, endYear: 2121)
new GroovyShell( binding ).evaluate('''
yearList = (startYear..endYear).findAll {
Date.parse("yyyy-MM-dd", "${it}-12-25").format("EEE") == "Sun"

View file

@ -0,0 +1,2 @@
f = load("return 42")
f() --> returns 42

View file

@ -0,0 +1,37 @@
function testEval
fprintf('Expressions:\n')
x = eval('5+10^2')
eval('y = (x-100).*[1 2 3]')
eval('z = strcat(''my'', '' string'')')
try
w eval(' = 45')
catch
fprintf('Runtime error: interpretation of w is a function\n\n')
end
% eval('v') = 5
% Invalid at compile-time as MATLAB interprets as using eval as a variable
fprintf('Other Statements:\n')
nl = sprintf('\n');
eval(['for k = 1:20' nl ...
'fprintf(''%.3f\n'', k)' nl ...
'if k == 3' nl ...
'break' nl ...
'end' nl ...
'end'])
true == eval('1')
try
true eval(' == 1')
catch
fprintf('Runtime error: interpretation of == 1 is of input to true\n\n')
end
fprintf('Programming on the fly:\n')
userIn = true;
codeBlock = '';
while userIn
userIn = input('Enter next line of code: ', 's');
codeBlock = [codeBlock nl userIn];
end
eval(codeBlock)
end

View file

@ -0,0 +1,3 @@
a: -5
b: 7
answer: do [abs a * b] ; => 35

View file

@ -1,12 +1,12 @@
/*REXX program to illustrate ability to execute code written at runtime.*/
numeric digits 10000000
/*REXX program illustrates ability to execute code entered at "runtime".*/
numeric digits 10000000 /*ten million digits should do it*/
bee=51
stuff='bee=min(-2,44); say 13*2 "[from inside the box."; abc=abs(bee)'
stuff= 'bee=min(-2,44); say 13*2 "[from inside the box.]"; abc=abs(bee)'
interpret stuff
say 'bee=' bee
say 'abc=' abc
say
/* [↓] now, we hear from da user*/
say 'enter an expression:'
pull expression
say
@ -16,7 +16,7 @@ interpret '?='expression
say
say 'length of result='length(?)
say ' left 50 bytes of result='left(?,50)'...'
say 'right 50 bytes of result=...'right(?,50)
say ' left 50 bytes of result='left(?,50)'···'
say 'right 50 bytes of result=···'right(?,50)
/*stick a fork in it, we're done.*/

View file

@ -0,0 +1,4 @@
$ a=42
$ b=a
$ eval "echo \$$b"
42