www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - MiniD 1.0 released!

reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
After more than a year of brainstorming, writing, re-writing, taking ideas 
from other languages and generally having a good time, I've come to what I 
feel is a good place to call it 1.0.

== What is MiniD? ==

MiniD is a scripting language written entirely in D, designed around D's 
features and with D's semantics in mind.  It's based mainly off of Lua and 
Squirrel, with influences from D and JavaScript.

MiniD is meant to be an extensible extension language, like Lua.  That is, 
rather than trying to be a huge do-everything language like Python, it's 
meant to be a smaller, more compact (but still expressive) language for 
writing programs and scripts meant to be run in the context of a larger 
program.  It's extensible in that the "host" program can provide functions 
and classes as hooks into application-specific functionality, and it's an 
extension language in that it can be used to extend the capabilities of the 
host program.

MiniD makes it easy to interface between native and script code.  The 
low-level API is muct simpler to use and cleaner than that of most languages 
implemented in C, and there is also a Pyd-like binding library to make it 
possible to quickly expose free functions and class types to MiniD.

== Why MiniD? ==

Why MiniD instead of something like Lua, Python, or DMDScript?  Lua and 
Python are both written in C, and as such have (compared to what D provides) 
clumsy APIs.  They also have their own memory management and error handling 
schemes, two things that D provides natively.  DMDScript has a D 
implementation, but it's not free for all use.  MiniD is written in D, has a 
simple-to-use API, takes advantage of as many D features as possible (the 
GC, exceptions, templates, classes), and is licensed under the zlib/libpng 
license, which means you can use it for just about anything.

== Describe the language. ==

- Uses a C-style syntax with a lot of D influences.

- Is dynamically typed, with booleans, integers, double-precision floats, 
UTF-32 characters and strings, tables (maps), arrays, first-class functions, 
and classes.

- Is object-oriented, with a class-based OOP model with support for single 
inheritance and dynamic modification of classes (as they are a first-class 
type).

- Makes it easy to make larger codebases with native support for modules and 
packages.

- Supports a form of collaborative multithreading with coroutines.  A 
coroutine is like a function which you pause and resume explicitly. 
Coroutines can be used to make iterators and to simulate simple 
multithreading.

== Describe the API. ==

- Supports code sandboxing through the use of multiple "contexts", into 
which libraries can be loaded.  You can create a sandbox by only loading a 
restricted set of libraries into a context, and then running code in it.

- Is templated in many places to support IFTI, and converts between native D 
types and MiniD types in many places as well, in order to avoid lots of 
tedious explicit types needing to be specified and conversions to be done.

- Makes it easy to write native functions using the API.  No confusing 
excessive stack manipulation like with Lua or Squirrel.  No reference 
counting like with Python.  Just get the values and manipulate them with a 
program state.

- Makes it really easy to expose native functions and classes to MiniD 
through a templated binding library, similar to Pyd.  Can bind free 
functions, classes, and in classes, constructors (even multiple constructors 
with the same number of parameters, unlike Pyd), methods, and properties 
(through a convention, as MiniD itself does not have explicit properties). 
Even supports binding multiple D classes which are in an inheritance 
hierarchy, but notably does _not_ yet support MiniD classes then inheriting 
from those exposed D classes.

== Licensing and Compatibility ==

MiniD is licensed under zlib/libpng, which basically means (1) I'd like you 
to give me credit if you use it, (2) you can't say that you made it, and (3) 
you can modify it all you want and even release your own modified version of 
the language, but you can't call a modified version "MiniD".

MiniD is, as far as I know, only compatible with D 1 (last compiled with D 
1.020).  Because it uses some newer features, it is not known to work with 
GDC 0.23, but may compile with one of the newer patches.

MiniD is based entirely on Tango, the alternative standard library for D. 
MiniD was last built with Tango 0.99.

MiniD is built with Bu[il]d, but should also work with DSSS.  Not real sure 
if it works with dsss net.  DSSS is still largely a mystery to me.

MiniD should compile on any platform for which there's a functional 
compiler.  It has been developed and tested on Windows, and has also been 
compiled and tested on Ubuntu 7.04.

== Links ==

The main page for MiniD is http://www.dsource.org/projects/minid.  The 
forums are at http://www.dsource.org/forums/viewforum.php?f=94; I use the 
forums for announcements, and you can also start discussions there.

You can find information on downloading the library on the main page. 
There's also a link to MDCL, the MiniD Command-Line interpreter, for which 
Windows binaries are provided.  If you're on another system, you can check 
out the trunk and compile MDCL manually.

Any questions, comments etc.  Either reply here or post on the forums :) 
Jul 31 2007
next sibling parent Derek Parnell <derek nomail.afraid.org> writes:
On Wed, 1 Aug 2007 02:05:40 -0400, Jarrett Billingsley wrote:

Congratulations Jarrett! This is a gem of a D project.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
1/08/2007 4:59:18 PM
Aug 01 2007
prev sibling next sibling parent reply Robert Fraser <fraserofthenight gmail.coim> writes:
Jarrett Billingsley Wrote:

 After more than a year of brainstorming, writing, re-writing, taking ideas 
 from other languages and generally having a good time, I've come to what I 
 feel is a good place to call it 1.0.
 
 == What is MiniD? ==
 
 MiniD is a scripting language written entirely in D, designed around D's 
 features and with D's semantics in mind.  It's based mainly off of Lua and 
 Squirrel, with influences from D and JavaScript.
 
 MiniD is meant to be an extensible extension language, like Lua.  That is, 
 rather than trying to be a huge do-everything language like Python, it's 
 meant to be a smaller, more compact (but still expressive) language for 
 writing programs and scripts meant to be run in the context of a larger 
 program.  It's extensible in that the "host" program can provide functions 
 and classes as hooks into application-specific functionality, and it's an 
 extension language in that it can be used to extend the capabilities of the 
 host program.
 
 MiniD makes it easy to interface between native and script code.  The 
 low-level API is muct simpler to use and cleaner than that of most languages 
 implemented in C, and there is also a Pyd-like binding library to make it 
 possible to quickly expose free functions and class types to MiniD.
 
 == Why MiniD? ==
 
 Why MiniD instead of something like Lua, Python, or DMDScript?  Lua and 
 Python are both written in C, and as such have (compared to what D provides) 
 clumsy APIs.  They also have their own memory management and error handling 
 schemes, two things that D provides natively.  DMDScript has a D 
 implementation, but it's not free for all use.  MiniD is written in D, has a 
 simple-to-use API, takes advantage of as many D features as possible (the 
 GC, exceptions, templates, classes), and is licensed under the zlib/libpng 
 license, which means you can use it for just about anything.
 
 == Describe the language. ==
 
 - Uses a C-style syntax with a lot of D influences.
 
 - Is dynamically typed, with booleans, integers, double-precision floats, 
 UTF-32 characters and strings, tables (maps), arrays, first-class functions, 
 and classes.
 
 - Is object-oriented, with a class-based OOP model with support for single 
 inheritance and dynamic modification of classes (as they are a first-class 
 type).
 
 - Makes it easy to make larger codebases with native support for modules and 
 packages.
 
 - Supports a form of collaborative multithreading with coroutines.  A 
 coroutine is like a function which you pause and resume explicitly. 
 Coroutines can be used to make iterators and to simulate simple 
 multithreading.
 
 == Describe the API. ==
 
 - Supports code sandboxing through the use of multiple "contexts", into 
 which libraries can be loaded.  You can create a sandbox by only loading a 
 restricted set of libraries into a context, and then running code in it.
 
 - Is templated in many places to support IFTI, and converts between native D 
 types and MiniD types in many places as well, in order to avoid lots of 
 tedious explicit types needing to be specified and conversions to be done.
 
 - Makes it easy to write native functions using the API.  No confusing 
 excessive stack manipulation like with Lua or Squirrel.  No reference 
 counting like with Python.  Just get the values and manipulate them with a 
 program state.
 
 - Makes it really easy to expose native functions and classes to MiniD 
 through a templated binding library, similar to Pyd.  Can bind free 
 functions, classes, and in classes, constructors (even multiple constructors 
 with the same number of parameters, unlike Pyd), methods, and properties 
 (through a convention, as MiniD itself does not have explicit properties). 
 Even supports binding multiple D classes which are in an inheritance 
 hierarchy, but notably does _not_ yet support MiniD classes then inheriting 
 from those exposed D classes.
 
 == Licensing and Compatibility ==
 
 MiniD is licensed under zlib/libpng, which basically means (1) I'd like you 
 to give me credit if you use it, (2) you can't say that you made it, and (3) 
 you can modify it all you want and even release your own modified version of 
 the language, but you can't call a modified version "MiniD".
 
 MiniD is, as far as I know, only compatible with D 1 (last compiled with D 
 1.020).  Because it uses some newer features, it is not known to work with 
 GDC 0.23, but may compile with one of the newer patches.
 
 MiniD is based entirely on Tango, the alternative standard library for D. 
 MiniD was last built with Tango 0.99.
 
 MiniD is built with Bu[il]d, but should also work with DSSS.  Not real sure 
 if it works with dsss net.  DSSS is still largely a mystery to me.
 
 MiniD should compile on any platform for which there's a functional 
 compiler.  It has been developed and tested on Windows, and has also been 
 compiled and tested on Ubuntu 7.04.
 
 == Links ==
 
 The main page for MiniD is http://www.dsource.org/projects/minid.  The 
 forums are at http://www.dsource.org/forums/viewforum.php?f=94; I use the 
 forums for announcements, and you can also start discussions there.
 
 You can find information on downloading the library on the main page. 
 There's also a link to MDCL, the MiniD Command-Line interpreter, for which 
 Windows binaries are provided.  If you're on another system, you can check 
 out the trunk and compile MDCL manually.
 
 Any questions, comments etc.  Either reply here or post on the forums :) 
 
 
Awesome; great job. From a cursory look, I like what's going on there, but the things keeping me from turning away from Perl for general scripting purposes are the lack of an eval() and first-class regexes. Still, this looks like an awesome language for scripting within the context of another application, which I guess is the point. Anyways, congratulations on 1.0!
Aug 01 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Robert Fraser" <fraserofthenight gmail.coim> wrote in message 
news:f8pdsq$1p4l$1 digitalmars.com...
 Awesome; great job. From a cursory look, I like what's going on there, but 
 the things keeping me from turning away from Perl for general scripting 
 purposes are the lack of an eval() and first-class regexes. Still, this 
 looks like an awesome language for scripting within the context of another 
 application, which I guess is the point.

 Anyways, congratulations on 1.0!
Oh, but it *does* have eval! OK, so because of the design of the implementation, it can't access local variables, but it's still there in both the scripting language and the native API. Thanks for the reply :)
Aug 01 2007
parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Jarrett Billingsley wrote:
 "Robert Fraser" <fraserofthenight gmail.coim> wrote in message 
 news:f8pdsq$1p4l$1 digitalmars.com...
 Awesome; great job. From a cursory look, I like what's going on there, but 
 the things keeping me from turning away from Perl for general scripting 
 purposes are the lack of an eval() and first-class regexes. Still, this 
 looks like an awesome language for scripting within the context of another 
 application, which I guess is the point.

 Anyways, congratulations on 1.0!
Oh, but it *does* have eval! OK, so because of the design of the implementation, it can't access local variables, but it's still there in both the scripting language and the native API. Thanks for the reply :)
Ah, but since it *does* have access to 'varargs', could you not use loadString (eval's older brother of sorts) and pass the generated function the locals you need? :) ____[ MiniD ]____________________________________ | | local x, y ; | // bunch of stuff | | x, y = loadString(" | local x, y = varargs ; | // do some dynamic stuff with x and y | return x, y; | ")(x,y); |_________________________________________________ Sure its more explicit... it also means the code string doesn't have to actually know the names of the local variables; ie, you could reuse the same string for other functions, or better yet store the generated function under its own name and use it like any other function. -- Chris Nicholson-Sauls
Aug 01 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Chris Nicholson-Sauls" <ibisbasenji gmail.com> wrote in message 
news:f8qrm5$131h$1 digitalmars.com...
  ____[ MiniD ]____________________________________
 |
 |  local x, y ;
 |  // bunch of stuff
 |
 |  x, y = loadString("
 |    local x, y = varargs ;
 |    // do some dynamic stuff with x and y
 |    return x, y;
 |  ")(x,y);
 |_________________________________________________
Pretty ingenious idea :D
Aug 01 2007
parent renoX <renosky free.fr> writes:
Jarrett Billingsley a écrit :
 "Chris Nicholson-Sauls" <ibisbasenji gmail.com> wrote in message 
 news:f8qrm5$131h$1 digitalmars.com...
  ____[ MiniD ]____________________________________
 |
 |  local x, y ;
 |  // bunch of stuff
 |
 |  x, y = loadString("
 |    local x, y = varargs ;
 |    // do some dynamic stuff with x and y
 |    return x, y;
 |  ")(x,y);
 |_________________________________________________
Pretty ingenious idea :D
Well as a workaround for a technical problem, why not, but from a syntactic point of view, it's not very good (that Perl do it this way is a good indication that you should avoid it IMHO). renoX
Aug 02 2007
prev sibling next sibling parent reply BLS <nanali nospam-wanadoo.fr> writes:
Well done, allways good to see a 1.0 for D.

Jarrett Billingsley schrieb:

 == Describe the API. ==
 
 - Supports code sandboxing through the use of multiple "contexts", into 
 which libraries can be loaded.  You can create a sandbox by only loading a 
 restricted set of libraries into a context, and then running code in it.
 
 - Is templated in many places to support IFTI, and converts between native D 
 types and MiniD types in many places as well, in order to avoid lots of 
 tedious explicit types needing to be specified and conversions to be done.
 
 - Makes it easy to write native functions using the API.  No confusing 
 excessive stack manipulation like with Lua or Squirrel.  No reference 
 counting like with Python.  Just get the values and manipulate them with a 
 program state.
 
 - Makes it really easy to expose native functions and classes to MiniD 
 through a templated binding library, similar to Pyd.  Can bind free 
 functions, classes, and in classes, constructors (even multiple constructors 
 with the same number of parameters, unlike Pyd), methods, and properties 
 (through a convention, as MiniD itself does not have explicit properties). 
 Even supports binding multiple D classes which are in an inheritance 
 hierarchy, but notably does _not_ yet support MiniD classes then inheriting 
 from those exposed D classes.
Jarret, I miss some API examples. I also can not figure out how DDL fits into the picture. Bjoern
Aug 01 2007
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"BLS" <nanali nospam-wanadoo.fr> wrote in message 
news:f8pgoi$1thd$1 digitalmars.com...
 Jarret, I miss some API examples. I also can not figure out how DDL fits 
 into the picture.
Cause I haven't written them yet XD This is what I plan to be working on for the next couple of weeks: examples and documentation. DDL will come in once it's been converted to Tango. Basically what you can do now is (1) import other MiniD source code modules, (2) import MiniD modules which have been compiled to bytecode and serialized, and (3) expose native functions to MiniD from the host application. What you can do with DDL is write a library of native functions, compile them into a DDL file, and then import that DDL module at run-time into the MiniD interpreter. This makes it really easy to develop and distribute native-code MiniD libraries (think of the use of DLLs/SOs in Lua and Python).
Aug 01 2007
parent reply Sean Kelly <sean f4.ca> writes:
Jarrett Billingsley wrote:
 
 DDL will come in once it's been converted to Tango.
I think the SVN version of DDL may actually work with Tango. Eric was doing some work on it not too long ago. Sean
Aug 01 2007
parent reply Pragma <ericanderton yahoo.removeme.com> writes:
Sean Kelly wrote:
 Jarrett Billingsley wrote:
 DDL will come in once it's been converted to Tango.
I think the SVN version of DDL may actually work with Tango. Eric was doing some work on it not too long ago. Sean
It's mostly there, but I'd consider it unstable at this time, since I have yet to fully test things. -- - EricAnderton at yahoo
Aug 01 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Pragma" <ericanderton yahoo.removeme.com> wrote in message 
news:f8q921$3fh$1 digitalmars.com...
 It's mostly there, but I'd consider it unstable at this time, since I have 
 yet to fully test things.
Wheee :D
Aug 01 2007
prev sibling next sibling parent Sean Kelly <sean f4.ca> writes:
Great work!


Sean
Aug 01 2007
prev sibling next sibling parent reply Benji Smith <dlanguage benjismith.net> writes:
Very nice. If you wouldn't mind (and if you have the time), I'd love to 
read more about the design of the MiniD interpreter. Are you using a 
parser generator for the lexing/parsing? Once you have your AST, do you 
internally generate VM bytecode, or do you walk the AST? What kinds of 
optimizations do you do? Is the VM/Interpreter purely stack-based, or do 
you use simulated registers? How do you implement your dynamic typing?

Have you read any of the documentation of the parrot project? Back when 
they were publishing more regular updates, I enjoyed reading about their 
implementation details. If you're interesting in writing about your 
experiences designing and implementing MiniD, I'd be very interested in 
reading about them.

Thanks!

--benji
Aug 01 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Benji Smith" <dlanguage benjismith.net> wrote in message 
news:f8rmam$2a74$1 digitalmars.com...
 Very nice. If you wouldn't mind (and if you have the time), I'd love to 
 read more about the design of the MiniD interpreter. Are you using a 
 parser generator for the lexing/parsing? Once you have your AST, do you 
 internally generate VM bytecode, or do you walk the AST? What kinds of 
 optimizations do you do? Is the VM/Interpreter purely stack-based, or do 
 you use simulated registers? How do you implement your dynamic typing?

 Have you read any of the documentation of the parrot project? Back when 
 they were publishing more regular updates, I enjoyed reading about their 
 implementation details. If you're interesting in writing about your 
 experiences designing and implementing MiniD, I'd be very interested in 
 reading about them.
That's a good idea for a wiki page. I'll put more stuff in the "Compilation" and "Execution" sections of the spec. But in short: I wrote my own lexer/parser from scratch, based on the DMD frontend. It's a recursive descent parser. Once the AST has been generated, the compiler walks the tree and generates bytecode. The VM is a pseudo-register design. Rather, it's more like a native CPU stack, where enough stack space is allocated for a function's call frame, and then all accesses to the stack are by offsets from the function's base pointer. (If you're at all familiar with the internal workings of Lua, MiniD works the same way.) The compiler, though, does use a sort of stack machine to convert expression ASTs into the RISC-style three-op bytecodes: it pushes expressions onto the expression stack, and an operation (like add, call, etc.) corresponds to a pop, which actually writes the code. This is my own design (though I wouldn't be surprised if there were other compilers that used a similar method) and it works pretty well :D Just as an example, here's some MiniD code: local x = [1, 2, 3, 4, 5]; for(local i = 0; i < #x; i++) writefln("x[", i, "] = ", x[i]); And here's something like what it compiles to (did this in my head so it might not be exact): Constants: 0: 1 1: 2 2: 3 3: 4 4: 5 5: 0 6: "x[" 7: "] = " 8: "writefln" // local x = [1, 2, 3, 4, 5]; newarr r2, 5 lc r3, c0 lc r4, c1 lc r5, c2 lc r6, c3 lr r7, c4 setarr r2, 0, 5 movl r1, r2 // for(local i = 0; i < #x lc r2, c5 len r3, r1 cmp r2, r3 jge 6 // writefln("x[", i, "] = ", x[i]); lc r5, c6 movl r6, r2 lc r7, c7 idx r8, r1, r2 precall r3, g8, 1 call r3, 6, 1 // ; i++) addeq r2, c0 jmp -11 The opcodes: newarr is "new array", it takes the dest register and the size of the array (if known). lc is load constant (the constant table is unique to each function). setarr sets a block of registers all at once to several elements of the array, and is only used for array constructors. movl moves two values, and is always followed immediately by jlt, jle, jgt, jge, je, or jne; the cmp-j pair is executed as a single instruction. idx indexes, and takes the destination register, then the thing to index, and then the index value. precall-call are also executed as a single instruction and are used for calling a regular function. If we were making a method call, it would be a method-call pair instead. precall takes the register of where the function should go, then the source of the function, and a flag (1 or 0) as to whether an explicit context was passed. "g8" as the source means "the global whose name is stored in constant 8", which is writefln. The flag is 1, so the interpreter will automatically fill the register after the function, r4, with the function's environment as the 'this' pointer. (this is 0 when you use the "with" at the beginning of the argument list to specify an explicit context.) Then call takes the function register to call (always the same as the register in precall), the number of parameters + 1, and the number of return values needed + 1. This is again, very similar to how Lua does it. Finally addeq is the += operator, and so we're just adding 1 to i, and jmp jumps back to the comparison of the loop. Notice that like a real processor, the PC is incremented after the instruction is fetched, so jump offsets are offsets from the instruction _after_ the jump. Hope that whets your appetite :)
Aug 02 2007
prev sibling next sibling parent Alexander Panek <a.panek brainsware.org> writes:
Jarrett Billingsley wrote:
 After more than a year of brainstorming, writing, re-writing, taking ideas 
 from other languages and generally having a good time, I've come to what I 
 feel is a good place to call it 1.0.
Congratulations! I have yet to test MiniD, but from what I've seen so far it really kicks ass. <3 Keep up the good work! Best regards, Alex
Aug 01 2007
prev sibling next sibling parent reply "Stewart Gordon" <smjg_1998 yahoo.com> writes:
I don't know how I managed to last this long without investigating what 
MiniD is.  But it's such a nice idea!  I had begun myself to think of a 
similar idea.

 MiniD is based entirely on Tango, the alternative standard library for D. 
 MiniD was last built with Tango 0.99.
Considering the nature of Tango, will an application that uses MiniD still be able to use code/libraries relying on Phobos as well? Stewart.
Aug 03 2007
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message 
news:f8vdpq$232c$1 digitalmars.com...
I don't know how I managed to last this long without investigating what 
MiniD is.  But it's such a nice idea!  I had begun myself to think of a 
similar idea.

 MiniD is based entirely on Tango, the alternative standard library for D. 
 MiniD was last built with Tango 0.99.
Considering the nature of Tango, will an application that uses MiniD still be able to use code/libraries relying on Phobos as well?
Tangobos works amazingly well. I used it while porting MiniD from Phobos to Tango, and had no problems with some parts of the library being in Phobos while others were in Tango. There are some linking issues with redefinitions of some of the libc functions, but that's easy to fix by commenting out those definitions in the Tangobos headers. Of course, in a perfect world, there'd be only Tango ;) But...
Aug 03 2007
prev sibling parent reply Christopher Wright <dhasenan gmail.com> writes:
Jarrett Billingsley wrote:
 After more than a year of brainstorming, writing, re-writing, taking ideas 
 from other languages and generally having a good time, I've come to what I 
 feel is a good place to call it 1.0.
 
 == What is MiniD? ==
 
 MiniD is a scripting language written entirely in D, designed around D's 
 features and with D's semantics in mind.  It's based mainly off of Lua and 
 Squirrel, with influences from D and JavaScript.
Is there any chance of support for optional strong typing? That's my main beef with Javascript; the one time I've used it for a production system, it took six hours to do something that would have been fifteen minutes with strong typing (due to a single bug), and I never did accomplish what I set out to do. At least function arguments should be typed, or typeable, in an object-oriented language. Lua doesn't need strong typing as much because it only has primitives, functions, and tables. But MiniD is object-oriented, and the only alternative to typing is reflection.[1] Maybe some sort of 'where' clause? function do_stuff(arg1, arg2) where arg2 : ExpectedClass {} -cbw [1] And that's rather ugly and long-winded: if (!is (typeof(argument) == ExpectedClass)) assert(false);
Aug 04 2007
next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Christopher Wright" <dhasenan gmail.com> wrote in message 
news:f926br$2a08$1 digitalmars.com...
 Is there any chance of support for optional strong typing? That's my main 
 beef with Javascript; the one time I've used it for a production system, 
 it took six hours to do something that would have been fifteen minutes 
 with strong typing (due to a single bug), and I never did accomplish what 
 I set out to do.

 At least function arguments should be typed, or typeable, in an 
 object-oriented language. Lua doesn't need strong typing as much because 
 it only has primitives, functions, and tables. But MiniD is 
 object-oriented, and the only alternative to typing is reflection.[1] 
 Maybe some sort of 'where' clause?
 function do_stuff(arg1, arg2) where arg2 : ExpectedClass {}
I think you must have been reading my personal design notes :) Function parameter type constraints is a feature I've been considering for v2.0. They'd look something like this: function f(x : int, y : !int, z : int | float, w : instanceof Foo) { ... } x : int means only ints are allowed; y : !int means anything _but_ ints; z : int | float means z can take an int or a float, and w : instanceof Foo means it has to be an instance of class Foo (or any class derived from it). I also had an idea for "semi-static typing" last year when I was making the transition from static typing to dynamic typing. Basically variables could be typed (but didn't have to be), but it wouldn't go any further than one "level" of typing deep. That is, you could do: int x = 5; array a = [1, 2, "hi"]; Basic types are not really affected, but aggregate and container types are just typed to the "first level": 'a' can only hold arrays, but there's no way to specify what should be _in_ that array. Notice that a holds ints and strings. I'm wondering how feasible this would be to implement. The static typing all happens at compilation, and then the compiler could emit instructions for optimized operations, i.e. if it knows that two operands of + are ints, it can output an "iadd" instruction which skips dynamic type checking on the operands at runtime and knows that the operands are ints. Who knows, it could eventually make it in :) It'd probably be optional in order to largely preserve backwards compatibility, but it probably wouldn't be too much of a departure from the current design.
Aug 04 2007
parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Jarrett Billingsley wrote:
 "Christopher Wright" <dhasenan gmail.com> wrote in message 
 news:f926br$2a08$1 digitalmars.com...
 Is there any chance of support for optional strong typing? That's my main 
 beef with Javascript; the one time I've used it for a production system, 
 it took six hours to do something that would have been fifteen minutes 
 with strong typing (due to a single bug), and I never did accomplish what 
 I set out to do.

 At least function arguments should be typed, or typeable, in an 
 object-oriented language. Lua doesn't need strong typing as much because 
 it only has primitives, functions, and tables. But MiniD is 
 object-oriented, and the only alternative to typing is reflection.[1] 
 Maybe some sort of 'where' clause?
 function do_stuff(arg1, arg2) where arg2 : ExpectedClass {}
I think you must have been reading my personal design notes :) Function parameter type constraints is a feature I've been considering for v2.0. They'd look something like this: function f(x : int, y : !int, z : int | float, w : instanceof Foo) { ... } x : int means only ints are allowed; y : !int means anything _but_ ints; z : int | float means z can take an int or a float, and w : instanceof Foo means it has to be an instance of class Foo (or any class derived from it).
This looks very nice to me. Actually, the internal language for a project of mine does something slightly similar. (I hadn't accounted for the case you solve with ": int|float"... might have to borrow that. And the last case would be just ": #Foo".) -- Chris Nicholson-Sauls
Aug 04 2007
prev sibling parent Alan Knowles <alan akbkhome.com> writes:
For reference, ecmascript v4 (aka Javascript 2) specifications allows a 
'strict' mode where all sorts of type definitions can be defined and 
caught by the compiler / runtime etc.

It's not a high priority for me working on dmdscript, but I am using 
that as the roadmap... (I already have class syntax though and have 
fixed the scoping issues with the original code)..

Regards
Alan

Christopher Wright wrote:
 Jarrett Billingsley wrote:
 After more than a year of brainstorming, writing, re-writing, taking 
 ideas from other languages and generally having a good time, I've come 
 to what I feel is a good place to call it 1.0.

 == What is MiniD? ==

 MiniD is a scripting language written entirely in D, designed around 
 D's features and with D's semantics in mind.  It's based mainly off of 
 Lua and Squirrel, with influences from D and JavaScript.
Is there any chance of support for optional strong typing? That's my main beef with Javascript; the one time I've used it for a production system, it took six hours to do something that would have been fifteen minutes with strong typing (due to a single bug), and I never did accomplish what I set out to do. At least function arguments should be typed, or typeable, in an object-oriented language. Lua doesn't need strong typing as much because it only has primitives, functions, and tables. But MiniD is object-oriented, and the only alternative to typing is reflection.[1] Maybe some sort of 'where' clause? function do_stuff(arg1, arg2) where arg2 : ExpectedClass {} -cbw [1] And that's rather ugly and long-winded: if (!is (typeof(argument) == ExpectedClass)) assert(false);
Aug 04 2007