Ai Dreams Forum

Member's Experiments & Projects => General Project Discussion => Topic started by: Zero on August 22, 2015, 05:43:36 pm

Title: deliberately simple programming language
Post by: Zero on August 22, 2015, 05:43:36 pm
Hi,

I'm working on a language that would be simple to learn. I teach IT in a training center (mostly MS products), and I noticed that what people find hard is:
- nested parentheses hell (3 is already hell, we don't do LISP ;) )
- the fact that a function name precedes parentheses
- function parameters have precise syntax, where order matters

For example, I often see things like:
=if(A1="ok";and;B1<0;C1;D1)
You can feel what was intended.


So, I put strong constraints on the language expressiveness, just to see where it leads.

It looks a bit like INI files.
You start function definition with the name of the function between square brackets.
You have only one command per line
Commands only take one argument, which is always a string
Syntax is "function: argument"
You can call functions inside parentheses, with the same syntax
You CANNOT nest parentheses
You can access variable by their name between angle brackets
You CANNOT nest variable names
Inside a function's body, argument is accessed through empty variable name <>
The return value of last command is always stored in variable <this>
That's it

Here is a taste.


Code
[repeat twice]
render: <> <>

[main]
about: cars
print: Now "this" means <this>
about: language
store this in: some variable
print: what a (repeat twice: really) awful programming <some variable>

==> Now "this" means cars
==> What a really really awful programming language



[pattern match]
parse this as: * isn't *
wildcard in: first
wildcard in: second
render: 1st is <first> and 2nd is <second>

[main]
print: (pattern match: parsing isn't that hard)

==> 1st is parsing and 2nd is that hard


[about]
new meaning of "this"

[render]
choose result value

[store this in]
store value of "this" in named variable

[print]
write text on screen

[parse this as]
do pattern matching on sentence

[wildcard in]
store capture in named variable



This language is intended to be used to code agent behavior in a multi-agent middleware, probably hosted in CouchDB, inspired from a previous work (http://noisett.lang.free.fr/). Feel free to borrow bits and pieces!

Title: Re: deliberately simple programming language
Post by: ranch vermin on August 22, 2015, 06:03:11 pm
getting rid of nesting is a good idea.

Looks like natural language like programming crossed with assembler? - which is what (the original) BASIC pretty much was intended to be.

I started off in basic, I was too girly for assembler, learnt a little pascal, then skipped over to C as quick as I could and avoided C++ - and went to shader programming instead.

And here I am now - with 2048 stream processors - going to make the content addressable memory of a decade.

blah... blah.. blah...  give a brain to my roomba... blah blah blah :)

Noisette looks cool -   Pattern matching languages are great.  Logic paradigm.
Title: Re: deliberately simple programming language
Post by: Zero on August 22, 2015, 10:50:56 pm
Indeed, this language is a bit like verbose assembly. With a lot of synonyms (store this in = store this as = call it = name this = remember this as = we'll call this = ...etc), it could reach a certain degree of flexibility, like NLP. Time will tell.

I don't know much about shader programming, but it sounds interesting. Do you use it for AI-related things? What shading language do you use? I just read on wikipedia that some shading languages are very low-level, like ARB. Then, do you think this "NLP crossed with assembly" thing could be executed on GPU?

Quote
And here I am now - with 2048 stream processors - going to make the content addressable memory of a decade.

Didn't get it. What are you going to make?


EDIT: Is there a shading language that supports strings?! GLSL supports arrays, so it should be possible. Am I right?
Title: Re: deliberately simple programming language
Post by: 8pla.net on August 23, 2015, 12:52:51 am
You said, "Commands only take one argument, which is always a string"

My question is, how would recursion be supported with only one argument?

My informal suggestion:

Code
[recurse thrice]
split: thrice
random: thrice
render: <random>

[main]
about: recursion
print: pseudocode
about: AI
store <Zero> in: friend
print: response (recurse thrice: hello|greetings|howdy) to you too <friend>

Title: Re: deliberately simple programming language
Post by: ranch vermin on August 23, 2015, 02:36:07 am
Not supporting recursion is not such a bad thing,  since recursion taken to the hardware is polling the transistors, so it only gets to 3gigahertz and then its dead... no more scaling.

Shader programming for ai?  Sure thing,  next to custom 1-0 hardware its the best you have for a basic consumer system.    If you wanted to handle strings, you have to treat them like binary pictures,   youll find any data type will make an image of some kind and it makes no difference.

Title: Re: deliberately simple programming language
Post by: Zero on August 23, 2015, 06:53:07 am
Quote
Shader programming for ai?  Sure thing,  next to custom 1-0 hardware its the best you have for a basic consumer system.    If you wanted to handle strings, you have to treat them like binary pictures,   youll find any data type will make an image of some kind and it makes no difference.

Cool. It's definitely worth investigating! I like pattern matching, and I also like cellular automata. Hey, we should do a pattern matching-based cellular automata  :D

Quote
You said, "Commands only take one argument, which is always a string"
My question is, how would recursion be supported with only one argument?

Do we need more than one argument to recurse? (and no one told me?)

Code
// 1. if n is 0, return 1
// 2. otherwise, return [ n × factorial(n-1) ]

[factorial]
if: <> eq 0                        // test if argument is zero
render: 1                          // if yes, return 1
end: if                            // end of if block
about: <>                          // put argument in <this>
decrement: 1                       // put <this>-1 in <this>
store this in: arg                 // put <this> in <arg>
about: <>                          // put argument in <this>
multiply by: (factorial: arg)      // put <this> times factorial of <arg> in <this>
render: <this>                     // return <this>

[main]
print: Please choose a positive number:
input: <num>
print: Factorial of <num> is (factorial: <num>)

It seems to work. What do you think? Actually, I'm cheating: <this> (which is the result of previous command) often acts as implicit second argument. Example: "store this in". See?

EDIT: Since it's based on string substitution, we can still so a few funny things. String substitution happens before command is executed, so:

Code
[Put function in variable]
about: print
store this in: foo
<foo>: hey!

[use function result as variable name]
print: now I'll <(choose what to do: next)>

[use function result as function]
(choose what to do: next): with something

Maybe I should be more strict about these.

And I'd like to get rid of code blocks. I don't like this "if/end if" thing. Shall we dare evil gotozzz?

Title: Re: deliberately simple programming language
Post by: 8pla.net on August 24, 2015, 05:57:06 am
You asked, "Shall we dare evil gotozzz?"
My answer is, "Oh yeah!  I love goto statements."
Goto statements are back in PHP.

Oh, you're right!  I forgot the goal was to keep it simple,
which is a nice goal.   I must have been thinking about
tail-recursive optimization.

But, in general I was asking about recursion, since it
may come in handy for intermediate chatbot design.

Good response.  Thanks!
Title: Re: deliberately simple programming language
Post by: 8pla.net on August 24, 2015, 06:44:12 am
Please help me port my bits and pieces
in the comments (to the right of my PHP).
Note: I may have implemented this Tail-recursive
optimization a little different for A.I. research.

The comments are pseudo code surrounded
by: /* comments_go_here */  I took an educated
guess on the else statement as well as on other
syntax in your language.

By the way, what's your language called?

Thanks!

Code

<?php

/* Tail-recursive optimization  */


function tro($arg, $this) {          /* [tro]                   */
if($arg <= 1){                       /* if: <> le 1             */
  echo "$arg ";                      /* print: <arg>            */
  return $this;                      /* render: <this>          */
  }else{                             /* else:                   */
  echo "$arg $this\n";               /* print: <arg> <this>     */
  return tro($arg-1, $this * $arg);   
                                     /* decrement: 1            */
                                     /* store this in: arg      */
                                     /* about: <>               */
                                     /* multiply by: (tro: arg) */
                                     /* render: <this>          */
  }
}

echo tro(8,1)."\n";

?>


   PHP OUTPUT:

   8 1
   7 8
   6 56
   5 336
   4 1680
   3 6720
   2 20160
   1 40320


Title: Re: deliberately simple programming language
Post by: Zero on August 24, 2015, 10:07:37 am
Hi,

Well, since there's only one argument, you cannot access what was <this> when you called the function from inside the function. You have to insert $this in $arg.
So I guess that a line by line translation would be:

Code
function tro($arg, $this) {          /* [tro]                     */
                                     /* parse this as: *,*        */
                                     /* capture in: $a            */
                                     /* capture in: $t            */
if($arg <= 1){                       /* if: <$a> le 1             */
  echo "$arg ";                      /* print part: <$a>\s        */
  return $this;                      /* render: <$t>              */
  }else{                             /* else:                     */
  echo "$arg $this\n";               /* print line: <$a> <$t>     */
                                     /* about: <$a>               */
                                     /* decrement: 1              */
                                     /* store this in: $deca      */
                                     /* about: <$t>               */
                                     /* multiply by: <$a>         */
                                     /* store this in: $mult      */
  return tro($arg-1, $this * $arg);  /* render (tro: $deca,$mult) */
  }                                  /* end: if                   */
}

                                     /* [main]                    */
echo tro(8,1)."\n";                  /* print line: (tro: 8,1)    */

But it all depends on your base instruction set. For example, for a multi-agent middleware, here is a work-in-progress instruction set:

Code
[about]                           // Put argument in <this>
[anyway]                          // Stop skipping commands, and put argument in <this>
[render]                          // Choose return value

[when message matches]            // Start skipping commands if message doesn't match argument
[when message doesn't match]      // Start skipping commands if message matches argument

[send]                            // Send argument to every followers
[send to myself]                  // Send argument to myself
[send to my tables]               // Send argument to agents owning links where I'm involved

[forget this in]                  // Delete everything that matches a pattern in a variable
[push this in]                    // Push <this> in a variable
[pop from]                        // Pop <this> from a variable
[unshift this in]                 // Push <this> at the other end in a variable
[shift from]                      // Pop <this> from the other end in a variable
[rotate]                          // Rotate list stored in a variable
[when something in this matches]  // Start skipping commands if nothing in a variable matches argument
[when nothing in this matches]    // Start skipping commands if something in a variable matches argument
[pick a random element from]      // Pick a random element from a variable

[put capture in]                  // Put what next wildcard has captured in a variable

[list agents having this once in] // List of agents having this pattern in given key
[list agents having only this in] // List of agents having this pattern in given key
[list used variables]             // List of every variable

[if all identical]                // Parse argument if everything in this is the same
[if one different]                // Parse argument if something in this is not the same

[for each one]                    // Put next element in this, parse argument, do it again

<message>                         // The current message
<message sender>                  // Id of agent who sent current message
<me>                              // Id of me

[follow input of]
[follow output of]
[follow upput of]
[follow action of]

In that case, instead of raw recursion, an agent would probably send a message to itself about the next iteration, which is a bit like tail recursion. I'm working on a Nodejs implementation currently.



About the name, I don't know yet, so if you guys have ideas, they're welcome!
:)

Title: Re: deliberately simple programming language
Post by: ivan.moony on August 24, 2015, 01:07:16 pm
How about "Simplite", "Simplique", "Simplicity" or "Simplelog"?
Title: Re: deliberately simple programming language
Post by: Zero on August 24, 2015, 03:02:02 pm
Not bad!  3 of them are already used: "Simplite (http://secway.software.informer.com/)", "Simplique (https://itunes.apple.com/us/app/simplique/id877155350?mt=8)",  "Simplelog (https://hackage.haskell.org/package/SimpleLog)". Simplicity is maybe too general, isn't it?
Title: Re: deliberately simple programming language
Post by: 8pla.net on August 24, 2015, 03:48:10 pm
How about PL/S or PL/DS?

The PL usually stands for "Programming Language".

I don't believe either of these are taken..

Already taken:

PL/0
PL/B
PL/C
PL/I - ISO 6160
PL/M
PL/P
PL/SQL

Reference: List of programming languages
https://en.wikipedia.org/wiki/List_of_programming_languages


@ivan: Nice recommendations!

Title: Re: deliberately simple programming language
Post by: Zero on August 24, 2015, 04:08:39 pm
Thank you both! What would PL/DS stand for?

PL/Simple...

Also I thought, something with ASM inside...


EDIT: is PL/Simplicity good?
Title: Re: deliberately simple programming language
Post by: 8pla.net on August 24, 2015, 06:00:01 pm
Thank you both! What would PL/DS stand for?

D=deliberately
S=simple
P=programming
L=language

PL/DS = Programming Language/Deliberately Simple

Yes, the "Simplicity" recommendation by ivan is very nice.

I don't think PL/S is taken yet?
 
Title: Re: deliberately simple programming language
Post by: ivan.moony on August 24, 2015, 06:27:36 pm
I think that the most important thing when naming a product is its correlation with a web search engine. If you are lucky, user will probably read the name somewhere, enter it into a search engine and click onto few of the first results to reach you. And once you have their attention... they're all history if you manage impress them. And the name of the product is where impression starts.

I've spent entire three days googling for absence of names when I was choosing name for my language. Everything was taken, from Synth, over Metacog to Transcript and a dozen of other ear-catchy names. Everything good was already taken. So I settled down with "Coglog", but I abandoned it after a month. Then it was "Transfigure" and more recently I've got another more descriptive name: "Metafigure". I like the new name because my language deals with mutable figures of data. Yet to be seen where I'll end up with these names, I have the time 'till I program it.
Title: Re: deliberately simple programming language
Post by: Zero on August 25, 2015, 08:49:39 am
Then we should name it "fantASM". Big hit!  :o ;D

EDIT: So far, I have
Code
log to console: (execute raw javascript: 5+5)
working!
Title: Re: deliberately simple programming language
Post by: Zero on August 27, 2015, 03:12:54 pm
Working on text user interface...
(https://aidreams.co.uk/forum/proxy.php?request=http%3A%2F%2Fnoisett.lang.free.fr%2Ftui-capture.png&hash=37122522e9ab5c711584c07caaee2d7daa9e4ac8)
(inspired from Steve Dekorte's Io website)
Title: Re: deliberately simple programming language
Post by: Zero on September 10, 2015, 08:55:14 am
Hi all,

This language is evolving a bit. I wasn't happy with having colons inside parentheses, so now functions act as chatbot triggers. They're defined between curlies.

Code
  {first name of *}
  command: argument
  command: argument
  render: something

  [regular command]
  command: argument
  insert: (first name of Joe Black)
  command: argument

Now, indentation matters. Also, the target has changed, it is now a language that compiles to a single html file, containing html5+css3+js. I still dont' have a name. PL/DS could mean "dead simple" :)


EDIT: Would "Litewave" be a good name?
Title: Re: deliberately simple programming language
Post by: Zero on September 14, 2015, 03:17:54 pm
Indentation is maybe too much for an "easy" language. So, maybe jumping a line to mark the end of a code block would suffice. Like:
Code

[my command]

print: Here is a list of cities I like:

for each item from: <list of cities>
print: I like <item>

print: That's it!

Nesting foreach loops wouldn't be allowed in that case.
Title: Re: deliberately simple programming language
Post by: 8pla.net on September 15, 2015, 03:05:19 am
Indentation may be one of my unfavorite things about Python, I think.
Title: Re: deliberately simple programming language
Post by: Zero on September 18, 2015, 03:34:15 pm
Here is a draft command set:

Code

[list vars like]    produces a list of variables with name matching given pattern
[with]              appends its argument to <this>
[without]           removes from <this> everything matching its argument
[only]              keeps in <this> everything matching its argument
[keep before]       keeps in <this> everything before first match
[keep after]        keeps in <this> everything after last match
[about]             puts its argument in <this>
[this is]           puts what is in <this> in the variable with the given name
[forget variable]   deletes variable with given name
[raw]               produces directly its argument (without string interpolation)
<this>

[here is]              defines a label you can jump to
[jump to]              jumps to a label
[if]                   executes code only if its argument is in <truth>
[unless]               executes code only if its argument isn't in <truth>
[while]                keeps looping code while its argument is in <truth>
[until]                keeps looping code until its argument is in <truth>
[for each item from]   executes code once for each value of its argument
[if this is]           executes code only if <this> is the same as its argument
<item>

[consider]             asserts strings in <truth>
[sufficient]           asserts a "sufficient" rule
[necessary]            asserts a "necessary" rule
[put aside]            removes from <truth> strings matching its argument
[keep and formulate]   produces a list of strings based on possibilities
[formulate]            produces possibilities and delete logic variables
[forget logic]         deletes logic variables
[truth in]             saves the content of <truth> in variable with given name
[truth from]           loads the content of <truth> from variable with given name
<truth>

[list nodes like]    lists html nodes using "document.querySelectorAll()"
[select node]        selects current node using "document.getElementById()"
[remove node]        deletes node with given id
[clear node]         deletes the content of node with given id
[set as attribute]   puts <this> in given attribute of current node
[get attribute]      puts given attribute of current node in <this>
[before node put]    inserts node of given type before current node and produces its id
[after node put]     inserts node of given type after current node and produces its id
[inside node put]    inserts node of given type inside current node and produces its id
[write]              appends given text in current node
[listen]             puts a listener on current node with following code block
[ignore]             deletes a listener from current node
<node>
<ui>

Title: Re: deliberately simple programming language
Post by: ivan.moony on September 18, 2015, 04:56:38 pm
I have to admit I don't fully understand your language all the time, while it is ought to be simple, but maybe it's just me and my silly mind...

Are those recent commands ought to be built in? How should they be written in use examples? Can there be arbitrary content inside [...] brackets? The only thing I think I understood is that after [...] brackets follows something that belogs to them, like a function, or maybe I got that wrong too?

I'd like, once when you're finished, to read a tutorial (if you ever get to that point), so don't mind me for now, I don't want to put unproductive influences to your ideas.
Title: Re: deliberately simple programming language
Post by: ivan.moony on September 18, 2015, 09:56:11 pm
Never mind... I finaly got it (I think). There is built in set of commands, but you can also write your own compound commands.
Title: Re: deliberately simple programming language
Post by: Zero on September 19, 2015, 03:33:46 pm
Sorry, I wasn't able to respond sooner. Thanks a lot for your input!

So yes, you got it. What I call "commands" here are named "subs" in basic, "procedure" in pascal, "function" in C. My previous post was a list of built-in commands.

To define a new command, you put its name between square brackets. Programs always start by executing the "main" command. So a basic hello world would be:

Code
  [main]

  print: Hello world!

It's a little bit early to write a tutorial, but when I'm done I'll make one, and if this tutorial is not clear, maybe you can help me make it better :)

Title: Re: deliberately simple programming language
Post by: yotamarker on March 23, 2016, 09:27:15 pm
without nested statements ? does it mean you can't use for loops ?
Title: Re: deliberately simple programming language
Post by: Zero on March 25, 2016, 01:49:06 pm
In Goto We Trust
(Oh ye of little faith)
 ;D