September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1 +1 @@
|
|||
console printLine("Hello"," ","World!").
|
||||
console.printLine("Hello"," ","World!");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
USING: accessors io kernel literals math sequences ;
|
||||
IN: rosetta-code.call-a-method
|
||||
|
||||
! Define some classes.
|
||||
SINGLETON: dog
|
||||
TUPLE: cat sassiness ;
|
||||
|
||||
! Define a constructor for cat.
|
||||
C: <cat> cat
|
||||
|
||||
! Define a generic word that dispatches on the object at the top
|
||||
! of the data stack.
|
||||
GENERIC: speak ( obj -- )
|
||||
|
||||
! Define methods in speak which specialize on various classes.
|
||||
M: dog speak drop "Woof!" print ;
|
||||
M: cat speak sassiness>> 0.5 > "Hiss!" "Meow!" ? print ;
|
||||
M: object speak drop "I don't know how to speak!" print ;
|
||||
|
||||
! Place some objects of various classes in a sequence.
|
||||
${ dog 0.75 <cat> 0.1 <cat> 10 }
|
||||
! Call speak, a method, just like any other word.
|
||||
[ speak ] each
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
SomeClass {
|
||||
|
||||
*someClassMethod {
|
||||
|
||||
}
|
||||
|
||||
someInstanceMethod {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SomeClass.someClassMethod;
|
||||
|
||||
a = SomeClass.new;
|
||||
a.someInstanceMethod;
|
||||
Loading…
Add table
Add a link
Reference in a new issue