KRL Build 424: Functions and Array Operators
Posted by phil in Uncategorized on February 8, 2010
The latest build of the Kynetx Rule Language (KRL) provides a significant upgrade in capability with the addition of functions. We’ve also added some new array operators that take advantage of functions to make using arrays easier.
KRL supports functions as first-class objects in the expression language. KRL supports only anonymous functions, but they can be given names by binding them to a variable in a declaration. Here’s an example:
pre {
add5 = function(x) {
x + 5
};
}
Functions are evaluated statically (e.g. the environment they are defined in, not the environment they are executed in determines the binding of free-variables) and can be recursive. Here’s an example of a recursive function in KRL:
pre {
fact = function(n) {
(n <= 0) => 1
| n * fact(n-1)
}
}
Functions are declared using the keyword function and contain optional declarations followed by a single expression that returns the result of the function when executed. To see this,
consider the following example which uses Newton’s method to calculate square roots (taken from Section 1.1.8 of Structure and Interpretation of Computer Programs):
sqrt = function(x) {
average = function(x,y) { (x + y) / 2 };
good_enough = function(guess, x) {
v = (guess * guess) - x;
v < 0.01 && v > -0.01
};
improve = function(guess, x) {
average(guess, (x / guess))
}
sqrt_iter = function(guess, x) {
good_enough(guess, x) => guess
| sqrt_iter(improve(guess,x), x)
};
sqrt_iter(1.0, x)
}
Functions can return functions as values and functions can be passed as the arguments to other functions and operators in KRL. The following example defined a generalized summation function that sums the numbers from a to b incrementing using inc and applying the function f to each term:
sum = function(f, a, next, b) {
(a > b) => 0
| f(a) + sum(f, next(a), inc, b)
};
inc = function(x) { x + 1 };
cube = function(x) { x * x * x };
sum_cubes = function(a, b) {
sum(cube, a, inc, b)
}
We could define a function that creates incrementor functions. When given a number, it returns a function that increments by that value:
inc_generator = function(n) { function(x){ x + n } };
inc = inc_generator(1);
inc_by_2 = inc_generator(2);
inc_by_25 = inc_generator(25);
Being able to write functions adds significant power. More so with some of the other languages changes we have in mind for the next few months.
Weve also added several new array operators in recent builds. Most notably, array references now work as follows:
a = [1,4,3,6,5]; b = a[1]
This would bind the value 4 to the variable b. Note that array references only work for arrays of one-dimension, so c[1][2] is not allowed (presuming c is an array of arrays).
In addition, there are a number of new operators available for arrays.
The following array operators are now available (in addition to length which has been previously available):
sort– sorts the array. With no argument, sorting is done in ascending order. The argument"reverse"causes sorting to happen in descending order. The argument can also be a function that takes two argument and returns a boolean value which will be used as the comparison function for the sort.filter– filters an array, producing a new array. The operator takes a function argument that takes a single parameter and returns a boolean value. The return array contains elements for which the function returns true.map– modfies an array from mapping a function to each member of the array. The operator takes a function argument that takes a single parameter and returns any value. The array returned frommapis the result of applying the function to each member of the original array in turn, collecting the results into a new array.head– returns the first element of an array without modifying the array.tail– returns an array that is identical to the orginal array except without the first member.
You could use these like so:
pre {
f = function(x) { x < 4 };
g = function(y) { y * 2 };
a = [1,4,3,6,5];
b = a.sort(); // returns [1,3,4,5,6]
c = a.filter(f); // returns [1,3]
d = a.head(); // d has the value 1
e = a.map(g); // e has the value [2,8,6,12,10]
}
Operators are fairly easy to add and handy to have, so if you have ideas for other operators, on arrays, strings, and so on, just let us know.
KRL Name Space Update
Posted by sog in Uncategorized on February 4, 2010
From this point forward, you must only use qualified (e.g. namespaced) functions in predicate positions (like referer:search_engine_referer()). The documentation has been updated to reflect these changes.
Kynetx Developer Program Vision Comes to Life with More Than 800 New Apps
LEHI, Utah, January 22, 2010–(BUSINESS WIRE)–Kynetx is leading the client-side revolution with its unparalleled development platform and program. At the heart of the platform is a rules-based language that allows developers to build entirely new web experiences that are cross-site, cross-platform and respond to context in the user’s environment. By leveraging this unique platform, the Kynetx developer program has already garnered more than 300 developers resulting in over 800 applications.
“Unlike any other platform, Kynetx offers developers the technology to easily resolve data mismatches coming from fractured sources of information. This capability results in a new breed of apps that act as powerful context-aware mash-ups,” says Stephen Fulling, Kynetx co-founder and CEO. “Information is only powerful if it touches you when and where you need it…in context. Kynetx gives developers the tools they need for connecting the dots.”
Richard Miller, a lead developer at FamilyLink.com, used the Kynetx Development platform to create a prototype application with the power to extend FamilyLink’s functionality to sites across the web, including Facebook, Gmail, LinkedIn, and Twitter. In just a few days, he crafted the prototype application that extends the experience of FamilyLink users when looking for relatives, adding relatives or communicating with them beyond the FamilyLink site.
“This is exactly the kind of viral growth and entrepreneurial innovation we were hoping would come out of our Developer Program,” Fulling continued. “Richard read a blog post about us, signed up, and was writing a ground-breaking app in minutes. The Kynetx Developer Program offers unparalleled tools and infrastructure to help unleash developers’ imaginations. Clearly, that’s what Richard Miller has done.”
Kynetx recently increased its “mash-up” capabilities with new Twitter API support. The Kynetx Rules Language now integrates with the Twitter API, using Twitter’s OAuth scheme, giving developers the ability to create Kynetx applications that can easily access Twitter data.
“The Twitter upgrade opens a myriad of possibilities for our Developer Program,” says Dr. Phillip Windley, Kynetx CTO. “Using Kynetx, you can create and deploy an app in minutes that understands and responds to Twitter data on any website or web-enabled device.”
Kynetx also offers semi-annual conferences designed for developers to explore ideas and learn from the experts, face to face. The next Kynetx Impact conference is scheduled for April 27th-28th in Salt Lake City. More information and registration can be found at www.kynetx.com.
To sign up for the Kynetx Developer program go to www.kynetx.com.
Demonstration of the Family Link app can be found at http://richardkmiller.com/860.
About FamilyLink
FamilyLink provides the platform for the family social experience. Family members can create family-generated content, preserve interactions, add historical content and communicate across Facebook, e-mail, chat and the Web. FamilyLink is a top 100 Web site and has more than 60 million users, 20 million monthly active users and more than 1 million daily active users. FamilyLink has been the top family application on Facebook since 2007. FamilyLink also leverages its content relationships to provide valuable historical family content. Families can search more than 1.2 billion names to find, tag and integrate ancestors. To learn more about FamilyLink go to www.familylink.com.
About Kynetx
Founded in 2007, Kynetx is a private company that has developed a proprietary rules-based development platform that is the first infrastructure to support the “purpose-centric” web metaphor that is driving the next era of software services and Internet applications. Kynetx offers a developer program that gives programmers access to technology that helps them create cross-platform, context and user-aware apps that stretch across the web.
Contacts:
For Kynetx
Snapp Conner PR
Cheryl Snapp Conner, 801-994-9625
cheryl@snappconner.com
or
FamilyLink
Stephanie Rogers, Steph@familylink.com
Using OAuth to Access Twitter from KRL
The latest build (Build 391) of the Kynetx Rule Language (KRL) includes support for accessing Twitter data intrinsically within the language. Integrating interesting data with KRL is an important part of what makes the language so useful for building cross-site applications that mash-up data and user interactions. But what’s really interesting about this release is that we’re using OAuth to access the Twitter API and have built primitives into the language for dealing with the Twitter OAuth interaction to save developers from doing it.
Not only are we making it easy for developers to write apps that use Twitter, but this is also the first time that end users will see significantly different behavior from an app than their friend might. An app that uses the Twitter library will use my Twitter data for me and your Twitter data for you. Using OAuth, Kynetx apps can now be personalized.
Using Twitter data inside a KRL app generally involves two KRL patterns: authorize then use and initialize then populate
In the authorize then use pattern, a rule is put in place to check if the app is authorized to take a certain action and, if not, do what is necessary to complete the authorization. What makes this work is using the rule postlude to ensure that the rest of the rules (which presumably rely on the authorization) don’t run. Here’s an example from an app I wrote to demonstrate using the the new Twitter library:
rule auth is active {
select using ".*" setting ()
if(not twitter:authorized()) then
twitter:authorize()
with opacity=1.0 and
sticky = true
fired {
last
}
}
Notice that this rule only fires if the predicate twitter:authorized() is false. The action, twitter:authorize(), is what initiates the OAuth ceremony. The action will pop up a notification in the user’s browser that looks like this:
The postlude of the rule (fired {...}) runs the last statement if the rule fires to ensure that nothing else happens. Of course, if the app is authorized, the rule doesn’t fire, the OAuth ceremony is not initiated, the last is never executed, and the remaining rules in the ruleset are evaluated.
The initialize then populate pattern is important any time you’re working with complex data. With complex data, you will frequently need to do something for each component of an array. That’s what the foreach statement does as part of the rule selector: executes a rule once for each member of an array.
The problem is that if we use a foreach to loop over the tweets we get back and use notify to place them on the page, we’ll end up with one notification box for each tweet. Not very pretty.
A better solution is to use a rule to place the notification box (the initializer) and another rule to loop over the tweets and place them in the notification box (the populater).
Here’s the initialization rule:
rule init_tweetdom is active {
select using ".*" setting ()
pre {
init_div = <<
<div id="tweet_list">
</div>
>>
}
notify("Friends Tweets", init_div)
with sticky=true and
opacity = 1.0
This is a pretty simple rule that places an empty notification box on the page.
The real work is done by the populating rule:
rule populate_tweetdom is active {
select using ".*" setting ()
foreach tweets setting (tweet)
pre {
text = tweet.pick("$..text");
div = "<div style='background-color:#666;margin:2px'>" +
text +
"</div>";
}
append("#tweet_list", div)
}
This rule loops over the tweets, grabs data out of them using pick, and appends the result to the div in the notification box.
The tweets variable was set in the global block:
tweets =
twitter:authorized() => twitter:friends_timeline({"count": 8})
| [];
After you’ve gone through the OAuth ceremony at Twitter, wherever you run this app, you will see a box like this that contains the last eight tweets from your friends timeline on Twitter. Here’s the results for me:
Of course, if you run this app, either by card or bookmarket, you’ll see the results from your friends timeline.
Craig Burton has created a nice tutorial about how all this works. There’s some important data in the tutorial about how to get the keys from Twitter for your application. The library is also well documented and the source code for the ruleset is available.
The ability to personalize apps by appealing to personal data elsewhere on the Web is a huge step forward for KRL. Look for other APIs to be embedded in KRL in the near term and, eventually, more general support for OAuth so that developers can use any OAuth protected data source.
UtahPolitics.org All Over the Web
Since 2003, I’ve been running a site called UtahPolitics.org. The site started off as a blog on which I and others posted articles. When I started UtahPolitics.org there was some speculation about my motives. But my motives are simple: create a place I can experiment with new media in an arena that interests me.
Last year, in an effort to continue the experiment, I put up a retweeter for UtahPolitics.org that would retweet any tweet from friends of the @utahpolitics account that contained the tag #utpol. When I did that I also morphed the web site–imperfectly–to a site that just aggregated those tweets. The idea was to move the discussion off of UtahPolitics.org and onto Twitter.
The problem with this is that it’s sometimes difficult to follow the thread of a conversation, particularly those about particular pages on the Web. To try to solve that problem, I’ve build a Kynetx app that will show all the #utpol tweets about page on that page when you visit it. Here’s a picture to show you what I mean:
The box on the right is showing any tweets that reference the page its on and contain the tag #utpol. Right now it’s tweets by anyone. If that gets to be a problem, I’ll restrict it to friends of @utahpolitics so that I have a way to block people.
I’m hoping that you’ll use this app to follow Utah Politics during the next legislative session and contribute to the Twitter discussion about specific bills or newspaper articles. Using this app and your Twitter account, you can comment on legislative pages, newspaper pages, and so on. Anyone else who has the app will see your tweets and be able to respond on the page.
You can use this app in one of three ways:
- Download the AzigoLite Card selector and install the Utah Politics card – this is the most flexible solution since once you have the card selector installed, you can also use other Kynetx apps without any further downloads. Just install the card and go.
- Install a browser extension – this is probably the fastest and most convinient way to get going. Just download the right extension for the browser you want to use (or several if you regularly use more than one browser) and you’re good to go. The following extensions are available:
- Use a bookmarklet – this is the simplest, but has the drawback of working only when you click on it. You may not always remember to do so and will miss out on people’s comments. To use the bookmarket, drag this link to your bookmark bar at the top of your browser
UtahPolitics Bookmarklet
Once you’ve got something installed, head on over to House Bill 10 on the Utah Legislature’s page to see it in action. I’ve left some test tweets there.
You don’t need to do anything special to use it. Just tweet about a page and include the tag #utpol. All the tweets about a particular page will show up in the app–even from people who don’t have it installed. This is an assymetrical communication tool. Note, if there are no tweets about a particular page, you won’t see anything–the app doesn’t do anything in that case.
If you’re interested in how this was made, I’ve made the source available on the app page. Feel free to ask questions or just copy it and build your own–Kynetx developer accounts are free.
I’m excited to see how this works–I hope it leads to some interesting discussions about Utah politics and gives some insight about how apps like this one–that work on multiple Web sites–can be made more effective.
Optini and Kynetx Pioneer New Online Solution for Network Marketing
Lehi, Utah, January 4, 2010—One of network marketing’s most successful experts and leaders, Craig Bryson has joined executives John Wright (President) and Joseph Watson (CTO) to create a new company Optini which is focused on user centric solutions which utilizes Kynetx (www.kynetx.com) technology. Optini’s Vu Platform makes direct selling easier and more efficient with permission-based web modules that let marketers tailor the web experience for downline distributors and customers. Integrating data from multiple sources, the Optini Vu Platform gives members a personal, relevant and anticipated experience that increases the satisfaction and efficiency of commerce in the multilevel marketing (MLM) industry.
Direct selling is a $26.9B industry in the U.S. according to the Direct Selling Association (DSA). In the U.S. alone there are more than 15.1M distributors/members—yet the greatest deterrent to new participants is the need to sell face-to-face, often by pitching to a finite group of family and friends (known as a “warm market”). Optini’s products and services allow network marketers to use an automated system that helps them quickly create a larger warm market by facilitating selling across any web site or web-enabled device. By leveraging the places people spend time online anyway (e.g. social networking sites, search engines, etc.), Optini’s Vu Platform reduces the need to sell face-to-face and diminishes the number one reason people say “no” to joining an MLM.
“The Vu platform has the potential to revolutionize the MLM industry by opening the door for the thousands of people who have never considered direct selling before,” Bryson said.
The Kynetx rules-based development platform is gaining traction as a catalyst to the new “Purpose-Based Web” that lets users shape the web to their desired experience in a private and secure way. The new applications can span multiple URLs appearing where users already spend time (like on search engines and social network sites). The ability for Kynetx apps to stretch across the web, (and onto web-enabled devices), gives users a more efficient, enjoyable way to navigate the web (and to conduct business online).
“We are extremely excited about the new horizons Kynetx has opened for user-driven selected apps that create more efficient buying and selling relationships on the web,” said John Wright, Optini co-founder and President. “Kynetx is allowing us to drive online commerce in entirely new ways. We are thrilled to be the exclusive provider of this new technology for the growing network marketing world. Marrying the MLM know-how of Optini with the new breed of Kynetx technology will create selling tools that have never existed before.”
“The Optini Vu Platform is a great example of the new client-side applications that are emerging since our launch of the Kynetx platform at our Impact Conference last October,” said Stephen Fulling, Kynetx co-founder and CEO. “We congratulate Optini for their game-changing application of Kynetx technology in the direct selling space. We look forward to seeing the ways Optini uses our technology to change the face of Network Marketing.”
About Optini
Optini, www.optini.com, is changing the face of network marketing through permission based online marketing tools based on Kynetx technology. Optini’s flagship product is the new Optini Vu Platform to increase the satisfaction and efficiency of conducting multilevel commerce online. Optini’s involvement in the Direct Selling/MLM industry is complimentary to their broader focus on other industries including membership services, ILM (Interactive Local Media, ISP (Internet Service Providers), Publishing, etc.
About Kynetx
Founded in 2007, Kynetx is a private company that has developed a proprietary rules-based development platform that is the first infrastructure to support the “purpose-centric” web metaphor that is driving the next era of software services and Internet applications.
### PR Contact Information for Kynetx:
Cheryl Snapp Conner or Josh Berndt
Snapp Conner PR
801 994-9625
cheryl@snappconner.com or josh@snappconner.com
PR Contact Information for Optini:
David Politis
Politis Communications
801-523-3730
dpolitis@politis.com
See Business Wire posting here.
Hot Startups to Watch in 2010
I’m watching hundreds of startups, have at least one list of them over on Twitter (500 startups are on that one) and will be starting other lists in 2010 but I’ve been watching the trends on Twitter of what people are talking about and here are 25 startups to watch.
Why?
Because they are the best of breed examples of trends that are bigger than them. Is this list complete? No way, but it gives you a good starting point on some companies who you should be trying out and watching.
I have 15 other companies that I’ll be posting over the weekend, please let me know if you have any companies you are watching and we can watch them together.
#8. Kynetx. Crunchbase entry. Twitter account. Video with founders explaining why Kynetx is an interesting real-time development system. Why is it important? Because it lets developers augment websites and search engines for their customers. AAA can add new data to Google.com for its members, for instance.
Read entire article.
Syntax Change to Action Labels
We will release a syntax change to action labels to accommodate a reuse of the : as a namespace separator for actions. The old action label syntax looked like this:
foo: notify("Hello", "A Note to say hello")
The new syntax uses => like so:
foo => notify("Hello", "A Note to say hello")
We don’t believe that action labels have found widespread use based on a review of the log files and consequently will release this syntax change tomorrow (Jan 7).
Kynetx Maintenance Window 1/9/2010
Date: 1/9/2010
Start Time: 0000 MST
End Time: 0500 MST
Duration: 00:05:00 (DD:HH:MM)
Outcome: Successful
Maintenance Summary:
Kynetx will be upgrading the OS versions on all of its servers from Fedora Core 8 to CentOS 5.4_final. In order to perform the upgrade, the host servers will need to be taken offline in turn and upgraded. This maintenance will be one of many over the course of the next ten (10) days.Impact Statement:
The following sites and services will be unavailable during the maintenance window due to OS upgrade and rebooting activities.- Corporate website – www.kynetx.com
- Corporate blog – code.kynetx.com
- Corporate news – news.kynetx.com
- Developer website – developer.kynetx.com
- Corporate email – mail.kynetx.com (POP/IMAP/SMTP)
- Appbuilder – appbuilder.kynetx.com
- Accounts – accounts.kynetx.com
- Appdirectory – appdirectory.kynetx.com
Maintenance Plan:
- Shutdown virtual or physical server being worked on
- Create backup copy of VM images on server
- Upgrade OS on host servers
- Restore VM images to host servers
- Start guest images and test
Roll Back Plan:
- Restore system from backup
- Test system
- Close maintenance window
Kynetx KNS Server Outage Report 12/31/2009
Start Time: 1606
Stop Time: 1635
Duration: 00:00:29 (DD:hh:mm)
Severity: Sev2 (Degraded Performance)
Incident Summary:
The KNS platform experienced degraded performance for a period of 29 minutes on 12/31/2009 due to high system load. This load was due to an ad-hoc software update job which was scheduled by the Kynetx IT Operations team.
Kynetx utilizes puppet from Reductive Labs to perform configuration management tasks. The system is a great system with one caveat, the daemon which communicates with the “puppet master” server(s) does so on a set schedule. If the daemons are all restarted within close time proximity to each other, you can run into a resource starvation issue if you are running a virtualized environment, like Kynetx does.
Services Impacted:
- Evaluation Servers (cs.kobj.net)
- Initialization Servers (init.kobj.net)
- Callback Serves (log.kobj.net)
- Code Fragment Server (frag.kobj.net)
- Kynetx Rule Language Server (krl.kobj.net)
- Kynetx Corporate Server (corp.kynetx.com)
- Mail Server (mail.kynetx.com)
- Corporate Web Server (www.kynetx.com, code.kynetx.com, news.kynetx.com, developer.kynetx.com)
- Kynetx Application Server (demo.kynetx.com)
- AppBuilder
- AppDirectory
- Accounts
The root cause was identified to be a ad-hoc software update job controlled through the Puppet system. The update was deployed to the platform within a ten (10) minute period of time, and caused resource starvation on one of the Xen host servers. The resource starvation manifested itself in the temporary inability of the guest servers to communicate with the virtual XEN network. This caused the guest servers to appear to be down, when in fact they were just busy.
Recovery Steps:
The Kynetx IT Operations team was notified of the issue within seconds of its inception by the network of monitoring agents. Once the Kynetx IT Operations team was made aware, a Severity Two (2) incident was declared, and engineers were immediately engaged to triage and resolve the issue.
Due to the load balanced architecture of the KNS platform, the impacted servers were taken out of rotation automatically and isolated as to not poison the entire platform.
Once the root cause was identified, steps were immediately taken to cancel the update job and relieve the resource starvation. The platform was fully recovered within 29 minutes of the first notification.

