Skip to content

Instantly share code, notes, and snippets.

@PhilipWitte
PhilipWitte / gist:4962210
Last active December 13, 2015 19:19
Memory Safety
type Foo
{
var bar = 0
}
func main()
{
ref f : Foo
ref b : int
@PhilipWitte
PhilipWitte / gist:4962255
Last active December 13, 2015 19:19
dynamic array problem
func main()
{
var nums = text[] # a dynamic array
ref n : text # a 'int' reference
nums += "foo" # add "foo"
nums += "bar" # add "bar"
nums += "baz" # add "baz"
n => nums[1] # 'n' refers to 'num[1]'
@PhilipWitte
PhilipWitte / gist:4969024
Last active December 13, 2015 20:18
Factory syntax
type Foo =
value : int
init Foo.new(v) =
value = v
proc Foo.bar =
echo(value)
proc main =
@PhilipWitte
PhilipWitte / gist:4974439
Last active December 13, 2015 20:59
The "Perfect" Programming Language

The "Perfect" Programming Language

Assertions

  1. The easier to learn, the better.
  2. Best if easy to mentally parse "at a glance".
  3. Easy to understand structure "at a glance".
  4. Easy to type.
@PhilipWitte
PhilipWitte / gist:5017538
Last active December 14, 2015 02:59
Reign Language Goals
type Person
{
var name : text
var age : uint
init new(.name, .age=)
init load(path) { # load from path # }
func greet()
{
# syntax:
# [key] <name> [attributes] [types]
type Sprite
{
var pos Vector
var rot Rotation
}
type Ship Sprite
@PhilipWitte
PhilipWitte / gist:6648742
Created September 21, 2013 08:58
Nimrod - feature suggestions

Changes I would love to see in Nimrod.

"Good Syntax" is often heavily subjective. So it makes sense to allow people to program in the styles they like best. I would argue that there is also value in the ability to lock-up and restrict syntax features (for things like compile-to-OpenCL, or game scripts), but that's beyond the scope of this document.

Many programmers prefer empirical style to functional. In the order to attract these people to Nimrod, and to give all developers freedom of expression, I have a few ideas on how to change and extend Nimrod to support a more empirical coding style, in addition to it's already great functional style.

type

First, a gripe. I don't like the inconsistency of type syntax. No other object is defined this way in the syntax. The following:

@PhilipWitte
PhilipWitte / gist:6665942
Last active December 23, 2015 16:59
Nimrod Engine/SDK ideas

Nimrod Engine Ideas & Goals

Key

using - template which essentially "from EXPR import nil" + some selection
part - macro which defines a part of the app/game (corresponds, by name, to editor data)
mode - built-in part state system component (multi-state. easy transition declaration)
on - app/game event logic (can be user-defined in editor)
import StrUtils, Times


type Vector = tuple[x, y, z, w:float]

# factories
proc new(x, y, z, w:float): Vector {.noSideEffect, noInit, inline.} =
  result.x = x
 result.y = y
@PhilipWitte
PhilipWitte / gist:6772348
Last active December 24, 2015 08:39
Nimrod's Times.EpochTime doesn't seem to measure correctly.
import StrUtils, Times
type Vector = tuple[x, y, z, w:float]
proc new(T:typedesc[Vector], x, y, z, w:float): Vector {.noSideEffect, noInit, inline.} =
result.x = x
result.y = y
result.z = z