java2tcl - Java to XOTcl source code translator
This is an automated tool to translate Java programs to Tcl (needs XOTcl): http://txl.ca/txl-resources.html (search for Tcl). The translator is based on TXL (http://www.txl.ca ), a quite general program transformation system.
26.12.2008 - Windows binary bug fixed
//Brewing Java: A Tutorial Copyright 1995-1998, 2000-2002, 2004-2006 Elliotte Rusty Harold public class Website { public String name; public String url; public String description; public static int site_count = 0; public Website() { site_count = site_count + 1; } public void print() { System.out.println(name + " at " + url + " is " + description); System.out.println("Number of class instances: " + site_count); } public static void main(String args[]) { Website w = new Website(); w.name = "Jorika"; w.url = "http://jorika.edu"; w.description = "Really cool!"; w.print(); Website w2 = new Website(); w.name = "Foggi 4"; w.url = "http://foggi4youevery.fa"; w.description = "Foggi file!"; w.print(); } }
becomes the following XOTcl code:
package require XOTcl namespace import ::xotcl::* Class create Website_metapapa -superclass {Class} -slots { Attribute site_count -default 0 } Website_metapapa create Website -superclass {Class} -slots { Attribute name -default "" Attribute url -default "" Attribute description -default "" } Website proc main {args} { set w [Website Website] $w set name "Jorika" $w set url "http://jorika.edu" $w set description "Really cool!" $w print set w2 [Website Website] $w set name "Foggi 4" $w set url "http://foggi4youevery.fa" $w set description "Foggi file!" $w print } Website proc Website {} { # #create new object set obj [Website new] # #call the constructor $obj Website_body # #return new object after constructor's work is done return $obj } Website instproc Website_body {} { [my class] set site_count [expr [[my class] set site_count] + 1] } Website instproc print {} { puts [concat [my set name] " at " [my set url] " is " [my set description]] puts [concat "Number of class instances: " [[my class] set site_count]] }
See the package for more samples.
Please leave your comments here...
See also Translating Java to Tcl.