Skip to content

Instantly share code, notes, and snippets.

View joseoliv's full-sized avatar

José de Oliveira Guimarães joseoliv

View GitHub Profile
@joseoliv
joseoliv / test_anonymous_functions.dart
Created December 20, 2024 21:58
Teste de funções anônimas em Dart
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);
@joseoliv
joseoliv / Box(1).cyan
Created December 20, 2024 21:50
Arquivo do diretório cyan-prototipos-genericos
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
@joseoliv
joseoliv / Program.cyan
Created December 20, 2024 21:49
Arquivo do diretório cyan-prototipos-genericos
package main
object Program
func run {
var bi = Box<Int>(0);
bi setValue: 5;
bi getValue println;
var pp = Box<Program>(self);
}
@joseoliv
joseoliv / Program.cyan
Created December 20, 2024 21:44
Introdução à Cyan - diretório cyan-intro
package main
object Program
func run {
prototypeExample;
ifWhileAsMessagePassing
}
func prototypeExample {
@joseoliv
joseoliv / Vaca.java
Created December 20, 2024 21:34
Vacas não podem comer pizza. É a opinião da orientação a objetos.
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;
@joseoliv
joseoliv / tudo.pl
Last active December 20, 2024 01:37
Exemplo de Prolog usado na apostila
/* 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 ').
@joseoliv
joseoliv / main.c
Created November 28, 2024 22:59
Dynamically typed language translation to C
// 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;
@joseoliv
joseoliv / Cyan-in-20-minutes
Last active August 30, 2022 12:53
Cyan in 20 minutes
package main
// import a Cyan package
import cyan.math
import cyan.reflect
// import a Java package
import java.lang
@doc{*
@joseoliv
joseoliv / Helloworld.cyan
Last active March 12, 2021 18:44
Hello world program in Cyan
package main
object Program
func run {
"Hello world" println
}
end
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)