This file contains hidden or 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 call/cc to write a program that loops indefinitely, | |
;; printing a sequence of numbers beginning at zero. | |
;; Do not use any recursive procedures, and do not use any assignments. | |
(let ((kontp (call-with-current-continuation (lambda (k) (cons k 0))))) | |
(let ((i (cdr kontp)) | |
(kont (car kontp))) | |
(display i) | |
(display " ") | |
(kont (cons kont (+ 1 i))))) |
This file contains hidden or 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
#lang racket/gui | |
#| | |
TODO: | |
1. Allow random numbers over any integer range (as opposed to the contract attached to random. | |
2. Possibly refactor everything into the guess-frame%. | |
|# | |
(define min-value (make-parameter 1)) | |
(define max-value (make-parameter 100)) |
This file contains hidden or 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
#include <sstream> | |
#include <vector> | |
#include <iterator> | |
#include <iostream> | |
using namespace std; | |
template <typename T> | |
vector<T> read_vector(const string& s) { | |
istringstream iss(s); |
This file contains hidden or 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
// | |
// Linguagem de expressoes aritmeticas | |
// Interpretador, compilador para maquina de pilha | |
// | |
//--- expressoes aritmeticas --------------------- | |
enum Exp { | |
case Const(Int) | |
indirect case Soma(Exp, Exp) | |
indirect case Sub(Exp, Exp) |
This file contains hidden or 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
// Calculo de tabela verdade para formulas representadas | |
// com arvores sintaticas. | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define TRUE 1 | |
#define FALSE 0 | |
// macro para calcular o valor da implicacao |
This file contains hidden or 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
# in main.nim, mainCommand proc | |
# ... | |
of "parse": | |
gCmd = cmdParse | |
wantMainModule() | |
let n = parseFile(gProjectMainIdx) | |
debug(n) | |
# ... |
This file contains hidden or 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
// | |
// Calcula a tabela-verdade para uma fórmula fixa | |
// | |
#include <stdio.h> | |
#define TRUE 1 | |
#define FALSE 0 | |
// macro para calcular o valor da implicacao |
This file contains hidden or 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
datatype nat = Z | S nat | |
fun plus :: "nat ⇒ nat ⇒ nat" where | |
"plus Z m = m" | | |
"plus (S n) m = S (plus n m)" | |
fun mult :: "nat ⇒ nat ⇒ nat" where | |
"mult Z m = Z" | | |
"mult (S n) m = plus (mult n m) m" |
This file contains hidden or 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
let string_fold s f ini = (* this is a left fold *) | |
let len = String.length s in | |
let rec loop i res = | |
if i >= len then res else loop (i+1) (f s.[i] res) | |
in | |
loop 0 ini | |
let explode s = (* a right string fold wouldn't need the reverse *) | |
List.rev @@ string_fold s (fun c l -> c :: l) [] | |
This file contains hidden or 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
assign.iter() | |
.zip(self.vars.iter()) | |
.filter(|&(_, var)| res_vars.contains(var)) | |
.map(|(val, var)| (val, self.table.var_cardinality(*var))) | |
.fold((0, 1), |(sum, cs), (val, c2)| (sum + val * cs, c2 * cs)); |