RapCAD imports

The syntax for importing modules into rapcad is quite different from the legacy way of doing it. I decided to break compatibility because of a number of problems with the old syntax, that arise when you want to quickly scan for dependencies. Lets first consider a valid example using the old syntax.

module foo(){
  module bar(){

The first problem with this is that the filename argument is actually an expression. If you were parsing this script to find its dependencies, the parser would have to be able to partially evaluate the script, turning str("file","name",".stl") into the string literal filename.stl. The second problem is that the import statements are nested in several sub constructs, meaning that the parser has to understand these constructs in order to extract the import module statements. Last of all the legacy way of importing seems to be inconsistent with the way ‘use‘ and ‘include‘ statements work.

My solution was to add an import statement which works as follows

import <triceratops.off> as dino;


The import statement appears at the top of the file and it doesn’t take an expression, only a string literal. It cannot be nested, and it fits with the use and include statements. The statement is followed by an ‘as‘ clause and the identifier following the ‘as‘ clause provides a name which can be used to instantiate the imported module. The module can be instantiated any number of times, just as you would any other built-in or user defined module. The module instances can of course be nested in any other construct as required, but the import declaration remains at the top of the file, and so one can easily glean which files the script depends on.

Version 0.3.0 is available this month and is capable of importing OFF files. See the Download Page for details.