Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,40 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Dynamic is
package Abstract_Class is
type Class is limited interface;
function Boo (X : Class) return String is abstract;
end Abstract_Class;
use Abstract_Class;
package Base_Class is
type Base is new Class with null record;
overriding function Boo (X : Base) return String;
end Base_Class;
package body Base_Class is
function Boo (X : Base) return String is
begin
return "I am Class";
end Boo;
end Base_Class;
use Base_Class;
E : aliased Base; -- An instance of Base
begin
-- Gone run-time
declare
type Monkey_Patch (Root : access Base) is new Class with record
Foo : Integer := 1;
end record;
overriding function Boo (X : Monkey_Patch) return String;
function Boo (X : Monkey_Patch) return String is
begin -- Delegation to the base
return X.Root.Boo;
end Boo;
EE : Monkey_Patch (E'Access); -- Extend E
begin
Put_Line (EE.Boo & " with" & Integer'Image (EE.Foo));
end;
end Dynamic;

View file

@ -0,0 +1,25 @@
class SuperDynamic
@vars = {} of String => String | Int32
def set_vars (@vars)
end
macro method_missing (call)
{% name = call.name %}
{% if name.ends_with? "=" %}
{% name = name.gsub(/=$/, "") %}
raise "unknown var" unless @vars.has_key? {{name.id.stringify}}
@vars[{{name.id.stringify}}] = {{call.args[0].id}}
{% else %}
@vars[{{name.id.stringify}}]
{% end %}
end
end
sd = SuperDynamic.new
sd.set_vars({ "a" => 1, "b" => "2" })
p! sd.a
sd.a = 99
p! sd.a

View file

@ -0,0 +1,5 @@
class myclass end
local mc = new myclass()
mc.somevar = 21
print(mc.somevar * 2)

View file

@ -0,0 +1,5 @@
$x = 42 `
| Add-Member -PassThru `
NoteProperty `
Title `
"The answer to the question about life, the universe and everything"

View file

@ -0,0 +1,48 @@
Rebol [
Title: "Add Variables to Class at Runtime"
URL: http://rosettacode.org/wiki/Adding_variables_to_a_class_instance_at_runtime
]
; As I understand it, a REBOL object can only ever have whatever
; properties it was born with. However, this is somewhat offset by the
; fact that every instance can serve as a prototype for a new object
; that also has the new parameter you want to add.
; Here I create an empty instance of the base object (x), then add the
; new instance variable while creating a new object prototyped from
; x. I assign the new object to x, et voila', a dynamically added
; variable.
x: make object! [] ; Empty object.
x: make x [
newvar: "forty-two" ; New property.
]
print "Empty object modifed with 'newvar' property:"
probe x
; A slightly more interesting example:
starfighter: make object! [
model: "unknown"
pilot: none
]
x-wing: make starfighter [
model: "Incom T-65 X-wing"
]
squadron: reduce [
make x-wing [pilot: "Luke Skywalker"]
make x-wing [pilot: "Wedge Antilles"]
make starfighter [
model: "Slayn & Korpil B-wing"
pilot: "General Salm"
]
]
; Adding new property here.
squadron/1: make squadron/1 [deathstar-removal-expert: yes]
print [crlf "Fighter squadron:"]
foreach pilot squadron [probe pilot]

View file

@ -0,0 +1,5 @@
>> o: object [a: 1] put o 'b 2 o
== make object! [
a: 1
b: 2
]

View file

@ -0,0 +1,35 @@
import os
import strconv
struct Obj {
mut:
var map[string]string
}
fn main() {
mut obj := Obj{}
mut nir, mut ir := 0, 1
mut name, mut val := "", ""
for nir < 1 || nir > 3 {
nir = strconv.atoi(os.input("How many variables to create (max 3): ")) or
{println("Invalid input!") continue}
}
for ir <= nir {
println("Enter the variable names and their values, below:")
println("Variable ${ir}")
name = os.input_opt(" Name: ") or {println("Invalid input!") exit(1)}
for {
val = os.input_opt(" Value: ") or {println("Invalid input!") exit(2)}
break
}
obj.var[name] = val
ir++
}
println("\n" + "Enter q to quit")
for {
name = os.input_opt("Which variable (field) name to inspect : ") or {continue}
if name.to_lower() == "q" {break}
if name !in obj.var {println("There's no variable (field) of that name, try again")}
else {println("It's value is: '${obj.var[name]}'")}
}
}