Ai Dreams Forum

Member's Experiments & Projects => General Project Discussion => Topic started by: Zero on November 23, 2017, 01:51:47 pm

Title: Mixing Tcl and Io
Post by: Zero on November 23, 2017, 01:51:47 pm


As you know, I like programming languages. Here I do a little thought experiment: mixing John Ousterhout's language Tcl and Steve Dekorte's language Io.

An interesting feature of Tcl is that function evaluation isn't automatic. You have to put code inside square brackets if you want it to be executed. The square brackets and their content will be "replaced by" the output of the code inside them.

set x 24
set y 18
set z "$x + $y is [expr $x + $y]"
puts $z


Io is modern and minimalist. An object is a list of slots, where each slot may contain data/code. You'd call an object's method by naming the corresponding object's slot.

Account := Object clone
Account balance := 0
Account deposit := method(amount,
    balance = balance + amount
)

account := Account clone
account deposit(10.00)
account balance println




Mixing them would give something like this:

set Dog [Object clone];

Dog set greet [
   fun {
      print "Hello, [arg]. I'm [name].";
   };
];

set my-dog [Dog clone];

my-dog
   set name "Maxy the dog",
   greet John;
   
-> Hello, John. I'm Maxy the dog.


"set" means "create a slot in yourself, with this name and this value".

In the first line, we're talking to the Environment, saying: create a slot named "Dog". The value of this slot will be the result of the code in square brackets [Object clone].

With "Object clone", we're talking to the object "Object", asking it to return a clone of itself.

The general form of a command is
command ::= <subject> <verb> <arguments> { "," <verb> <arguments> } ";"

Example:
obj part3 subPartB doThis like that, doThat like this;
where
"obj part3 subPartB" is the subject
"doThis" is a function with arguments "like" and "that"
"doThat" is a function with arguments "like" and "this"

I choose not to use named function arguments. Arguments are accessible through "arg", which contains the list of every argument the function was called with.

This would blend perfectly with the pub/sub semantics of Birdy (http://aidreams.co.uk/forum/index.php?topic=12542.msg48975).

Title: Re: Mixing Tcl and Io
Post by: Thierry on November 23, 2017, 02:07:57 pm
What those languages can do that python cannot ? (Compared to guys like you I really consider myself as beginner in programming !  :))
Title: Re: Mixing Tcl and Io
Post by: Zero on November 23, 2017, 02:40:44 pm
Nothing, really. All general purpose mainstream programming language are (pseudo) Turing-complete, which means they can compute everything, if they have enough space-time.

Differences are rather:
- some things are easier in one language, other things are easier in another
- porting to specific platforms can be easy/hard
- the ecosystems are different (ecosystem = libraries made by communities)
- communities have different "style" and size...

You code in Python? Python is good for AI. Good choice!
Title: Re: Mixing Tcl and Io
Post by: Thierry on November 23, 2017, 09:56:08 pm
Nothing, really. All general purpose mainstream programming language are (pseudo) Turing-complete, which means they can compute everything, if they have enough space-time.

Differences are rather:
- some things are easier in one language, other things are easier in another
- porting to specific platforms can be easy/hard
- the ecosystems are different (ecosystem = libraries made by communities)
- communities have different "style" and size...

You code in Python? Python is good for AI. Good choice!

ok I get it.
Yes Python is the only language I know. I went to it because I saw roboticists in many forums going to it and being quite satisfied.  I love it as well. Thanks to it I saw very fast that I could do almost everything with a machine. I don't say I don't want to go further with other languages but at least for what I need now this is enough.

Are you into Python as well ?
Title: Re: Mixing Tcl and Io
Post by: Thierry on November 23, 2017, 10:23:28 pm
By the way ... IO dictionaries  are weird ! They look more like "set" than "dict". There s no item:value... ???

http://iolanguage.org/tutorial.html

Title: Re: Mixing Tcl and Io
Post by: Zero on November 24, 2017, 09:17:28 am
Actually, Python is not my favorite language :)

This "There's only 1 way to do it" (the pythonic way) philosophy isn't my taste, really. Or maybe it's just because I like to choose my own indentation style. I'm more Perl-ish style. Javascript is currently what excites me most. People usually under-estimate it, seeing it as a language that encourages bad practices and unstructured code, but it's wrong. It demands discipline, but once you're there, it can be everywhere, it can be very fast, and it's elegant.

Now Python is a perfect choice for you in my opinion. It gives you structure. In AI and robotics fields, it is highly appreciated by communities. You can work easily with very high level concepts, and get things done neatly. Stick to it, master it, I'm sure you'll be a happy dev. A dev should be happy!

About Io dictionaries, it's ok... There's everything you would expect: atPut() can set new key:values, at() fetches a value when given a key, keys() returns the list of keys, and foreach() lets you loop through it. What it doesn't have though, is a literal syntax for expressing them, like {a:1, b:2} for instance. But well, it's a minimalist language.