Skip to content

Instantly share code, notes, and snippets.

View Varriount's full-sized avatar

Clay Sweetser Varriount

View GitHub Profile
@Varriount
Varriount / genfail.nim
Created November 14, 2013 18:10
Fail for generic calling newSeq with a generic type
proc test[T](number: int): seq[T] =
return newSeq[T](number)
var x = test[int](5)
@Varriount
Varriount / gist:7547631
Created November 19, 2013 16:00
Possible gc bug
Traceback (most recent call last)
builder.nim(908) builder
asyncio.nim(585) poll
gc.nim(445) newSeq
gc.nim(438) newObj
gc.nim(414) rawNewObj
gc.nim(985) collectCT
gc.nim(953) collectCTBody
gc.nim(912) CollectZCT
gc.nim(352) forAllChildren
@Varriount
Varriount / generator.nim
Last active December 28, 2015 19:19
Look ma, it's a generator!
iterator additionIterator(value: int): int {.closure.} =
var total = 0
while True:
total += value
yield total
var addIter = additionIterator # Creates a *copy* of the original iterator procedure
for i in 1..5:
echo(addIter(i)) # The argument the iterator takes is updated each time we call it.
@Varriount
Varriount / gendesc.nim
Last active December 29, 2015 00:39
Generics vs Typedesc : The Movie
# EXAMPLE A
iterator count* [T](start: T, step = 1): T {.closure.} =
## An iterator function that returns evenly spaced values of ordinal T,
## starting with `start`
## Note, this doesn't have any protections against overflow errors!
##
## Parameters:
## start: A starting ordinal
## step: The space between returned values.
var i = start
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
<language
name="Nimrod"
version="1.0"
kateversion="2.4"
section="Sources"
extensions="*.nim"
mimetype="text/x-nimrod">
@Varriount
Varriount / nimrod.YAML-tmLanguage
Created December 3, 2013 18:52
Nimrod TmLanguage
# [PackageDev] target_format: plist, ext: tmLanguage
---
name: Nimrod
scopeName: source.nimrodtwo
fileTypes: [".nim2"]
uuid: fa6f2c1c-dd3f-4bcd-b2be-d05312be4080
patterns:
- name: comment.line.number-sign.nimrod
match: (#).*$\n?
# This will build nimrod using the specified settings.
import
osproc, json, sockets, asyncio, os, streams, parsecfg, parseopt, strutils,
ftpclient, times, strtabs
import types
const
builderVer = "0.2"
buildReadme = """
This is a minimal distribution of the Nimrod compiler. Full source code can be
@Varriount
Varriount / gist:7815593
Created December 5, 2013 23:00
Meep. Brain has exploded.
proc foo[T](): array[T, int] =
return result
discard foo[TSlice[int](a:1,b:5)]()
Folder PATH listing
Volume serial number is 0000001A 644F:8281
C:.
├───.git
│ ├───hooks
│ ├───info
│ ├───logs
│ │ └───refs
│ │ ├───heads
│ │ │ ├───core
@Varriount
Varriount / os.nim
Created December 18, 2013 01:30
RemoveFile snippet
proc removeFile*(file: string) {.rtl, extern: "nos$1", tags: [FWriteDir].} =
## Removes the `file`. If this fails, `EOS` is raised. This does not fail
## if the file never existed in the first place.
## On Windows, ignores the read-only attribute.
when defined(Windows): # Would this be better using a template to
when useWinUnicode:
let f = newWideCString(file)
if DeleteFileW(f) == 0:
if GetLastError() == ERROR_ACCESS_DENIED:
if SetFileAttributesW(f, FILE_ATTRIBUTE_NORMAL) == 0: