Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@def-
def- / error
Created August 27, 2015 19:20
C++ error
$ g++ -o x x.cpp
x.cpp: In function ‘int main()’:
x.cpp:9:13: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘voi ’)
std::cout << foo() << std::endl;
^
x.cpp:9:13: note: candidates are:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/iostream:39:0,
from x.cpp:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/ostream:108:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
operator<<(__ostream_type& (*__pf)(__ostream_type&))
@def-
def- / magicForest.nim
Last active August 29, 2015 14:02
Goats, Lions and Wolves in Nimrod
# http://unriskinsight.blogspot.de/2014/06/fast-functional-goats-lions-and-wolves.html
#
# Goats Wolves Lions C++11 Nimrod
# 17 55 6 0.00 0.03
# 117 155 106 0.17 0.13
# 217 255 206 0.75 0.62
# 317 355 306 2.16 1.89
# 417 455 406 5.28 4.34
# 517 555 506 10.75 8.42
# 617 655 606 19.15 14.45
@def-
def- / funMagicForest.nim
Created June 6, 2014 18:51
Functional Goats, Lions and Wolves in Nimrod
# http://unriskinsight.blogspot.de/2014/06/fast-functional-goats-lions-and-wolves.html
#
# Goats Wolves Lions C++11 Nimrod (functional)
# 17 55 6 0.00 0.00
# 117 155 106 0.17 0.31
# 217 255 206 0.75 1.88
# 317 355 306 2.16 5.81
# 417 455 406 5.28 14.16
# 517 555 506 10.75 27.72
# 617 655 606 19.15 46.19
@def-
def- / ambiguous.nim
Last active August 29, 2015 14:02
Ambiguous
type
Time = distinct float
Frequency = distinct float
Radioactivity = distinct float
proc `/` *(x: float, y: Time): Frequency = Frequency(x / float(y))
proc `/` *(x: float, y: Time): Radioactivity = Radioactivity(x / float(y))
# Error: ambiguous call; both ambiguous./(x: float, y: Time): Frequency and ambiguous./(x: float, y: Time): Radioactivity match for: (int literal(1), Time)
var fr: Frequency = 1 / Time(1)
@def-
def- / avg.nim
Last active August 29, 2015 14:02
Average in Nimrod and Python
# 3.5 seconds
# compute average line length
var count = 0
var sum = 0
for line in stdin.lines:
count += 1
sum += line.len
# Not much faster
@def-
def- / gist:461c6a35aa593f1a2d0a
Created June 18, 2014 16:06
nimrod pretty crash
# echo > bar.nim
# nimrod pretty bar.nim
config/nimrod.cfg(38, 2) Hint: added path: '/home/def/.babel/pkgs/' [Path]
Hint: used config file '/home/def/nimrod/config/nimrod.cfg' [Conf]
Hint: system [Processing]
lib/system.nim(53, 9) Error: name should be: Ptr
lib/system.nim(54, 9) Error: name should be: Ref
lib/system.nim(53, 2) Error: name should be: Ptr
lib/system.nim(54, 2) Error: name should be: Ref
lib/system.nim(129, 10) Error: name should be: t
@def-
def- / fasta.nim
Last active August 29, 2015 14:03
Fasta_Pairs
# 0.19 seconds, 79 MB/s
proc fgets(c: cstring, n: int, f: TFile): cstring {.
importc: "fgets", header: "<stdio.h>", tags: [FReadIO].}
proc myReadLine(f: TFile, line: var TaintedString): bool =
var buf {.noinit.}: array[8192, char]
setLen(line.string, 0)
result = true
while true:
import opengl
import glut
proc paint() {.cdecl.} =
glClearColor(0.3,0.3,0.3,0.0)
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glShadeModel(GL_SMOOTH)
glLoadIdentity()
import sequtils, math
template any(sequence, operation: expr): expr =
var result {.gensym.}: bool = false
for i in 0 .. <sequence.len:
let it {.inject.} = sequence[i]
result = operation
if result:
break
result
@def-
def- / knightstour.nim
Last active August 29, 2015 14:04
Knight's tour
import sets
const
moves = 8
knight: array[moves, tuple[x, y: int]] =
[(1, 2), (1, -2), (2, 1), (2, -1), (-1, 2), (-1, -2), (-2, 1), (-2, -1)]
start = 2
board_size = 6
bs2 = board_size * board_size