One might assume that in order for Schlep-dialect code to map to these three languages [C, C#, and Java], the Schlep-dialect must manifest the worst limitations of each language; but translation can actually rectify some of these limitations.
If I had to pick one practical feature of Scheme which elevates it above other languages, it would be internal definitions. The Algorithmic Language Scheme allows procedure definitions (using define
, letrec
, and named-let
) inside of other procedures, which none of C, C#, or Java does. Internal definitions allow calls of internal procedures with a small number of arguments to replace the common alternatives:
- duplication of code, or
- top-level definitions and calls passing large numbers of arguments.
goto
statement. The restriction to the tail-position does not allow internal recursion other than tail-recursion; but this facilitates use of internal procedures in many situations which would otherwise force less desirable practices. Java lacks a `goto' statement. Tail-called internal procedures are instead implemented using while (true)
, continue
, and break
with labels. The resulting Java code is not as readable as the original Scheme-dialect; but that loss in clarity is balanced by greater expressive power.
Schlep-example gives an example of a procedure with an internal procedure and how Schlep translates this procedure into C, C#, and Java.
Well done.
ReplyDeleteSchlep for Javascript would be wonderful (slightly related note: Javascript is stepping on the server side as well).
Can you supply the JavaScript equivalent of Schlep-example?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHere it is, along with a speed performance check (building on Lazutkin's).
ReplyDeletescm2js would be a bounty, since it would solve the javascript recursion issue while providing best speed performance.
One can also do the tail optimization in Javascript directly. Comments and suggestions welcome.
ReplyDelete