How minimal is too minimal? Brainstorming syntax for VisionScript
Published on under the VisionScript category.Toggle Memex mode
Yesterday evening I was thinking about syntax for VisionScript, the programming language on which I am working. My goal is to make the syntax as intuitive as possible while retaining a clear structure. As an aside, VisionScript got to the front-page of Hacker News (HN). I was humbled, excited; indeed, elated. Thank you for being so amazing, HN community! If you haven't seen it, check out the demo for the language.
I want to take a moment to talk language syntax.
At the moment, a VisionScript command looks like this:
Classify["a person making a fist", "a person holding up a flat hand", "two fingers" ]
Names with a capital letter at the beginning are language methods; square brackets denote the location of parameters. But could this be made simpler?
I was writing a rock paper scissors game yesterday evening and started to think about new syntax for the game (and an unrelated < 10 LOC script to change an LED light colour when a person enters a room, but that's for another post!). Here is the rock paper scissors game in valid VisionScript:
gamemaster = Random["rock", "paper", "scissors"]
UseCamera["background"]
Say["You have 3 seconds to get into position!"]
Wait[3]
Classify["a person making a fist", "a person holding up a flat hand", "two fingers"]
If["a person making a fist"]
player = "rock"
End
If["a person holding up a flat hand"]
player = "paper"
End
If["two fingers"]
player = "scissors"
End
Break[]
EndCamera
Say["You chose"]
Say[player]
Say["The computer chose"]
Say[gamemaster]
The code above starts two threads: a camera thread and a program thread. The program thread controls the rock paper scissors logic, then stops once a photo has been taken and classified. Then, the user's choice and computer's choice are displayed on the console.
Here is the idea I had for new syntax:
gamemaster = Random "rock", "paper", "scissors"
UseCamera "background"
Say "You have 3 seconds to get into position!"
Wait 3
Classify "a person making a fist" "a person holding up a flat hand" "two fingers"
If "a person making a fist"
player = "rock"
End
If "a person holding up a flat hand"
player = "paper"
End
If "two fingers"
player = "scissors"
End
Break
EndCamera
Say "You chose" player
Say "The computer chose" gamemaster
I removed all of the square brackets and commas. The resulting syntax is clean. There is a clear structure, but one has fewer characters to type. The language reads more naturally, too. The "what, not how" approach to the primative functions (i.e. Classify[]
and UseCamera[]
) that are available shine through.
I could go even further and use IsItA
, which maps internally to Classify
. Read out the following aloud:
Say "You have 3 seconds to get into position!"
IsItA "a person making a fist" "a person holding up a flat hand" "two fingers"
If "a person making a fist"
player = "rock"
End
Or further:
gamemaster = Random "rock", "paper", "scissors"
UseCamera "background"
Say "You have 3 seconds to get into position!"
Wait 3
Classify "a person making a fist" "a person holding up a flat hand" "two fingers"
If "a person making a fist" player = "rock"
If "a person holding up a flat hand" player = "paper"
If "two fingers" player = "scissors"
Break
EndCamera
Say "You chose" player
Say "The computer chose" gamemaster
I could remove the need for capital letters in functions.
Implementing the new syntax outlined above will take some time, but before I do I need to make a decision on what version of syntax would be more approachable and intuitive. I would love input!
Responses
Comment on this post
Respond to this post by sending a Webmention.
Have a comment? Email me at readers@jamesg.blog.