Skip to content
Browse files

[fix] opadoc/manual.src: move exposed where they should be

  • Loading branch information...
1 parent 2d12f94 commit 3013e32f76d93bb801d884cca0a2a05510949f80 @OpaOnWindowsNow OpaOnWindowsNow committed
Showing with 28 additions and 9 deletions.
  1. +28 −9 opadoc/manual.src/opa_binding_examples/opa_types/dbm.opa
View
37 opadoc/manual.src/opa_binding_examples/opa_types/dbm.opa
@@ -26,35 +26,54 @@ dbm dbm =
_ = System.at_exit(function () { %%dbm.close_db%%(dbm) })
dbm
-function result(string) {
- #result = string
+
+/**
+ * Client interface to the Db
+**/
+exposed
+function find_person(name) {
+ %%dbm.find_person%%(dbm, name);
+}
+
+exposed
+function add_person(person) {
+ // Because this function is exposed, it should check that person is well formed.
+ // e.g. name is not too long ...
+ %%dbm.add_person%%(dbm, person);
}
+
+
/**
* Find an entry in the ndbm from the contains of the Name box
**/
-exposed function action_find() {
+function action_find() {
Dom.clear_value(#age);
Dom.clear_value(#email);
name = Dom.get_value(#name)
- match (%%dbm.find_person%%(dbm, name)) {
+ match (find_person(name)) {
case { some: person }:
Dom.set_value(#age, string_of_int(person.age));
Dom.set_value(#email, person.email);
void
- case { none }: result("\"{name}\" Not-found")
+ case { none }:
+ result("\"{name}\" Not-found")
}
}
+function result(string) {
+ #result = string
+}
+
/**
* Submit the truplet in the ndbm
**/
-exposed function action_submit() {
+function action_submit() {
name = Dom.get_value(#name)
age = Parser.int(Dom.get_value(#age)) ? 0
email = Dom.get_value(#email)
person = ~{ name, age, email }
- %%dbm.add_person%%(dbm, person);
+ add_person(person);
Dom.clear_value(#name);
Dom.clear_value(#age);
Dom.clear_value(#email);
@@ -69,8 +88,8 @@ exposed function action_submit() {
the_captain = "The Captain"
the_question = "What is the age of \"{the_captain}\" ?"
-exposed function action_captain() {
- match (%%dbm.find_person%%(dbm, the_captain)) {
+function action_captain() {
+ match (find_person(the_captain)) {
case { some: person }:
result("The captain is {person.age} years old")
case { none }:

0 comments on commit 3013e32

Please sign in to comment.
Something went wrong with that request. Please try again.