Concurrency?

Showing 1-6 of 6 messages
Concurrency? Xan 3/29/12 6:40 AM
Hi,

I'm new user of zimbu. First of all, I'm impressed with it.  I want it
to write a web crawler and for that I need mainly concurrency. Is
there any concurrency model implemented in zimbu like Actors in Scala
or Fantom or pipes in Golang or spawn in D?

If not, is it planned to have?


For the other hand, I like to know if any of this topics are features
of zimbu:
* generics
* higher-order functions
* immutability
* lists of diffent tyes (like [1, "a"])
* use of pointers
* Null-safety ("type? a" means a could be type and null and type a
means a could not be null)


Thanks in advance,
Re: Concurrency? Bram Moolenaar 3/29/12 2:02 PM

Xan -

> I'm new user of zimbu. First of all, I'm impressed with it.  I want it
> to write a web crawler and for that I need mainly concurrency. Is
> there any concurrency model implemented in zimbu like Actors in Scala
> or Fantom or pipes in Golang or spawn in D?
>
> If not, is it planned to have?

Currently there are threads.  You can setup pipes to distribute work
over threads.  See the Threads section on the highlights page for an
example: http://www.zimbu.org/Home/threads-and-pipes

I would like to implement coroutines, which are much more light weight
than threads, but it's hard to find a good, portable implementation.
They all seem to use a fixed stack size and crash when you run out of
stack.

> For the other hand, I like to know if any of this topics are features
> of zimbu:
> * generics

Zimbu has templates.  I haven't yet found a reason to also support
generics.

> * higher-order functions

You can pass around function references.  I'm not sure if this has
relevant limitations.

> * immutability

Not yet.  Not sure how to do this properly.  Static or runtime?

> * lists of diffent tyes (like [1, "a"])

In two ways:
- list<ANY>  list of any kind of thing
- tuple<int, string>  

These are not implemented yet though.  Tuples are nice to have, should
implement this soon.

> * use of pointers

No.  You can pass around references:

        int i
        increment(&i)

And you can include a block of C code if you really want to do low-level
stuff.

> * Null-safety ("type? a" means a could be type and null and type a
> means a could not be null)

No.  In practice this makes declarations more complicated and doesn't
help enough to justify that.  Just like with const in C, it's a hassle
and hardly ever avoids a problem.

Using NIL pointers is a problem though, e.g, trying to iterate over a
NIL collection.  Don't have a nice solution for that yet, only this:

        FOR i IN mylist ?: []

The ?: operator works more-or-less like || in Javascript.  But it's
type-safe.  You can also see it as a short notation for:

        FOR i IN mylist != NIL ? mylist : []

Perhaps it's better to say that iterating over a collection type that is
NIL is equivalent to an empty collection.

--
ARTHUR: Right! Knights! Forward!
   ARTHUR leads a charge toward the castle.  Various shots of them battling on,
   despite being hit by a variety of farm animals.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Re: Concurrency? Xan 4/4/12 1:50 AM


On Mar 29, 11:02 pm, Bram Moolenaar <B...@Moolenaar.net> wrote:
> Xan -
>
> > I'm new user of zimbu. First of all, I'm impressed with it.  I want it
> > to write a web crawler and for that I need mainly concurrency. Is
> > there any concurrency model implemented in zimbu like Actors in Scala
> > or Fantom or pipes in Golang or spawn in D?
>
> > If not, is it planned to have?
>
> Currently there are threads.  You can setup pipes to distribute work
> over threads.  See the Threads section on the highlights page for an
> example:http://www.zimbu.org/Home/threads-and-pipes
>
> I would like to implement coroutines, which are much more light weight
> than threads, but it's hard to find a good, portable implementation.
> They all seem to use a fixed stack size and crash when you run out of
> stack.
>

I think this is cool feature. Please consider to implement it. It's
useful for not overcharge systems.

> > For the other hand, I like to know if any of this topics are features
> > of zimbu:
> > * generics
>
> Zimbu has templates.  I haven't yet found a reason to also support
> generics.

Are these not the same?
>
> > * higher-order functions
>
> You can pass around function references.  I'm not sure if this has
> relevant limitations.

Yes, but with this I have to create a function first and pass as
reference after. Is there any way to define anonymous function in
parameter place?

Something like:
someprocedure(int a, (int,int)->int f) {
  return f(a,a)
}

(in pseudocode)
>
> > * immutability
>
> Not yet.  Not sure how to do this properly.  Static or runtime?

What is the difference? Can you explain me? I'm not expert on that.

>
> > * lists of diffent tyes (like [1, "a"])
>
> In two ways:
> - list<ANY>  list of any kind of thing
> - tuple<int, string>

Mmm... Pretty good syntax.

>
> These are not implemented yet though.  Tuples are nice to have, should
> implement this soon.

Good news!!!

>
> > * use of pointers
>
> No.  You can pass around references:
>
>         int i
>         increment(&i)
>
> And you can include a block of C code if you really want to do low-level
> stuff.
>
> > * Null-safety ("type? a" means a could be type and null and type a
> > means a could not be null)
>
> No.  In practice this makes declarations more complicated and doesn't
> help enough to justify that.  Just like with const in C, it's a hassle
> and hardly ever avoids a problem.
>
> Using NIL pointers is a problem though, e.g, trying to iterate over a
> NIL collection.  Don't have a nice solution for that yet, only this:
>
>         FOR i IN mylist ?: []
>
> The ?: operator works more-or-less like || in Javascript.  But it's
> type-safe.  You can also see it as a short notation for:
>
>         FOR i IN mylist != NIL ? mylist : []
>
> Perhaps it's better to say that iterating over a collection type that is
> NIL is equivalent to an empty collection.
>

It's useful for having an automatic expception when var is null. If
you say that a is String and not null at first, then if you pass a as
null, then you get NullExcp. This is something you should NOT to test


Thanks for comments,


My plan is to build a web crawler. I want concurrent web page. Go is
ok, but there is no class, inheritance and templates (in zimnbu
sense). D is good, but has there is _no_ lots of libraries. And C++
has bad bad syntax and non-Garbage-Collection nightmare.


Xan.

> --
> ARTHUR: Right! Knights! Forward!
>    ARTHUR leads a charge toward the castle.  Various shots of them battling on,
>    despite being hit by a variety of farm animals.
>                  "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
>
>  /// Bram Moolenaar -- B...@Moolenaar.net --http://www.Moolenaar.net  \\\
> ///        sponsor Vim, vote for features --http://www.Vim.org/sponsor/\\\
> \\\  an exciting new programming language --http://www.Zimbu.org       ///
Re: Concurrency? Bram Moolenaar 4/5/12 6:38 AM

Xan wrote:

> > > I'm new user of zimbu. First of all, I'm impressed with it. �I want it
> > > to write a web crawler and for that I need mainly concurrency. Is
> > > there any concurrency model implemented in zimbu like Actors in Scala
> > > or Fantom or pipes in Golang or spawn in D?
> >
> > > If not, is it planned to have?
> >
> > Currently there are threads. �You can setup pipes to distribute work
> > over threads. �See the Threads section on the highlights page for an
> > example:http://www.zimbu.org/Home/threads-and-pipes
> >
> > I would like to implement coroutines, which are much more light weight
> > than threads, but it's hard to find a good, portable implementation.
> > They all seem to use a fixed stack size and crash when you run out of
> > stack.
>
> I think this is cool feature. Please consider to implement it. It's
> useful for not overcharge systems.

Perhaps someone voluteers to work on this.

> > > For the other hand, I like to know if any of this topics are features
> > > of zimbu:
> > > * generics
> >
> > Zimbu has templates. �I haven't yet found a reason to also support
> > generics.
>
> Are these not the same?

Similar but not the same:
http://en.wikipedia.org/wiki/Generics_in_Java
http://en.wikipedia.org/wiki/C%2B%2B_Templates

> > > * higher-order functions
> >
> > You can pass around function references. �I'm not sure if this has
> > relevant limitations.
>
> Yes, but with this I have to create a function first and pass as
> reference after. Is there any way to define anonymous function in
> parameter place?
>
> Something like:
> someprocedure(int a, (int,int)->int f) {
>   return f(a,a)
> }
>
> (in pseudocode)

Sure:

FUNC someprocedure(int a, int b, func<int, int: int> f) int
  RETURN f(a, b)
}

And call it with:

  IO.writeLine("add: " .. someprocedure(2, 3, { a, b => a + b }))
  IO.writeLine("multiply: " .. someprocedure(2, 3, { a, b => a * b }))

Read the => as "gives".  This is implemented.

> > > * immutability
> >
> > Not yet. �Not sure how to do this properly. �Static or runtime?
>
> What is the difference? Can you explain me? I'm not expert on that.

Compile time immutability means the compiler checks if a variable is
allowed to be changed, like "const" in C and C++.  This can be used to
declar that a method will never change an argument.

Runtime immutability means locking a variable or object so that trying
to change it will throw an exception.  This can be used to create an
object in any way and then lock it, so that it can no longer be
modified.

Yes, an exception is thrown when attempting to use a NIL reference.

> Thanks for comments,
>
>
> My plan is to build a web crawler. I want concurrent web page. Go is
> ok, but there is no class, inheritance and templates (in zimnbu
> sense). D is good, but has there is _no_ lots of libraries. And C++
> has bad bad syntax and non-Garbage-Collection nightmare.

Exactly the reason why I started creating Zimbu.  The libraries are
limited, but since you can always invoke functions in a C library you
should be able to make this work.  I should actually make it easier to
create a wrapper arounc a C library soon.

--
ARTHUR:      Who are you?
TALL KNIGHT: We are the Knights Who Say "Ni"!
BEDEVERE:    No!  Not the Knights Who Say "Ni"!


                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///


 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

Re: Concurrency? Xan 4/5/12 8:20 AM
Al 05/04/12 15:38, En/na Bram Moolenaar ha escrit:

> Xan wrote:
>
>>>> I'm new user of zimbu. First of all, I'm impressed with it.  I want it
>>>> to write a web crawler and for that I need mainly concurrency. Is
>>>> there any concurrency model implemented in zimbu like Actors in Scala
>>>> or Fantom or pipes in Golang or spawn in D?
>>>> If not, is it planned to have?
>>> Currently there are threads.  You can setup pipes to distribute work
>>> over threads.  See the Threads section on the highlights page for an
>>> example:http://www.zimbu.org/Home/threads-and-pipes
>>>
>>> I would like to implement coroutines, which are much more light weight
>>> than threads, but it's hard to find a good, portable implementation.
>>> They all seem to use a fixed stack size and crash when you run out of
>>> stack.
>> I think this is cool feature. Please consider to implement it. It's
>> useful for not overcharge systems.
> Perhaps someone voluteers to work on this.

Good if someone could do that. I have no tech skills to do that. Just user.


>>>> For the other hand, I like to know if any of this topics are features
>>>> of zimbu:
>>>> * generics
>>> Zimbu has templates.  I haven't yet found a reason to also support
>>> generics.
>> Are these not the same?
> Similar but not the same:
> http://en.wikipedia.org/wiki/Generics_in_Java
> http://en.wikipedia.org/wiki/C%2B%2B_Templates

Templates are enough in my case. I just want to define something like:

sum[T](T a, T b) {a + b}

For the other hand, you have asserts? Like:

Class Rational(int a, int b) {

        make(int a, int b) {
                require(b!=0)
        }
}

(in pseudocode; make is constructor of this class)

If this, the following function is the same as previous:

sum(ANY a, ANY b){
     with(a.typeof = b.typeof)
     with(a.typeof has OperatorSum)
     return sum (a, b) {a + b}
}


isn't?


>>>> * higher-order functions
>>> You can pass around function references.  I'm not sure if this has
>>> relevant limitations.
>> Yes, but with this I have to create a function first and pass as
>> reference after. Is there any way to define anonymous function in
>> parameter place?
>>
>> Something like:
>> someprocedure(int a, (int,int)->int f) {
>>    return f(a,a)
>> }
>>
>> (in pseudocode)
> Sure:
>
> FUNC someprocedure(int a, int b, func<int, int: int>  f) int
>    RETURN f(a, b)
> }
>
> And call it with:
>
>    IO.writeLine("add: " .. someprocedure(2, 3, { a, b =>  a + b }))
>    IO.writeLine("multiply: " .. someprocedure(2, 3, { a, b =>  a * b }))
>
> Read the =>  as "gives".  This is implemented.

Very well. It's good. This is what I want.


>>>> * immutability
>>> Not yet.  Not sure how to do this properly.  Static or runtime?
>> What is the difference? Can you explain me? I'm not expert on that.
> Compile time immutability means the compiler checks if a variable is
> allowed to be changed, like "const" in C and C++.  This can be used to
> declar that a method will never change an argument.
>
> Runtime immutability means locking a variable or object so that trying
> to change it will throw an exception.  This can be used to create an
> object in any way and then lock it, so that it can no longer be
> modified.

I think static is enough. What other languages do that? Perhaps you
could "import" their ideas.

>
>>>> * lists of diffent tyes (like [1, "a"])
>>> In two ways:
>>> - list<ANY>    list of any kind of thing
>>> - tuple<int, string>

Could I do something like:

list<T,T>

with Type T defined bellow?

But C library could have Garbage-Collection nightmare, isn't?


Thanks,
Xan.

Re: Concurrency? Bram Moolenaar 4/5/12 10:24 AM

Xan wrote:

> >>>> For the other hand, I like to know if any of this topics are features
> >>>> of zimbu:
> >>>> * generics
> >>> Zimbu has templates.  I haven't yet found a reason to also support
> >>> generics.
> >> Are these not the same?
> > Similar but not the same:
> > http://en.wikipedia.org/wiki/Generics_in_Java
> > http://en.wikipedia.org/wiki/C%2B%2B_Templates
>
> Templates are enough in my case. I just want to define something like:
>
> sum[T](T a, T b) {a + b}

That would be:

   FUNC sum<Tt>(Tt a, Tt b) Tt
     RETURN a + b
   }

> For the other hand, you have asserts? Like:
>
> Class Rational(int a, int b) {
>
>         make(int a, int b) {
>                 require(b!=0)
>         }
> }

       CHECK.true(b != 0)

> (in pseudocode; make is constructor of this class)
>
> If this, the following function is the same as previous:
>
> sum(ANY a, ANY b){
>      with(a.typeof = b.typeof)
>      with(a.typeof has OperatorSum)
>      return sum (a, b) {a + b}
> }
>
> isn't?

It's not the same, because here the type will be checked at runtime,
which is much slower and might throw exceptions.

> >>>> * immutability
> >>> Not yet.  Not sure how to do this properly.  Static or runtime?
> >> What is the difference? Can you explain me? I'm not expert on that.
> > Compile time immutability means the compiler checks if a variable is
> > allowed to be changed, like "const" in C and C++.  This can be used to
> > declar that a method will never change an argument.
> >
> > Runtime immutability means locking a variable or object so that trying
> > to change it will throw an exception.  This can be used to create an
> > object in any way and then lock it, so that it can no longer be
> > modified.
>
> I think static is enough. What other languages do that? Perhaps you
> could "import" their ideas.

My experience with C and C++ that using "const" can be a hassle and
hardly ever avoids a problem.  Java has "final", which is weird (can
change the value in the constructor, not elsewhere).

> >>>> * lists of diffent tyes (like [1, "a"])
> >>> In two ways:
> >>> - list<ANY>    list of any kind of thing
> >>> - tuple<int, string>
>
> Could I do something like:
>
> list<T,T>
>
> with Type T defined bellow?

A list only takes one type, all items are of that type.

> >> My plan is to build a web crawler. I want concurrent web page. Go is
> >> ok, but there is no class, inheritance and templates (in zimnbu
> >> sense). D is good, but has there is _no_ lots of libraries. And C++
> >> has bad bad syntax and non-Garbage-Collection nightmare.
> > Exactly the reason why I started creating Zimbu.  The libraries are
> > limited, but since you can always invoke functions in a C library you
> > should be able to make this work.  I should actually make it easier to
> > create a wrapper arounc a C library soon.
> >
> But C library could have Garbage-Collection nightmare, isn't?

That is something I haven't worked on yet.

--
Yah, well, we had to carve our electrons out of driftwood we'd
find.  In the winter.  Uphill.  Both ways.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///