Skip to content

Instantly share code, notes, and snippets.

@krainboltgreene
Last active September 25, 2015 05:07
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save krainboltgreene/868032 to your computer and use it in GitHub Desktop.
Some early Dragon writings

Red Dragon: The Syntax & Use Of

As you may have heard Red Dragon is a simple procedural imperative DSL programming language. What does that mean? It means that RD is particularly good at being a learning language. It can, with practice, do some pretty smart things but prides itself on being easy to learn.

Basic Values: Numbers & Text

Red Dragon has two basic values:

Numbers which are integers, and pretty self explanatory.

Example 1: 1
Example 2: -1
Example 3: 2.0
Example 4: 3.5e+42

And Text, which are even simpler, as they're just your basic string.

Example 1: "Hello, World!"
Example 2: "Count down, 3, 2, 1!"

These types of values are used in every day life and will make absolute sense to most students, as they've been crammed with this sort of stuff for years.

Your student will likely understand exactly what these are, and understanding gives a foothold for future context.

Grouped Values: Lists & Pairs

The second two types of values are a little more complex, yet still presented in an easily digested manner:

Lists are groups of values like Numbers, Texts, and even other Lists, plus more. List values can be referenced by an index, a Number.

Example 1: ( 1, 42, 23, 11, 200000 )
Example 2: ( "High", "Five", "Jesus!" )
Example 3: ( 1, 2.0, -3, 4e+50, "word", "heaven", "demigod" )

Pairs are like Lists in a lot of ways, except each item consists of a key/value pairing. Instead of referencing the value by an index number, you gather it through the key. Both Pairs and Lists use the same syntax, so the student has an easier time understanding the context.

Example 1: ( rent: 400.00, utilities: 75.00, food: 35.00 )
Example 1:
    (
        name: "Kurtis Rainbolt-Greene",
        age: 42, 
        likes: ( "Pizza", "Hacking", "Women" )
    )

By now you've probably noticed how each new value type, from Number to Pair, we've stacked on. You're using Numbers and Texts in Lists, and all three in Tables. Students catch onto this, and they tend to learn faster.

By keeping the syntax similar it's easy to remember how it's used, which is probably the biggest hurdle for learning developers.

Basic Definitions: Words & Verbs

Ok, so now that we've gone over all the important value types I think it's time to get to logic. First up to bat is a Word.

Words are your every day variables from other languages. Words are immutable, because in real communication once you define something it's generally a bad idea to change the definition mid-conversation. This connection is something the student should be made aware of: Words are like language words. You define them, and then use them later on as a way of shortcutting to a meaning.

Example 1:
    my_name: "Kurtis Rainbolt-Greene"
Example 2:
    my_age: 42
Example 3:
    groceries: ( "Pizza", "Hamburgers", "Green things" )
Example 4:
    profile: ( name: "Jack", age: 32, likes: ( "Oceans" )

Words get defined and then can be used later. The student will probably best understand this as "Saving". An observant reader will notice how Words look strangely similar to the keys in Pairs. That's correct! Pairs are lists with items that are just variable definitions. Neat, huh?

In fact, lets see it in use:

my_name: "Kurtis Rainbolt-Greene"
my_age: 23
my_likes: ( "Pizza", "Hacking", "Women" )

profile: ( name: my_name, age: my_age, likes: my_likes )

Verbs however, are a bit more complex (as usual). Verbs, as I've explained to my students are things you do to values. Verbs are your standard Function, Method, or Operation in other languages. Verbs take Nouns, commonly called Arguments.

Example 1: add: ( a, b ) => a + b

Example 2: remove_tld: ( url ) do new_url: remove url, ( ".com", ".net", ".org" ) print new_url end

Alright, so now you've seen two types of verbs. Short and long. Each has it's own uses. Notice how we continue to use syntax from previous things. Nouns are inside of a List. You have a list of Arguments being used inside the Verb. Some new things, however, are the Hash Rocket and Do/End blocks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment