The code got mangled in the posting. Here it is again. TEST=$(cat <<"END" String key1 = ""; String key2= ""; TwitterFactory factory =new TwitterFactory(key1,key2); Twitter twitter = factory.getInstance(); User user = twitter.verifyCredentials(); List<Status> statuses = twitter.getHomeTimeline(); screenName = user.getScreenName(); text = status.getText(); END) echo "$TEST" | perl -ne ' s/=/ = /g; # Put spaces around = s/\s+/ /g; # Remove multiple spaces s/^\s+|\s+$//g; # Trim s/,/ /g; # Remove commas
# Handle var = new Obj(); # Handle var = obj.method(); # Handle var = value; s/.*?(\S+) = new (\S+)\(([^\)]*)\);/(def $1 (new $2 $3))/; s/.*?(\S+) = (\S+)\.(\S+)\(([^\)]*)\);/(def $1 (.$3 $2 $4))/; s/.*?(\S+) = (.*);/(def $1 $2)/; s/\s+\)/)/g; # Cleanup print qq{$_\n};' On Sat, Oct 31, 2015 at 1:35 PM, Asim Jalis <asimja...@gmail.com> wrote: > On Wednesday, June 18, 2008 at 4:32:01 PM UTC-7, kyle smith wrote: >> >> Is it possible to automatically convert java code to clojure? If so, >> would someone like to volunteer to write it? > > > I frequently want to quickly translate code snippets from Java to Clojure > to test out an API. > > For example Twitter4J has some code snippets in Java that would be more > useful for me in Clojure. > > For this I use a Perl one-liner to translate the kind of simple code that > occurs in API snippets. > > Here is the Perl translator with a simple test case. > > TEST=$(cat <<"END" > > String key1 = ""; > > String key2= ""; > > TwitterFactory factory =new TwitterFactory(key1,key2); > > Twitter twitter = factory.getInstance(); > > User user = twitter.verifyCredentials(); > > List<Status> statuses = twitter.getHomeTimeline(); > > screenName = user.getScreenName(); > > text = status.getText(); > > END) > > echo "$TEST" | > > perl -ne ' > > s/=/ = /g; # Put spaces around = > > s/\s+/ /g; # Remove multiple spaces > > s/^\s+|\s+$//g; # Trim > > s/,/ /g; # Remove commas > > > > # Handle var = new Obj(); > > # Handle var = obj.method(); > > # Handle var = value; > > > > s/.*?(\S+) = new (\S+)\(([^\)]*)\);/(def $1 (new $2 $3))/; > > s/.*?(\S+) = (\S+)\.(\S+)\(([^\)]*)\);/(def $1 (.$3 $2 $4))/; > > s/.*?(\S+) = (.*);/(def $1 $2)/; > > > > s/\s+\)/)/g; # Cleanup > > print qq{$_\n};' > > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.