-1

I am trying to find an implementation of the language in c that is actually based on the language standards ,here is a simple example

#include "linda.h"

int worker(int num)
{
  int i;
  for (i=0; i<num; i++)
    out("hello, world");
  return 0;
}

int main()
{
  int result;
  eval("worker", worker(5));
  in("hello, world");
  in("hello, world");
  in("hello, world");
  in("hello, world");
  in("hello, world");
  in("worker", ? result);
  return 0;
}
QuakeCore
  • 1,886
  • 2
  • 15
  • 33

1 Answers1

2

So directly to your question:

Where can i find an implementation of the coordination language linda in c?
Here: http://www.comp.nus.edu.sg/~wongwf/linda.html

You can download it and use it!

If you download it you should get this:

linda //dir
  |
  | - linda.c     //file
  | - linda.h     //file
  | - primes.c    //file
  | - README.txt  //file

But you have to know:

  • You must call linda_init() before you do linda stuff
  • You must call linda_end()before exiting
  • There is no eval() function but you can use spawn()
  • The library varargs.h is outdated! So i would recommend you to use: stdarg.h
    • So that means it could be that you have to rewrite stuff!

So there is only one thing todo!
Download it and get started!

EDIT:

Another way you could go is to download a Linda-C compiler and write your programs in Linda-C (*.clc).

So but back to library from above:
I got a program working with linda in c with this library!

I have: GNU GCC compiler(tdm64-1) 4.7.1 MinGW64

What you have to look out for:

  • In linda.h you have to change the include sys/varargs.h to stdarg.h since varargs is outdated!
    • That means also that you have to change in linda.c all va_arg() calls and change the following type:
      • float -> double
      • char -> int
  • After you have done that you should be able to compile linda.c to linda.o with this command line:
    • gcc -c -O linda.c (Also it could be that you have to direct to the gcc.exe so that the command gcc is known in Windows cmd)

So as an example:

Path to gcc compiler:

"C:\Program Files (x86)\Dev-Cpp\MinGW64\bin"

Path to linda library:

"C:\Users\xy\Downloads\linda\linda"

So now if you open cmd and type in: gcc --version and it's not found you have to direct to the gcc.exe file like this (otherwise your fine and you don't have to direct to the compiler dir):

cd "C:\Program Files (x86)\Dev-Cpp\MinGW64\bin"

So if your in the directory where gcc.exe is located you should be able to execute that command: gcc --version

And from there you can execute the command to create linda.o! Which looks like this in this example:

gcc -c -O C:\Users\xy\Downloads\linda\linda\linda.c

If all worked out! You should end up with the file linda.o in your compiler directory

And now with the file linda.o you can compile primes.c (Which is in this library as an example) and get a linda programm in c working! with the following line:

gcc -o C:\Users\xy\Downloads\linda\linda\primes -O C:\Users\xy\Downloads\linda\linda\primes.c C:\Users\xy\Downloads\linda\linda\linda.o -lpthread -lm

With this line you should end up with the .exe file: primes.exe! Which you can copy in the compiler directory and execute! If you don't have it in this dir then lpthreadGC2_64.dll is unknown and it can't be executed!

  • Few side notes to the compiling of this example:
    • lpthread -> pthread library
    • lm -> math library
    • Also i would recommend you to add the following line in the primes.c file at the end so that if you execute it, the window does not close instant: system("pause");


  • Also for your problem that with this library you can't use eval() there are a few workarounds/ solutions:
    • You can make a for loop and call your functions multiple times! (Since the function you call with spawn() has to have void as return type)
    • You can define a constant with: #define CALLS 5 and use this in the function itself for the commands to execute in a for loop or also in the main function to call spawn() multiple times
    • I think there are more ways to solve this!

So all that said. Your program should look something like this:

#include "linda.h"

#define NUM 5

void worker() {

  int i;

  for (i = 0; i < NUM; i++)
      out("%s", "hello, world");

}

int main() {

    int result;

    spawn(worker);
    in("%s", "hello, world");
    in("%s", "hello, world");
    in("%s", "hello, world");
    in("%s", "hello, world");
    in("%s", "hello, world");
    in("%s?d", "worker", &result);

    system("pause");
    return 0;

}

Hope this helps you!

Cheers

Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • unfortunately my friend , i already have seen this link you provided ,but it didn't for me :( for example the spawn function only takes a call to a void function with no params , that is certainly not following the language standards. – QuakeCore Nov 24 '14 at 22:11
  • @QuakeCore updated my answer with a few extra info's and hint's! Hope it helps you and you get it working! – Rizier123 Nov 26 '14 at 12:08
  • i really appreciate your interest @Rizier123, the problem with this implementation is the spawn function it takes a call to a void function with no arguments , but its expected to take a call to a function with any return type , and any number of arguments. there might be a work around to implement any program to match up with this implementation (like you did) and thats totally fine with me , but believe me i am not the one who is making the rules here :). – QuakeCore Nov 28 '14 at 11:23
  • @QuakeCore You could search for a `Linda-C compiler`, but then you would program in `Linda-C`, otherwise i don't see a way around to write your own `API`(->Github project and get started)! Also this library is not update as you can see yourself, so i don't think there is a newer API.. (OR you write a `Interpreter` that convert's your `C` program in a `Linda` program) – Rizier123 Nov 28 '14 at 11:27
  • you are my only hope , you said "Another way you could go is to download a Linda-C compiler and write your programs in Linda-C (*.clc)" , I've searched the entire web and couldn't find it. hnestly i am not sure exactly what i am looking for... :( – QuakeCore Dec 02 '14 at 19:36
  • @QuakeCore I only can give you this help: https://www.cs.oberlin.edu/~jbasney/honors/thesis.html i never programmed in Linda so i'm slowly at the limit of my ideas! – Rizier123 Dec 02 '14 at 19:45
  • sorry for wasting your time searching for something as useless as this language (in my opinion) :) ,anyway thank you. – QuakeCore Dec 02 '14 at 19:54