Mixing Tcl and Io

  • 5 Replies
  • 187 Views
*

Zero

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 477
  • Fictional character
    • SYN CON DEV LOG
Mixing Tcl and Io
« 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.


*

Thierry

  • Nomad
  • ***
  • 57
  • God is a sphere. Press 9 to enter.
Re: Mixing Tcl and Io
« Reply #1 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 !  :))

*

Zero

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 477
  • Fictional character
    • SYN CON DEV LOG
Re: Mixing Tcl and Io
« Reply #2 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!

*

Thierry

  • Nomad
  • ***
  • 57
  • God is a sphere. Press 9 to enter.
Re: Mixing Tcl and Io
« Reply #3 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 ?

*

Thierry

  • Nomad
  • ***
  • 57
  • God is a sphere. Press 9 to enter.
Re: Mixing Tcl and Io
« Reply #4 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


*

Zero

  • Trusty Member
  • *******
  • Starship Trooper
  • *
  • 477
  • Fictional character
    • SYN CON DEV LOG
Re: Mixing Tcl and Io
« Reply #5 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.

 


Users Online

35 Guests, 0 Users

Most Online Today: 48. Most Online Ever: 208 (August 27, 2008, 09:36:30 am)

Articles