This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void testAnonymousFunctions() { | |
var f = (int n) { return n*n;}; | |
print(f(5)); | |
var g = (int n) => n*n; | |
print(g(5)); | |
var sum = 0; | |
var list = [1, 2, 3, 4]; | |
list.forEach( | |
(n) => sum += n ); | |
assert (sum == 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
@concept{* | |
T has [ func * T -> T ], | |
"Prototype T does not define method *" | |
T get has [ func printK ] | |
*} | |
object Box<T> | |
func init: T value { self.value = value } | |
@property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
object Program | |
func run { | |
var bi = Box<Int>(0); | |
bi setValue: 5; | |
bi getValue println; | |
var pp = Box<Program>(self); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
object Program | |
func run { | |
prototypeExample; | |
ifWhileAsMessagePassing | |
} | |
func prototypeExample { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pessoa { ... } | |
class Estudante extends Pessoa { ... } | |
class Fazendeiro extends Pessoa { ... } | |
class Animal { | |
public void coma(Comida c) { ... } | |
public Estudante getTutor() { ... } | |
} | |
class Vaca extends Animal { | |
public Vaca(String name) { this.name = name; } | |
String name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* use em https://swish.swi-prolog.org/ */ | |
:- style_check(-singleton). | |
:- dynamic molhado/1. | |
homem(jose) :- write('jose '). | |
homem(joao) :- write('joao '). | |
homem(pedro) :- write('pedro '). | |
homem(paulo) :- write('paulo '). | |
mulher(maria) :- write('maria '). | |
mulher(ana) :- write('ana '). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// also in https://www.onlinegdb.com/edit/xhqFlnv8f | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <malloc.h> | |
struct TypeData { | |
void (**virtualTable)(void); | |
char **methodNameList; | |
int methodNameListSize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// import a Cyan package | |
import cyan.math | |
import cyan.reflect | |
// import a Java package | |
import java.lang | |
@doc{* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
object Program | |
func run { | |
"Hello world" println | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package metaobjectTest | |
@doc{* | |
This annotation takes two parameters. The first is a number. There should be | |
an error from the line of the annotation plus this number. The second parameter | |
is the error message that the compiler should issue (or a similar message). | |
The compiler checks if there is an error in the indicated line. If not, | |
an error message is issued. That is, suppose the code | |
@cep(1, "Expression expected) |
NewerOlder