Skip to content

Latest commit

 

History

History
102 lines (64 loc) · 4.17 KB

README.md

File metadata and controls

102 lines (64 loc) · 4.17 KB

pseudoscript

Natural language scripting!

Translates pseudo code in to valid CoffeeScript/JavaScript.

It's kind of magic...

Status

Proof of concept.

Aim

Trying to figure out if it's possible to use natural language for simple scripting, thereby making scripting accessible to non-programmers. As a first demo I've tried to apply the principles I've worked out (see below) to the domain of home automation, since I see great potential for pseudoscript there.

Principles

Haven't really had time to write down all the principles behind this project must the most important are:

Natural language scope

Programming languages are built to be robust and unambiguous. This of course is very useful but also makes them rather unappealing, mechanic and difficult to learn for non-programmers. They also lead to a lot of repetition that natural languages deal with a lot more elegantly. One of the main principles of this project is to introduce natural language scope to scripting, i.e. avoidance of unnecessary repetition. For example, when speaking to other humans about a member of a certain class (e.g. 'the kitchen light') we don't need to repeat the identifier all the time. For example

"turn on the light in the kitchen and set the color of the light in the kitchen to red and set the brightness of the light in the kitchen to 10"

sounds very mechanical. We all know which light we're talking about so instead we'd say something like

"turn on the light in the kitchen and set the color [of the light in the kitchen] to red and [set] the brightness [of the light in the kitchen] to 10"

One of the basic principles of this project is to harness the power and elegance of natural language scope and apply it to scripting.

[more principles to come...]

Demo

The following demo shows the input (.pseudo) and output (.coffee) of a simple home automation script. Two versions are presented: one quite expressive and human like and the other terse and to the point. This is to demonstrate that the level of expressiveness is something the user can choose him or herself.

# Expressive
Add a home
Add a room called 'living room' to the home
Add a light called 'ceiling light' to the room and set the color to blue
Every 10 seconds set the color to red and after 5 seconds set the color back to blue
After 1 hour 30 minutes and 30 seconds, set the temperature of the room to 20

# Terse
Add home
Add room 'living room' to home
Add 'ceiling light' to room, set color blue
Every 10s set color red, wait 5s, set color blue
Wait 1h30m30s, set room temperature 20

Both result in identical compiled CoffeeScript:

### generated by pseudoscript 0.1 ###

# Adding new Home 'home_0'
new Home('home_0')									# reference is autogenerated if omitted

# Adding new Room 'living room' to Home 'home_0'
new Room('living room', 'home_0')

# Adding new Light 'ceiling light' to Room 'living room'
new Light('ceiling light', 'living room')

# Setting 'color' of 'ceiling light' to 'blue'
Light.select('ceiling light').set('color', 'blue')

# Setting interval to 10 seconds
setInterval () ->

  # Setting 'color' of 'ceiling light' to 'red'
  Light.select('ceiling light').set('color', 'red')

  # Setting timeout to 5 seconds
  setTimeout () ->

    # Setting 'color' of 'ceiling light' to 'blue'
    Light.select('ceiling light').set('color', 'blue')

  , (5*1000)

, (10*1000)

# Setting timeout to 5430 seconds
setTimeout () ->

  # Setting 'temperature' of 'living room' to '20'
  Room.select('living room').set('temperature', '20')

, (5430*1000)


Central metaphor and graphical profile

The central metaphor for this project is magic, which is really just a continuation of a long tradition within this area. What do we call a bearded sys admin? A wizard! What does he or she do? Well, mostly he consults the scriptures (e.g. regex cheatsheets), constructs new spells (scripts) which he proceeds to cast into the void (terminal window) in order to manifest his intentions in the universe (system).

I asked my designer colleague to riff off this theme and he came up with a cute, little mascot that I suppose symbolises the state of someone just learning to script: a sorcerer's apprentice.

Wizard