Author Topic: Pike  (Read 11181 times)

Tomaaz

  • Guest
Pike
« on: February 06, 2016, 11:10:23 PM »
I've recently tried Pike and it seems to be a  nice language. It has syntax very similar to C, but it's interpreted and comes with several modules that are very easy to use. A couple of examples:

Primes
Code: [Select]
void main() {   
    int x, y, isprime;
    for (x = 11; x < 1000000; x += 2) {
isprime = 1;
for (y = 3; y <= sqrt(x); y += 2) {
if (x % y == 0) {
isprime = 0;
break;
}
}
if (isprime == 1) {
write("%d\n", x);
}
}
}

Images
Code: [Select]
void main() {
    object obrazek=Image.Image(1000, 1000);
    obrazek -> setcolor(255, 0, 0);
    obrazek -> box(10, 10, 20, 20);
    object plik = Stdio.File();
    plik -> open("test.gif", "wc");
    plik -> write(Image.GIF.encode(obrazek));
    plik -> close;
}

Graphics (GL)
Code: [Select]
int main() {
GLUE.init(([
"fullscreen": 0,
"resolution": ({ 640, 480 }),
]));
 
while (1) {
GL.glViewport(0, 0, 640, 480);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.glOrtho(-30.0, 30.0, -30.0, 30.0, -30.0, 30.0);
GL.glMatrixMode(GL.GL_MODELVIEW);
 
GL.glClearColor(0.3,0.3,0.3,0.0);
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
GL.glShadeModel(GL.GL_SMOOTH);
 
GL.glLoadIdentity();
GL.glTranslate(-15.0, -15.0, 0.0);
 
GL.glBegin(GL.GL_TRIANGLES);
GL.glColor(1.0, 0.0, 0.0);
GL.glVertex(0.0, 0.0);
GL.glColor(0.0, 1.0, 0.0);
GL.glVertex(30.0, 0.0);
GL.glColor(0.0, 0.0, 1.0);
GL.glVertex(0.0, 30.0);
GL.glEnd();
 
GL.glFlush();
 
GLUE.swap_buffers();
Pike.DefaultBackend(0.0);
sleep(0.01);
}
}

GUI (GTK)
Code: [Select]
GTK2.Widget mainwindow,clickcnt,clicker;
int clicks;
 
void click()
{
        clickcnt->set_text("Clicks: "+(++clicks));
}
 
int main()
{
        GTK2.setup_gtk();
        mainwindow=GTK2.Window(GTK2.WindowToplevel);
        mainwindow->set_title("Click counter");
        mainwindow->add(GTK2.Vbox(0,10)
                ->add(clickcnt=GTK2.Label("There have been no clicks yet"))
                ->add(clicker=GTK2.Button("Click me"))
        )->show_all();
        mainwindow->signal_connect("delete_event",lambda() {exit(0);});
        clicker->signal_connect("clicked",click);
        return -1;
}

Internet (fetching a website)
Code: [Select]
void main()
 {
write("%s", Protocols.HTTP.get_url_data("http://forum.retrogamecoding.org"));
}

I've tried it only on Linux (it's in Debian repos), but installer for Windows is available to download. Here are some usefull links:

http://pike.lysator.liu.se/
http://fredrik.hubbe.net/pike/
http://www.gotpike.org/
http://bobo.fuw.edu.pl/~rjb/Pike/FAQ.html
http://rosettacode.org/wiki/Category:Pike

If anyone interested, I've got a Geany file for it.

ScriptBasic

  • Guest
NIM (aka Nimrod)
« Reply #1 on: February 07, 2016, 03:48:10 AM »
@Tomaaz - Have you tried NIM?

AIR introduced NIM (Nimrod) on the All BASIC forum some time ago which there is still threads on the topic.

Tomaaz

  • Guest
Re: Pike
« Reply #2 on: February 08, 2016, 05:06:23 PM »
I have finally tried Pike on Win 10 and all the examples works without problems. The only strange thing was that my firewall blocked Pike when I run first example.

John, NIM's syntax looks more like Python. It is translated to C and then compiled to executables. I really can't see any similarities to Pike (it has C-like syntax and is an interpreted language).
« Last Edit: February 08, 2016, 05:09:13 PM by Tomaaz »

gomio

  • Guest
Re: Pike
« Reply #3 on: February 11, 2016, 11:22:02 AM »
Thanks for the info, Tomaaz, I didn't know this language and seems very interesting!

http://pike.lysator.liu.se/about/

jbk

  • Guest
Re: Pike
« Reply #4 on: February 11, 2016, 03:35:20 PM »
I've recently tried Pike and it seems to be a  nice language. It has syntax very similar to C, but it's interpreted and comes with several modules that are very easy to use.
..........
If anyone interested, I've got a Geany file for it.
hi Tomaaz
I am interested in the Geany file as I mostly use Geany for my recreational programming, would you share it?
btw, I built the latest version (8.0.164) of Pike on my Mac but have some missing dependencies, the dependency list is huge.
« Last Edit: February 11, 2016, 03:45:11 PM by jbk »

Tomaaz

  • Guest
Re: Pike
« Reply #5 on: February 12, 2016, 10:03:38 AM »
I am interested in the Geany file as I mostly use Geany for my recreational programming, would you share it?

The file is attached. Also, you need to add Pike=*.pike;  to your filetype_extensions.conf.

jbk

  • Guest
Re: Pike
« Reply #6 on: February 12, 2016, 03:16:31 PM »
thank you Tomaaz :)

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Pike
« Reply #7 on: February 12, 2016, 05:22:37 PM »
Hm, it looks almost like C but it isn't C. It's not a compiler, so why not use real C instead? Using TCC is really fun ...
And GTK isn't more compilcated using C:
Code: [Select]
#include <gtk/gtk.h>

void print_msg(GtkWidget *widget, gpointer window) {

  g_printf("Button clicked\n");
}

int main(int argc, char *argv[]) {

  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *halign;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "Mnemonic");
  gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
  gtk_container_set_border_width(GTK_CONTAINER(window), 15);
 
  button = gtk_button_new_with_mnemonic("_Button");
 
  g_signal_connect(button, "clicked",
      G_CALLBACK(print_msg), NULL); 
 
  halign = gtk_alignment_new(0, 0, 0, 0);
  gtk_container_add(GTK_CONTAINER(halign), button);
  gtk_container_add(GTK_CONTAINER(window), halign); 

  gtk_widget_show_all(window);
 
  g_signal_connect(G_OBJECT(window), "destroy",
      G_CALLBACK(gtk_main_quit), NULL);

  gtk_main();

  return 0;
}

Tomaaz

  • Guest
Re: Pike
« Reply #8 on: February 12, 2016, 05:47:46 PM »
Hm, it looks almost like C but it isn't C.

Well, that's the whole point...

It's not a compiler, so why not use real C?

You just answered your own question, even before you asked it. :) Why not to use C instead? Because Pike is an interpreter. You whole point doesn't make sense. If Pike was a compiler you could write: "It is a compiler, so why not use real C?". :)

And GTK isn't more compilcated using C:

Could you translate the other examples as well? And when you're done, I can send you a couple of more. Using TCC is fun, so...  ;)

ScriptBasic

  • Guest
Re: Pike
« Reply #9 on: February 12, 2016, 06:25:47 PM »
I think using an interpreter is fine as long as it can be extended and has a seamless C interface. Best of both worlds.

jbk

  • Guest
Re: Pike
« Reply #10 on: February 12, 2016, 06:35:42 PM »
my impression is that Pike includes many library functions without having to include headers, I could be wrong on this as I barely started with Pike.

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Pike
« Reply #11 on: February 12, 2016, 07:33:24 PM »
In my opinion it's again better to use C. Why? It's an ISO standard. It's probably 1000x faster than an interpreter.
Don't get me wrong, I do like interpreters. But if I use one it has to be totally different from C (otherwise using C makes more sense).  And all libraries Pike is using are made with either C or C++, so ...

Tomaaz

  • Guest
Re: Pike
« Reply #12 on: February 12, 2016, 08:57:09 PM »
In my opinion it's again better to use C. Why? It's an ISO standard. It's probably 1000x faster than an interpreter.

What's the point of using Lua in pulsarLua? In my opinion it would be better to use Luajit. Why? It is the same as Lua, but much faster.

Quote
Don't get me wrong, I do like interpreters. But if I use one it has to be totally different from C (otherwise using C makes more sense). 

 ;D ;D ;D Perl is C + sigils. Do you really believe that in any case it makes more sense to go for C?

And all libraries Pike is using are made with either C or C++, so ...

I wasn't expecting a stupid argument like that from you. Majority of languages use libraries written in C or C++. But some of those libraries are easy and pleasant to use, some are not.

For all who didn't bother to check Pike, but are playing experts. Pike is not a C interpreter. It has syntax similar to C (the same way Perl or Javascript have), but it's a separate language.

EDIT I'm not saying that Pike is the best language ever. I'm even not saying it will become my language of choice. It's an interesting interpreted language. A bit different that other scripting languages. That's it.
« Last Edit: February 12, 2016, 09:04:42 PM by Tomaaz »

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: Pike
« Reply #13 on: February 12, 2016, 10:10:48 PM »
So what is about that:
Quote
C has been around for 30 years, and there is a ton of source code available. This means there's a lot to learn from, and a lot to use. Moreover, many of the issues with the language have been clearly elucidated -- it's well understood, and you can find a lot of tutorials available.
I just wanted to say that for me (=my opinion) it's a waste of time to learn another C-like language if I can learn C itself.

Why I am not using LuaJIT: it's not as stable as Lua and for most users Lua is fast enough. (Why does WoW use Lua and not LuaJIT?) But again that's not the topic.

Tomaaz

  • Guest
Re: Pike
« Reply #14 on: February 12, 2016, 11:15:15 PM »
I just wanted to say that for me (=my opinion) it's a waste of time to learn another C-like language if I can learn C itself.

Pike is not a C-like language. It has syntax similar to C. Variables can be 'mixed' type, you don't have to dim arrays. Arrays can be nested, they can have elements of different type. You can do arithmetic operations on arrays. There is plenty of easy to use functions to manipulate arrays, strings, files etc. Of course, it's worth learning C, but there is many possible situation where choosing it over a scripting language with C-like syntax (Perl, PHP) would be an extremely stupid idea.

Why I am not using LuaJIT: it's not as stable as Lua and for most users Lua is fast enough.

No. You are not using LuaJIT, because it doesn't work nicely with FreePascal. At least, this is what you told me when I asked you some time ago. ;) You could try to make Luajit work with Pascal, but, as you say, Lua is... fast enough. :) The same applies to C and Perl, PHP or Pike. Sometimes you don't need C speed and you prefer to choose language that is much easier to use instead.