Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

Croc

< >

Croc is a programming language created in 2006 by Jarrett Billingsley.

#663on PLDB 18Years Old
Download source code:
git clone https://github.com/JarrettBillingsley/Croc
Homepage · Source Code · Wikipedia

The MiniD (has been renamed Croc) programming language is a small, lightweight, extension language in the vein of Lua or Squirrel, but designed to be used mainly with the D programming language. It supports both object-oriented and imperative programming paradigms, as well as some simple functional aspects. Distributed under the licence of zlib/libpng, MiniD is free software.. Read more on Wikipedia...


Example from the web:
module samples.interfaces class Method { _name _numParams this(name: string, numParams: int) { :_name = name :_numParams = numParams } function name() = :_name function implements(f: function) = f.numParams() == :_numParams function toString() = "{} ({} params)".format(:_name, :_numParams) } class Interface { _name _methods _implementors this(name: string, methods: array) { if(!methods.all(\m -> m as Method)) throw TypeError("All methods must be Methods") :_name = name :_methods = methods.dup() :_implementors = {} } function implement(T: class) { foreach(m; :_methods) { local name = m.name() if(!hasMethod(T, name) || !m.implements(T.(name))) throw TypeError("Class {} does not implement method '{}' from {}".format(nameOf(T), m, :_name)) } :_implementors[T] = true } function opCall(val: instance) { if(superOf(val) not in :_implementors) :implement(superOf(val)) return true } } function implements(T: class, vararg) { for(i; 0 .. #vararg) { local p = vararg[i] if(!(p as Interface)) throw TypeError("All varargs must be Interfaces") p.implement(T) } return T } local IStream = Interface("IStream", [ Method("read", 3) Method("write", 3) Method("seek", 2) ]) class DerpStream { function read(m, offset, size) {} function write(m, offset, size) {} function seek(offset, whence) {} } function streamSomething(s: @IStream) { s.read() writeln("yay!") } function main() { local d = DerpStream() streamSomething(d) }
Example from Wikipedia:
function first(x: array|string) = x[0] writeln(first([1, 2, 3])) // prints 1 writeln(first("hello")) // prints h writeln(first(45)) // error, invalid parameter type 'int'

Language features

Feature Supported Example Token
MultiLine Comments
Binary Literals // 0[bB][01][01_]*
Integers // ([0-9][0-9_]*)(?![.eE])
Floats // ([0-9][0-9_]*)(?=[.eE])(\.[0-9][0-9_]*)?([eE][+\-]?[0-9_]+)?
Hexadecimals // 0[xX][0-9a-fA-F][0-9a-fA-F_]*
Comments // A comment
Line Comments // A comment //
Semantic Indentation X

- Build the next great programming language · Add · Issues · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements

Built with Scroll v164.7.0