After working on Nava, I released that Nava is an overly complex language (it might even need another overhaul) and I need to get into better background on creating programming languages with something much easier. So, I decided that I would attempt to design a simpler language and eventually program its interpreter. I don't have any ideas what to name it, so for now, it's called MistSpark (mtsk).
The main idea is that functions can be named like (name x y name z) like Snap! and Scratch, which is for readability. Here's an example I created to illustrate the syntax and tokenizer's design.
set :x: to []
repeat 10 times
add (length of :x: + 1) to :x:
log (item (length of :x:) of :x:)
log :x:
With more freedom with writing your functions' names, it can help make their functionality more clear. For example, if you are writing code for a game's API, you can name a function like achievement(id, goal_code, reward_code) to achivement (id) where doing (goal_code) does (reward_code). Of course, you free to write it transitionally if you wanted.
Here's all the main ideas of MistSpark.
More clear functions by free name and argument place, supported with polymorphism and types.
Minimal object-oriented programming, featuring things like variable/item tie-ins and items with names and values, but not things like classes and inheritance.
The ability to write external modules and mods.
Here's some more examples.
! Hello World
log "Hello, world!"
! Factorial
set :number: to 5
set :fib: to {
set :x: to 1
for :i: = 2 to :number:
set "x" to (:x: * :i:)
return :x:
}
log (join ["Factorial of", (convert :number: to a "string"), "is", (call :fib:)] by " ")
! Fibonacci
function ["fib", [:n:, "number"]]
if (:n: = 1) or (:n: < 1)) then
return :n:
else
return ((fib(:n: - 1)) + (fib(:n: - 2)))
log (fib 9)
! FiizBuzz
for :i: = 1 to 100
if ((:i: % 3) = 0)
if ((:i: % 5) = 0)
log "FizzBuzz"
else
log "Fizz"
else
if ((:i: % 5) = 0)
log "Buzz"
else
log :i:
I don't have a repository and documentation made yet until progress was made towards the language and its interpreter, so please ask me if you have any questions.
I suggest a tiny bit more syntax, because all that (get "x") stuff makes the code much harder to read than necessary. Being as I am a Logo person, I suggest :x as the abbreviation for the get function.
Thanks for the suggestion on renaming it from get to :. It would look like (:"x") because colons aren't part of the syntax and the reason of strings is to name variables like "pen color" instead to pen_color/penColor and easily get variables like (:(item 1 in (:"vars names"))) = (:"i"), but I might consider changing this if more people have a problem with it. I might change this soon or later.
Ah, that's a good point about spaces. Okay, new suggestion: :pen color:. The point isn't just to save two keystrokes, it's to lose the parentheses too, so people don't have to think about so much nesting in their program structure. You could still have get for the case of a computed variable name (or looked up var name, as in your example).
That's a much better way, and I am probably going to introduce this as the standard way to get variables. But the get function might stay in case you want to get variables with strings. But it's removed, we can rather use tables.
set :vars: to ["foo" = :foo:, "bar" = :bar:, "moo" = :moo:]
set (item "foo" in :vars:) to 42
log :foo:
@bh, I changed all the examples using from (get "x") to :x:, so you don't need to use a function and parentheses. I actually found it much better, but I smuggle in the ability to get variables by strings for two cases: using a string in a var argument or using (convert "x" to a "var"). Therefore, for anyone who wants to get any variables by a string (it should be for things like inputs), they can do so without defining a table.