Froglingo

An Alternative to DBMS, Programming Language, Web Server, and File System

 

 

/*

            Case Study: Three Independent and Interactive Applications

                        Froglingo Development Association

                                    2/30/2010

 

            File Name: Sales.Frog

            The MS DOS command to inventory this application: frog -b sales.frog

            For example in the folder FOLDER having the executable frog.exe:

                        C:\FOLDER\frog -b sales.frog

 

            Description: There are 3 applications: 1) a community with residents and

            products; 2) a sales company selling the community's products to the

            people in the community; and 3) a shipping company delivering the

            products sold by the sales company.

 

            The 3 applications are hosted by a single Froglingo server.

 

            Note that the 3 applications should be managed separately in real world.

            Here we merge them together just for demonstration purpose.

 

            Also the included HTML files for web access are not used at this time

*/

 

/* Choose a password for the root user account of the Froglingo server */

passwd;

 

/* Create the user accounts for the 3 applications. Please remember the

passwords generated and displayed on the console*/

addusr www.acommunity.org;

addusr www.asale.com;

addusr www.ashipping.com;

 

/* Make the community world-accessible */

grtacc www.acommunity.org anyone;

 

/* Make the built-in account anyone world-accessible. A make-up to an feature

   not implemented in Froglingo

*/

grtacc anyone anyone;

 

/* Log into the community account and create a few sample residents and products

   More data can be added anytime in the future.

*/

login www.acommunity.org "passwd";

"//www.acommunity.org";

 

/* Create two user accounts as residents. Please remember the passwords

   generated by the command addusr.

*/

addusr dow.jone;

addusr mary.smith;

 

/*  load the index.html as the home page of the community, and make it available

    publically.

*/

load "index.html";

grtacc index.html anyone;

 

/* Log into the resident account dow.jone and create a few sample data */

login dow.jone "passwd";

"//www.acommunity.org dow.jone";

create fname = "Down";

create lname = "Jone";

create address = "23 Shields Lane, Califon, New Jersey";

 

/* Log into the resident account mary.smith and create a few sample data */

login (//www.acommunity.org mary.smith) "passwd";

"//www.acommunity.org mary.smith";

create fname = "Mary";

create lname = "Smith";

create address = "406 Rose Street, Chester, New York";

 

/* Go back to the community account to create sample products and their description

*/

login (//www.acommunity.org) "passwd";

"//www.acommunity.org";

create apple size = 1;

create milk size = 5;

create TV size = 100;

 

/* Log into the sales company to construct business logic. It is the main application of this file

*/

login (//www.asale.com) "passwd";

"[//www.asale.com]";

 

/* Define the products it sales and the sale prices */

create I_sale (//www.acommunity.org apple) price = 4.2;

create I_sale (//www.acommunity.org TV) price = 4004;

 

/* load the web page ord_form.html and its associated image files and make

   them world-accessible

*/

create INVALID_ITEM = 2;

load images;

grtacc images anyone;

load ord_form.html;

load cart.html;

grtacc ord_form.html anyone;

 

/* Create one sample order, serving as a "template" used by the order process

   An order has status, one or more than one items (with volumes); and it

   is made accessible to the shipping company only.

*/

create order (//www.acommunity.org dow.jone) 1 status = "open";

create order (//www.acommunity.org dow.jone) 1 itms (//www.acommunity.org apple) volume = 4;

create order (//www.acommunity.org dow.jone) 1 itms (//www.acommunity.org TV) volume = 1;

grtacc (order (//www.acommunity.org dow.jone) 1) (//www.ashipping.com);

 

/* Initiate one global variable ord_num; and declare 3 other functions. Note

that a data must be delcared first before it can be used as a sub-term of an

assigner.

*/

create ord_num = 0;

create add_item_to_ord;

create add_item_in_a_new_ord;

create is_item_in_stock;

 

/* is_an_item_I_sale: Do I sell the item $item? If no, stop and return client an error message */

create is_an_item_I_sale false $cust $item $volume = print (ord_form.html INVALID_ITEM) in html;

 

/* increase ord_num by $x */

create increase_ord_num_by $x = (update ord_num = (ord_num + $x));

 

 

/* If customer doesn't have an open order, then increase ord_num by 1, and take

   it as the new order number, and call add_item_in_a_new_ord to add the item

   $item.

*/

create if_cust_has_an_open_ord null $cust $item $volume = increase_ord_num_by 1, add_item_in_a_new_ord $cust ord_num $item $volume;

 

/* If customer does have an open item, the select operation, the first parameter

   of the function if_cust_has_an_open_ord, adds the requested item to the

   existing order already. The function itself doesn't have to do anything else.

   Here, a text message is provided

 */

create if_cust_has_an_open_ord $sel_result $cust $item $volume = "Item has been added into order earlier", $sel_result, "\n";

 

 

 

/* If the requested item is one of the items I sale, then continue the process.

   Note that the select operation finds the order if it does exist, and then

   call add_item_to_ord to add the item to the existing order

*/

create is_an_item_I_sale true $cust $item $volume = if_cust_has_an_open_ord (select add_item_to_ord $ord $item $volume where $ord {+ order $cust and $ord status == "open") $cust $item $volume;

 

/* add an item into a given order $ord */

create add_item_to_ord $ord $item $volume = is_item_in_stock ($ord itms $item volume != null) $ord $item $volume;

 

 

/* add the item $item to a new order: record its volume, status "open", and

   grant access permission to //www.ashipping.com

*/

create add_item_in_a_new_ord $cust $new_ord $item $volume =

            (create order $cust $new_ord itms $item volume = $volume),

            (create order $cust $new_ord status = "open"),

            (grtacc (order $cust $new_ord) (//www.ashipping.com));

 

 

/* if the given item was not added in the order earlier, then create the item

   with its volume

*/

create is_item_in_stock false $ord $item $volume =  "Item is not in order",

            (create $ord itms $item volume = $volume)

            /*print cart.html*/;

 

/* if the given item was added in the order earlier, then add the new volume

   to the existing volume

*/

create is_item_in_stock true $ord $item $volume = "item is in Order",

            (update $ord itms $item volume  = ($ord itms $item volume + $volume))

            /*, print cart.html*/;

 

 

/*  The function to be called by customers. It requires that the parameter $cust

   must be the builtin-term "signature" and a resident in the community

 

   It take 3 parameters:

            $cust, the signature of the caller, and the caller must be a resident

            $item, a product defined under //www.acommunity.org

            $volume, a number in physical space (e.g., in feet)

*/

create rec_ord $cust:[$cust isa signature and $cust  {+ (//www.acommunity.org)]

            $item $volume = is_an_item_I_sale (I_sale $item != null)

                                    $cust $item $volume;

 

/* The function is accessible by anyone */

grtacc rec_ord anyone;

 

/* the following expressions build a function req_close_ord. By calling it, users can change an order status to "closed".

*/

create if_cust_doesnt_have_an_open_ord null = "Error: you dont' have an open order\n";

create if_cust_doesnt_have_an_open_ord $ord = "The order has been closed earlier\n";

create close_ord $ord = (update $ord status = "closed");

create req_close_ord $cust:[$cust isa signature] = if_cust_doesnt_have_an_open_ord (select close_ord $ord where $ord {+ order $cust and $ord status == "open");

grtacc req_close_ord anyone;

 

 

/* User logs into www.ashipping.com to offer an interface to accept shipping orders

*/

login //www.ashipping.com "passwd";

"[//www.ashipping.com] ";

 

/* initiate itms used later */

create itms;

 

/* the transporation tool truck1 has 1000 as the maximum capacity.

   Assuming that all the products will be carried by using truck1

*/

create truck1 capacity = 1000;

 

/* the current available space in truck1 */

create avai_space = 896;

 

/* the date truck1 will deliver */

create truck1 delivery_date = '12/21/2009';

 

/* a sample order. Assuming that all the products are carried on truck1

*/

create truck1 (//www.asale.com

                          order

                      (//www.acommunity.org dow.jone)

                          1)

                   occupied_space = 104;

 

/* a temporary value holder to calculate truck space*/

create space_needed = 0;

 

/* Given the order $ord, calculate the total space needed to deliver all the

   items in the order */

create cal_space $ord = select (update space_needed =

            (space_needed + ($item volume * (mterm $item) size)))

            where $item {+ $ord itms;

 

create display_success $ord $space = "The shipping order is completed.";

 

create is_enough_space false $ord $space_to_occu  = "print display_err.html";

create is_enough_space true $ord $space_to_occu =

            (update avai_space = (avai_space - $space_to_occu)),

            (create truck1 $ord occupied_space = $space_to_occu),

            display_success $ord $space_to_occu;

 

 

/* The interface rec_ord takes one parameter:

            $ord, an order under //www.asale.com order

 

   It first calculate the space needed for the given order by calling cal_space.

   If truck1 has enough space, the shipping order is allowed. Otherwise

   it is rejected.

 

   This function is made accessible to //www.asale.com only

*/

           

create rec_ord $ord = cal_space $ord,

            is_enough_space ((avai_space  - space_needed) > 0) $ord space_needed,

            (update space_needed = 0);

grtacc rec_ord (//www.asale.com);

 

/* a test: mary.smith makes a purchase on apple */

login (//www.acommunity.org mary.smith) "fdd";

//www.asale.com rec_ord signature (.. apple) 5;

 

/* a test: the order from mary.smith is requested to be shipped */

login (//www.asale.com) "df";

"//www.asale.com";

//www.ashipping.com rec_ord (. order (//www.acommunity.org mary.smith) 1);