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,5 +1,8 @@
;Task:
Invoke an object method where the name of the method to be invoked can be generated at run time.
;Cf:
;Related tasks:
* [[Respond to an unknown method call]].
* [[Runtime evaluation]]
<br><br>

View file

@ -1,18 +1,17 @@
#import system.
#import extensions.
import extensions.
#class Example
class Example
{
#method foo : x
foo : x
= x + 42.
}
#symbol program =
program =
[
#var example := Example new.
#var methodSignature := "foo".
var example := Example new.
var methodSignature := "foo".
#var result := example::(Signature new &literal:methodSignature) eval:5.
var result := example~(Signature new literal:methodSignature) eval:5.
console writeLine:methodSignature:"(":5:") = ":result.
console printLine(methodSignature,"(",5,") = ",result).
].

View file

@ -3,10 +3,8 @@ include FMS-SILib.f
var x \ instantiate a class var object named x
: test
heap> string locals| s |
'!' s +: ':' s +: \ build the message "!:" into string s
42 x s @: evaluate \ retrieve the text from s and execute it
x p: ; \ lastly, send the p: message to x to print it
\ Use a standard Forth string and evaluate it.
\ This is equivalent to sending the !: message to object x
42 x s" !:" evaluate
test \ => 42 ok
x p: 42 \ send the print message ( p: ) to x to verify the contents

View file

@ -1,24 +0,0 @@
package main
import (
"fmt"
"reflect"
)
type example struct{}
// the method must be exported to be accessed through reflection.
func (example) Foo() int {
return 42
}
func main() {
// create an object with a method
var e example
// get the method by name
m := reflect.ValueOf(e).MethodByName("Foo")
// call the method with no argments
r := m.Call(nil)
// interpret first return value as int
fmt.Println(r[0].Int()) // => 42
}

View file

@ -1,12 +0,0 @@
procedure main()
x := foo() # create object
x.m1() # static call of m1 method
# two examples where the method string can be dynamically constructed ...
"foo_m1"(x) # ... need to know class name and method name to construct name
x.__m["m1"] # ... general method (better)
end
class foo(a,b,c) # define object
method m1(x)
end
end

View file

@ -0,0 +1,13 @@
// Kotlin JS version 1.1.4-3
class C {
fun foo() {
println("foo called")
}
}
fun main(args: Array<String>) {
val c = C()
val f = "c.foo"
js(f)() // invokes c.foo dynamically
}

View file

@ -1,3 +0,0 @@
| ?- query_foo::query.
Message: bar(X).
Reply: bar(42)

View file

@ -0,0 +1,10 @@
procedure Hello()
?"Hello"
end procedure
string erm = "Hemmm"
for i=3 to 5 do
erm[i]+=-1+(i=5)*3
end for
call_proc(routine_id(erm),{})

View file

@ -0,0 +1,10 @@
$method = ([Math] | Get-Member -MemberType Method -Static | Where-Object {$_.Definition.Split(',').Count -eq 1} | Get-Random).Name
$number = (1..9 | Get-Random) / 10
$result = [Math]::$method($number)
$output = [PSCustomObject]@{
Method = $method
Number = $number
Result = $result
}
$output | Format-List

View file

@ -0,0 +1 @@
name:="len"; "this is a test".resolve(name)() //-->14