Blog Home

What Does This Line of Code Do?

Thu Aug 11, 2011

As all good posts start with a quick to-the-point intro; here goes this one. Can anybody tell me what this line of code does? And what language is it in?

(do ((i 0 (+ i 1))) ((= i l))
        (set! en (list-ref allEntities i))

Obviously it’s a loop (that part is not hard) and it’s in the Scheme Programming language. Although it’s easy to recognize when you see it, it’s not that trivial to write from scratch. I’ve personally been using Scheme for ten years now (it’s the scripting language of our ACIS kernel) and I still have to go back to reference material in order to write a loop if I’m not using Scheme’s map function.

So why are we discussing this? Well, we’re at a point with the CGM modeling kernel in which we are adding scripting functionality to the kernel and we are in the process of choosing a language. In this case the decision is between Python, JavaScript and yes, Scheme (old habits die hard).

But I have to digress a bit before we discuss the scripting language itself. It’s really not in itself, the problem. Actually, what is the problem? Well, we need easy access to the modeling engine so one can quickly test and code geometric modeling works flows. (Example; build a block and fillet and edge.) We want to do this from a scripting language for the obvious reasons of not re-compiling, etc. However to do this efficiently, it’s the programming interface to the CGM kernel that’s important. In the case of ACIS we have a collection of high level functions we call "Scheme extensions" that have been bound to the Scheme programming language (they’re actually written in C++). These functions sit over the standard ACIS C++ interface and allow us to perform commands such as constructing a block:

(define block (solid:block (position 0 0 0) (position 10 10 10)))

This functional interface has many of the qualities that we originally intended; brief, declarative / procedural, and all inclusive. (Specifically, the viewport and part management gets updated at the end of each call). Now, we could have bound the functions to any scripting language, we just chose Scheme at the time. (We have a functional interface into the modeler, so we picked a functional language). In the end, I’m not saying the scripting language is not important for our purposes . . . we just need to develop the context of how we are scripting; and what extensions we are using.

Today, we’re at the same crossroads with CGM. We’re working on the modeler’s higher level functions; writing them in C++ but we have to choose again, the scripting language of preference. In doing so we made a comparison of the languages in consideration:

script chart

This is far from being an exhaustive comparison but it should include the main points. But back to the beginning of the post. . . how easily can one write a for loop? What language has the broadest understanding by our user customer base? What language supports on-the-fly, easy, command line typing? (And in what programming paradigm would you use to do this? Functional, procedural or OO?) In what language can you easily read a script someone else wrote two years ago? At the end of the day, these are the key questions.

Your thoughts? What language would you choose?


Tags: 3D Modeling