Return to overview Return to Application List

How to user clCalculator from your application

If you will call clCalculator and use macro function, you can use hold evaluator for your application with appliction identifire in URI of Intent.

How to start application

When launch your application, send Intent to clCalculator to create evaluator.

action
Intent.ACTION_INSERT
data
"lisp://<identifier of your application>"

Example

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	// Identifier of my application is "to.clishna.iplus.MyApplication"
	Intent i = new Intent(Intent.ACTION_INSERT, Uri.parse("lisp://to.clishna.iplus.MyApplication"));
	startActivity(i);
}

When clCalculator received intent, start service and create evaluator for your application.

How to finish application

When your application will shutdown, send Intent to delete evaluator. If you not delete evaluator, Service is staying and use memory on device.

action
Intent.ACTION_DELETE
data
"lisp://<identifier of your application>"

Example

@Override
public void onDestroy() {
	Intent i = new Intent(Intent.ACTION_DELETE, Uri.parse("lisp://to.clishna.iplus.MyApplication"));
	startActivity(i);
	super.onDestroy();
}

Evaluate expression

Method of evaluate expression is same single-evaluation. send intent with ACTION_RUN. If evaluate succeeded, return RESULT_OK and include result with extra RESULT.

Example

private void callClCalc() {
	Intent i = new Intent(Intent.ACTION_RUN, Uri.parse("lisp://to.clishna.iplus.MyApplication"));
	i.putExtra("expression", "(+ 1 2 3)");
	startActivityForResult(i, 0);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	String result;
	if(resultCode == Activity.RESULT_OK) {
		// returns 6.
		result = "SUCCESS: " + data.getStringExtra("result");
	} else {
		result = "FAILED: " + data.getStringExtra("error");
	}
	Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
}

Define function

This is not compatible with LISP.

If you will define function, evaluate setq function and lambda function. setq function is define Variable. lambda function is returns function object from expression.

Example

private void defineExpression() {
	Intent i = new Intent(Intent.ACTION_RUN, Uri.parse("lisp://to.clishna.iplus.MyApplication"));
	//define expression (+ x y) named "tasu"
	//"tasu" means "add" in Japanese.
	i.putExtra("expression", "(setq tasu (lambda (x y) (+ x y)))");
	startActivityForResult(i, 0);
}

private void addTwoValue() {
	Intent i = new Intent(Intent.ACTION_RUN, Uri.parse("lisp://to.clishna.iplus.MyApplication"));
	//evaluate add two values.
	//this expression returns 3
	i.putExtra("expression", "(tasu 1 2)");
	startActivityForResult(i, 0);
}

Return to overview Return to Application List