September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,25 +1,24 @@
#import system.
#import system'dynamic.
#import extensions.
import system'dynamic.
import extensions.
#class TestClass
class TestClass
{
#field theVariables.
object theVariables.
#constructor new
constructor new
[
theVariables := DynamicStruct new.
]
#method eval
eval
[
#var(type:subject) varRef := Signature new &literal:(console write:"Enter the variable name:" readLine).
theVariables::varRef set:42.
subject varRef := Signature new literal:(console write:"Enter the variable name:"; readLine).
theVariables~varRef set:42.
#var v := theVariables::varRef get.
var v := theVariables~varRef get.
console writeLine:(varRef name):"=":(theVariables::varRef get).
console printLine(varRef literal,"=",theVariables~varRef get); readChar.
]
}
#symbol program = TestClass new.
program = TestClass new.

View file

@ -0,0 +1,4 @@
"Enter a variable name:",
(input as $var
| ("Enter a value:" ,
(input as $value | { ($var) : $value })))

View file

@ -0,0 +1,41 @@
// version 1.1.4
fun main(args: Array<String>) {
var n: Int
do {
print("How many integer variables do you want to create (max 5) : ")
n = readLine()!!.toInt()
}
while (n < 1 || n > 5)
val map = mutableMapOf<String, Int>()
var name: String
var value: Int
var i = 1
println("OK, enter the variable names and their values, below")
do {
println("\n Variable $i")
print(" Name : ")
name = readLine()!!
if (map.containsKey(name)) {
println(" Sorry, you've already created a variable of that name, try again")
continue
}
print(" Value : ")
value = readLine()!!.toInt()
map.put(name, value)
i++
}
while (i <= n)
println("\nEnter q to quit")
var v: Int?
while (true) {
print("\nWhich variable do you want to inspect : ")
name = readLine()!!
if (name.toLowerCase() == "q") return
v = map[name]
if (v == null) println("Sorry there's no variable of that name, try again")
else println("It's value is $v")
}
}

View file

@ -0,0 +1,17 @@
import tables
var
theVar: int = 5
varMap = initTable[string, pointer]()
proc ptrToInt(p: pointer): int =
result = cast[ptr int](p)[]
proc main() =
write(stdout, "Enter a var name: ")
let sVar = readLine(stdin)
varMap.add($svar, theVar.addr)
echo "Variable ", sVar, " is ", ptrToInt(varMap[$sVar])
when isMainModule:
main()

View file

@ -1,3 +1,11 @@
my $vname = prompt 'Variable name: ';
$GLOBAL::($vname) = 42;
say $GLOBAL::($vname);
our $our-var = 'The our var';
my $my-var = 'The my var';
my $name = prompt 'Variable name: ';
my $value = $::($name); # use the right sigil, etc
put qq/Var ($name) starts with value $value/;
$::($name) = 137;
put qq/Var ($name) ends with value {$::($name)}/;

View file

@ -0,0 +1,16 @@
constant globals = new_dict()
while 1 do
string name = prompt_string("Enter name or press Enter to quit:")
if length(name)=0 then exit end if
integer k = getd_index(name,globals)
if k=0 then
string data = prompt_string("No such name, enter a value:")
setd(name,data,globals)
else
string data = prompt_string(sprintf("Already exists, new value[%s]:",{getd(name,globals)}))
if length(data) then
setd(name,data,globals)
end if
end if
end while

View file

@ -0,0 +1,3 @@
display "Name?" _request(s)
scalar $s=10
display $s

View file

@ -0,0 +1,5 @@
vname:="foo"; // or vname:=ask("var name = ");
klass:=Compiler.Compiler.compileText("var %s=123".fmt(vname))(); // compile & run the constructor
klass.vars.println();
klass.foo.println();
klass.setVar(vname).println(); // setVar(name,val) sets the var