September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,24 +1,24 @@
|
|||
import extensions.
|
||||
import extensions;
|
||||
|
||||
class T
|
||||
{
|
||||
Name = "T".
|
||||
Name = "T";
|
||||
|
||||
clone = T new.
|
||||
T clone() = new T();
|
||||
}
|
||||
|
||||
class S :: T
|
||||
class S : T
|
||||
{
|
||||
Name = "S".
|
||||
Name = "S";
|
||||
|
||||
clone = S new.
|
||||
T clone() = new S();
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
type<T> original := S new.
|
||||
type<T> clone := original clone.
|
||||
public program()
|
||||
{
|
||||
T original := new S();
|
||||
T clone := original.clone();
|
||||
|
||||
console printLine(original Name).
|
||||
console printLine(clone Name).
|
||||
].
|
||||
console.printLine(original.Name);
|
||||
console.printLine(clone.Name)
|
||||
}
|
||||
|
|
|
|||
38
Task/Polymorphic-copy/Julia/polymorphic-copy.julia
Normal file
38
Task/Polymorphic-copy/Julia/polymorphic-copy.julia
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
abstract type Jewel end
|
||||
|
||||
mutable struct RoseQuartz <: Jewel
|
||||
carats::Float64
|
||||
quality::String
|
||||
end
|
||||
|
||||
mutable struct Sapphire <: Jewel
|
||||
color::String
|
||||
carats::Float64
|
||||
quality::String
|
||||
end
|
||||
|
||||
color(j::RoseQuartz) = "rosepink"
|
||||
color(j::Jewel) = "Use the loupe."
|
||||
color(j::Sapphire) = j.color
|
||||
|
||||
function testtypecopy()
|
||||
a = Sapphire("blue", 5.0, "good")
|
||||
b = RoseQuartz(3.5, "excellent")
|
||||
|
||||
j::Jewel = deepcopy(b)
|
||||
|
||||
println("a is a Jewel? ", a isa Jewel)
|
||||
println("b is a Jewel? ", a isa Jewel)
|
||||
println("j is a Jewel? ", a isa Jewel)
|
||||
println("a is a Sapphire? ", a isa Sapphire)
|
||||
println("a is a RoseQuartz? ", a isa RoseQuartz)
|
||||
println("b is a Sapphire? ", b isa Sapphire)
|
||||
println("b is a RoseQuartz? ", b isa RoseQuartz)
|
||||
println("j is a Sapphire? ", j isa Sapphire)
|
||||
println("j is a RoseQuartz? ", j isa RoseQuartz)
|
||||
|
||||
println("The color of j is ", color(j), ".")
|
||||
println("j is the same as b? ", j == b)
|
||||
end
|
||||
|
||||
testtypecopy()
|
||||
7
Task/Polymorphic-copy/REXX/polymorphic-copy.rexx
Normal file
7
Task/Polymorphic-copy/REXX/polymorphic-copy.rexx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/*REXX program to copy (polymorphically) one variable's value into another variable. */
|
||||
b= 'old value.'
|
||||
a= 123.45
|
||||
b= a /*copy a variable's value into another.*/
|
||||
if a==b then say "copy did work."
|
||||
else say "copy didn't work." /*didn't work, maybe ran out of storage*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
Loading…
Add table
Add a link
Reference in a new issue