val everyone: list[Person] = new(size:50, step:25, max:250)
enum Emotion {
Relaxed, Happy, Angry, Distress
}
type Vector[T:int|num] byRef: tuple {
var
x, y, z: T
var | |
vertArrayObject: GLuint | |
vertBufferObject: GLuint | |
proc init = | |
var verts = [ | |
0f32, 0f32, 0f32, | |
4f32, 0f32, 0f32, | |
0f32, 4f32, 0f32, | |
After a recent reddit post and the resulting IRC discussion it caused on Nimrod's syntax, I came up with a couple of changes to the syntax which have a realistic migration path (in theory), and allow for Nimrod to expand to a syntax which could end most of the complaints we here from the C/Java/etc camp, without stepping on the toes of those already happy with the existing syntax.
Instead of a lengthy explanation, i'm sure the code can somewhat speak for itself..
# First, we change set's to @{} instead of {} which..
# ..is consistent with seq and allows us to repurpose {}
var mySet = @{ A, B, C }
var mySeq = @[ a, b, c ]
import StrUtils | |
# --- | |
type Vec4* {.incompleteStruct, importc:"__m128", header:"<xmmintrin.h>".} = object | |
type Vec4Array = array[0 .. 3, float32] | |
# --- | |
proc setVec4 (w, z, y, x:float32): Vec4 {.importc:"_mm_set_ps".} |
# Change set's to @{} instead of {} | |
# which is consistent with seq | |
var mySet = @{ A, B, C } | |
var mySeq = @[ a, b, c ] | |
# Force ':' where ever a "body" is consumed which | |
# allows both indent style and bracket-style | |
# the follow types are all identical.. | |
type Foo* {.final.} = ref object: |
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 |
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
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)
"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.
First, a gripe. I don't like the inconsistency of type
syntax. No other object is defined this way in the syntax. The following: