If-then-else chains in KRL

I’m using the book OAuth in Action by Justin Richer and Antonio Sanso, to guide implementation of an authorization server using a pico and, of course, KRL. This is a bit more involved than the OAuth client, and involves several if-then-else chains.

Conditionals are different in KRL compared to other languages. Each event triggers one or more rules, which are evaluated in order. Each KRL rule implements an event-condition-action pattern (ECA).

As part of the work-in-progress, I’ve prepared a side-by-side comparison of one of the JavaScript functions from the book with one way of implementing an equivalent in KRL, at http://sanbachs.net/byu/picolabs/oauth/server/krlvsifs.html and a variant, at http://sanbachs.net/byu/picolabs/oauth/server/krlvsifs-2.html

In the field of Computing Education, there is a teaching technique, known as Subgoal Labeling, which has been shown to help people learn programming. Interesting that the rule names in the KRL here can be viewed as labeling the subgoals of the JavaScript code:

oauth_authorize_initialize_requests oauth_authorize_check_client_id oauth_authorize_check_redirect_uri oauth_authorize_render_approve

1 Like