Skip to content

Instantly share code, notes, and snippets.

@clairvy
Created September 3, 2010 11:01
Show Gist options
  • Save clairvy/563754 to your computer and use it in GitHub Desktop.
Save clairvy/563754 to your computer and use it in GitHub Desktop.
;; This config was generated using ensime-config-gen. Feel free to customize its contents manually.
(
:server-root "/usr/local/ensime/"
:project-package "com.myexample"
:use-sbt t
)
.ensime
project/boot
target/scala_*
scall.zsh
#compdef scall
function _scall () {
_arguments : \
'-h[Show message and exit]' \
'-e[Specify expression to run with each line]:Expression' \
'-B[Specify expression to run on begin of program]:Expression' \
'-E[Specify expression to run on end of program]:Expression' \
'*:argument:_files'
}
#Project properties
#Fri Sep 03 00:05:18 JST 2010
project.scratch=true
project.name=test
sbt.version=0.7.4
project.version=1.0
build.scala.versions=2.8.0
project.initialize=false
package com.myexample
object Scall {
import scala.tools.nsc._
import scala.io._
def main(args : Array[String]) {
var begin = "()=>Unit"
var end = "()=>Unit"
var expression = "(l:String)=>println(l)"
def usage {
println("scall [options...] [files...]")
println("options:")
println(" -e program : one line of program ")
println(" -B program : like -e, but run first and once")
println(" -E program : like -e, but run first and once")
println("unless specified files, it use stdin for input.")
exit(1)
}
def take(e: Iterator[String]) = if (e.hasNext) e.next else null
val e = args.iterator
var files : List[String] = List()
while (e.hasNext) e.next match {
case "-B" => begin = take(e)
case "-E" => end = take(e)
case "-e" => expression = take(e)
case "-h" => usage
case file => files = file :: files
}
val interp : Interpreter = new Interpreter()
val script = "((" + begin + "), (" + expression + "), (" + end + "))"
var result : (()=>Unit, (String)=>Unit, ()=>Unit) = null
interp.eval[(()=>Unit, (String)=>Unit, ()=> Unit)](script) match {
case Some(ret) => result = ret;
case _ => println("compile error");exit(1);
}
result._1()
(if (files.length > 0) files.map(f=>Source.fromFile(f)) else List(Source.stdin)).foreach(f=>f.getLines.foreach((l:String)=>result._2(l)))
result._3()
}
}
#!/usr/bin/env zsh
# -*- coding: utf-8; -*-
alias scall="scala -cp $HOME/oneliner/target/scala_2.8.0/classes com.myexample.Scall"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment