Skip to content

Instantly share code, notes, and snippets.

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:
@PhilipWitte
PhilipWitte / gist:9324201
Last active August 29, 2015 13:56
Unified Nimrod Syntax

Nimrod - Unified Command Syntax

RULES

<command> <ident> <pragma> <type> : <body>

<command> <ident>
  <pragma> <type> :
    <body>
var
vertArrayObject: GLuint
vertBufferObject: GLuint
proc init =
var verts = [
0f32, 0f32, 0f32,
4f32, 0f32, 0f32,
0f32, 4f32, 0f32,
@PhilipWitte
PhilipWitte / gist:10698296
Last active August 29, 2015 13:59
random syntax thoughts
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
@PhilipWitte
PhilipWitte / gist:11251113
Created April 24, 2014 11:29
Game Engine Update
# engine.nim
proc update* =
Time.update()
Input.update() # update input every cycle (raw input)
GameParts.rawUpdate() # respond to input changes (often minimal, if needed at all)
if Time.elapsed >= Time.fixedStep:
Physics.update() # either unique thread, or uses thread pool
@PhilipWitte
PhilipWitte / gist:11272741
Last active August 29, 2015 14:00
Nimrod syntax suggestions - OOP & @pragma
type Person: ref object @inheritable =
var
name*: string
age+: int
proc new*(name:string, age = 0) @init =
this.name = name
this.age = age
proc greet*() @pure =
@PhilipWitte
PhilipWitte / gist:11306682
Last active August 29, 2015 14:00
Nimrod - @Keyword for OOP
macro class* (head:expr, body:stmt): stmt @keyword =
## builds OOP-style type/procs...
# @keyword makes this behave in the following ways..
# - is compiled (no VM) for compile-time performance
# - is used with '=' instead of ':' (like 'proc' not 'for')
macro init* (head:expr, params:expr{param}, body:stmt): stmt @keyword =
## builds OOP-style alloc/init procs for a type
# NOTE: {param} means 'params' only accepts parameter syntax (a:T, b:U, ...)
import macros
macro class*(head:expr, body:stmt): stmt {.immediate.} =
# The macro is immediate so that it doesn't
# resolve identifiers passed to it
var typeName, baseName: PNimrodNode
if head.kind == NnkIdent: