RetroBASIC
Offtopic => Offtopic => Topic started by: Tomaaz 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
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
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)
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)
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)
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.
-
@Tomaaz - Have you tried NIM (http://nim-lang.org/)?
AIR introduced NIM (Nimrod) on the All BASIC forum some time ago which there is still threads on the topic.
-
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).
-
Thanks for the info, Tomaaz, I didn't know this language and seems very interesting!
http://pike.lysator.liu.se/about/
-
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.
-
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.
-
thank you Tomaaz :)
-
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:
#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;
}
-
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... ;)
-
I think using an interpreter is fine as long as it can be extended and has a seamless C interface. Best of both worlds.
-
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.
-
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 ...
-
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.
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.
-
So what is about that:
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.
-
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.
-
Sometimes you don't need C speed and you prefer to choose language that is much easier to use instead.
I agree and that's the goal I have with Script BASIC. The language does a good job of integrating external C functionality and using C BASIC when developing the extensions somehow brings it full circle.
-
Do you remember the word count challenge from BP.org? For those who don't a little explanation. The task was to count all and unique words in Bible and then count how many times each word appears in the whole text. Then the result should be sorted and written to the file. Here is a Pike version:
void main() {
array|mixed a, b, c, b2;
b = ({});
b2 = ({});
c = ({});
int x, x2;
string y;
write("Reading the file...\n");
string content=Stdio.File("Bible.txt")->read();
content = lower_case(content);
a = content / " ";
write("Counting all words...\n");
for(x = 0; x < (sizeof(a) - 1); x++) {
a[x] = Regexp.PCRE("[^a-z]")->replace(a[x]," ");
b = b + (a[x] / " ");
}
for(x = 0; x < (sizeof(b) - 1); x++) {
if (strlen(b[x]) > 1 || b[x] == "a" || b[x] == "i") {
c = c + ({b[x]});
}
}
object plik = Stdio.File();
plik -> open("Words.txt", "wc");
write("All words: ");
plik -> write("All words: ");
write("%d\n", sizeof(c));
plik -> write("%d\n", sizeof(c));
write("Counting unique words...\n");
plik -> write("Counting unique words...\n");
a = Array.uniq(c);
write("Unique words: ");
plik -> write("Unique words: ");
write("%d\n", sizeof(a));
plik -> write("%d\n\n", sizeof(a));
write("Counting numbers of occurences of each word and sorting the result...\n");
b = ({});
x = 0;
foreach (a, y) {
b = b + ({y});
b2 = b2 + ({Array.count(c, y)});
}
c = (b2[0 .. sizeof(b2)]);
c = reverse(sort(c));
for(x = 0; x < sizeof(c); x++) {
for(x2 = 0; x2 < sizeof(b2); x2++) {
if (b2[x2] == c[x]) {
write(b[x2]);
plik -> write(b[x2]);
write(" - ");
plik -> write(" - ");
write("%d\n", b2[x2]);
plik -> write("%d\n", b2[x2]);
b2[x2] = -1000;
}
}
}
plik -> close();
}
BTW That was a very nice challenge. Maybe we should think about bringing it back?
-
It started off as a stress test for SPLITA() and became the word count challenge. I agree that was the best one with the most participation.
I have native array sort in SB now and if we did another round, I wouldn't cheat and use the OS sort utility.
-
Tomaaz, would you check this rosetta code? http://rosettacode.org/wiki/Associative_array/Iteration#Pike
it don't work for me.
-
I can't get on Rosettacode. Seems to be a problem with the server. Will try later.
-
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.
D.
-
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.
D.
I feel the same ;D
Try here (http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia), searching for Dickens.txt
-
It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.
Have you ever heard of the coding bible or tons of other references using the word bible as a substitute for standard?
-
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.
I feel the same ;D
Try here (http://sun.aei.polsl.pl/~sdeor/index.php?page=silesia), searching for Dickens.txt
Thanks JJ, that's much better - I'll see what I can find and propose that those who don't want to taint their good lives with that other text use something a little more... less aggressive? :)
D.
-
Does anyone have a text that's about the same size, but isn't the bible? It just feels wrong to be pushing something like that in a coding forum and kind of smacks of evangelism.
D.
I feel the same, using the Bible in such a trivial manner is disrespectful, here you will find other text files to consider ftp://ftp.cs.princeton.edu/pub/cs226/textfiles/
how about using dickens.txt it's about 29 MB in size or lilwomen.txt it's size about 1 MB
-
I feel the same, using the Bible in such a trivial manner is disrespectful...
I don't feel this way, but I understand others may do. So, what about Leo Tolstoy's "War and Peace"? I found a free copy in .txt format. It's 3 MB. The file is attached.
Result:
All words: 569924
Unique words: 17599
the - 34721
and - 22303
to - 16755
of - 15008
a - 10608
he - 10004
in - 9036
that - 8205
his - 7984
was - 7360
with - 5710
it - 5617
had - 5365
her - 4725
not - 4697
him - 4637
at - 4547
i - 4541
but - 4055
as - 4036
on - 4014
...
-
Weighted by string length:
Using warandpeace.txt on Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
22 ms for reading the file and converting to Lower$
402 ms for counting
9 ms for sorting
00104163 the
00066909 and
00033510 to
00032820 that
00030016 of
00023952 his
00022840 with
00022080 was
00020008 he
00018072 in
00016095 had
00014175 her
00014091 not
00013911 him
00012165 but
00011778 pierre
00011613 you
00011568 prince
00011368 said
00011234 it
00010836 from
00010665 for
00010608 a
00010467 she
00010320 which
00009700 were
00009596 what
00009094 at
00009024 they
00008491 natasha
Average=5.07 bytes
540895 duplicates, 17622 unique words
-
Tomaaz,
Can you verify that you changed the original word count challenge focus and the goal is something else? Looks like the JJ nuked thread and my SB post got deleted. :-\
-
Can you verify that you changed the original word count challenge focus and the goal is something else?
I haven' changed anything. The goal is to count all and unique words, count how many times each word appears in the file and sort the result by occurrence (not alphabetically!).
But I don't care anymore. The whole topic has been wiped out without any information. On the other forum I found posts saying that the whole word count challenge is just boring. Well, it may be not the most exciting programming task ever, but is definitely more interesting that another combination of color dots, circles and rectangles in 20 lines of code. On the same forum I just read that I'm a a copy/paste programmer and a liar. I really can't see a point of being part of this community. Having high-school like fights? Risking all my posts being wiped out only because someone else got angry at someone? No, thanx.
-
I feel your pain Tomaaz. That was the reason I bailed from the old PB.org forum was due to JJ speed freak antics and calling anything other than his work crap. I think the guy is whacked and needs to retire.
I haven' changed anything.
If you look at the the Script BASIC version that was the first example and what the code challenge was based on. Produce a sorted (by word - no dups) with instance count next to it. The SB version remarks out the by rank listing as that was an option to the challenge.
-
Tomaaz: I wouldn't describe what I posted as a high-school fight; I don't think that a BASIC programming forum is the place to promoting religious texts of any kind - this is a forum that, by it's very nature may well be read by children and we should be keeping it family friendly.
That said, the word count challenge is a worthy exercise - but it shouldn't be used in this manner.
D.
-
Tomaaz: I wouldn't describe what I posted as a high-school fight...
I wasn't referring to you. I was called "a liar" and a "copy/paste programmer" on the other forum (you know which one). Without any proof or examples. Also, some members here change their opinion about me to often. One minute I'm a cool guy (because I happen to agree with them), the other one I'm a troll, liar and lamer (because I dared to disagree with them). This all reminds me about teenagers fighting and playing games between each other. I totally understand your opinion about the Bible. I never thought about it before, because Bible is not that much important to me.
-
Bible is not that much important to me
The bible is a book of words hacked over the years to suit the current audience. Hell didn't make it's debut until after the depression with the onslaught of evangelist. I would think anyone that could code and look in the sky has figured out god, after life are just couping tools to get through life.
-
I haven' changed anything. The goal is to count all and unique words, count how many times each word appears in the file and sort the result by occurrence (not alphabetically!).
But I don't care anymore. The whole topic has been wiped out without any information. On the other forum I found posts saying that the whole word count challenge is just boring. Well, it may be not the most exciting programming task ever, but is definitely more interesting that another combination of color dots, circles and rectangles in 20 lines of code. On the same forum I just read that I'm a a copy/paste programmer and a liar. I really can't see a point of being part of this community. Having high-school like fights? Risking all my posts being wiped out only because someone else got angry at someone? No, thanx.
That is a real shame. I was really enjoying seeing (especially) the way it could be done in various other languages - Pike, Perl, Python, Ruby and Lua.
I guess beauty truly is in the eye of the beholder. But just ignore those that want to complain and argue about almost anything. Keep the posts coming!
-
isking all my posts being wiped out only because someone else got angry at someone? No, thanx.
Tomaaz,
As Ed already wrote, I enjoyed your posts very much. It looked promising, and I am genuinely interested in the topic, which you certainly understand when looking at my second version, where the occurrence is weighted by the length of the words.
However, when I start a thread, and Mr "I'll send my lawyers to shut this site down if you don't obey to my orders" dumps several long and completely irrelevant posts, with the absolutely clear intention to troll me, then I will be kind enough to react to his provocation. Apparently he needs the occasional beating, for reasons that my professional background doesn't allow me to analyse. Maybe his mother knows what went wrong.
-
But just ignore those that want to complain and argue about almost anything.
I can do it easily, but what about moderators/administrators who delete my posts/topics only because someone else started trolling?
As Ed already wrote, I enjoyed your posts very much. It looked promising, and I am genuinely interested in the topic, which you certainly understand when looking at my second version, where the occurrence is weighted by the length of the words.
I know you're interested in the topic, but well... the topic has been wiped out. As I said above - this is what I can't understand. It was the same problem with BP.org. One member started trolling, so let's close/remove the whole topic.
BTW Thanx guys! It's good to know that some people are interested in the same things I am. :)
EDIT jj, all the sources I posted are gone, so do you want me to send them to you? They are very similar (it's the same code translated to other languages), so if you still have the Python version, you've got everything you need.
Tomaaz, would you check this rosetta code? http://rosettacode.org/wiki/Associative_array/Iteration#Pike
it don't work for me.
I was finally able to check this example. It works but you need to add main() function and remove badly inserted comments:
void main() {
mapping(string:string) m = ([ "A":"a", "B":"b", "C":"c" ]);
foreach(m; string key; string value)
{
write(key+value);
}
foreach(m; string key;)
{
write(key);
}
foreach(m;; string value)
{
write(value);
}
}
Here (http://pike.lysator.liu.se/generated/manual/ref/chapter_2.html) you can find information about foreach loop.
Was that the problem or did you mean something else?
-
all the sources I posted are gone, so do you want me to send them to you? They are very similar (it's the same code translated to other languages), so if you still have the Python version, you've got everything you need.
I've got the Python version, of course, but it would do no harm if you zipped them all and attached it here. Before the whole thread goes bang again ;-)
-
The file is attached.
-
The old, good, boring word count again. ;) The last Pike version I've posted is very slow. This is the proper one:
void main() {
mapping(string:int) m;
m = ([]);
array|mixed a, b, c;
b = ({});
c = ({});
int x;
string y;
write("Reading the file...\n");
string content = Stdio.File("warandpeace.txt")->read();
content = lower_case(content);
a = content / " ";
write("Counting all words...\n");
for(x = 0; x < (sizeof(a) - 1); x++) {
a[x] = Regexp.PCRE("[^a-z]")->replace(a[x]," ");
b = b + (a[x] / " ");
}
for(x = 0; x < (sizeof(b) - 1); x++) {
if (strlen(b[x]) > 1 || b[x] == "a" || b[x] == "i") {
c = c + ({b[x]});
}
}
object plik = Stdio.File();
plik -> open("Words.txt", "w");
write("All words: ");
plik -> write("All words: ");
write("%d\n", sizeof(c));
plik -> write("%d\n", sizeof(c));
write("Counting unique words...\n");
write("Unique words: ");
plik -> write("Unique words: ");
write("%d\n", sizeof(Array.uniq(c)));
plik -> write("%d\n\n", sizeof(Array.uniq(c)));
write("Counting numbers of occurences of each word and sorting the result...\n");
x = 0;
foreach (c, y) {
if (m[y]) {
m[y] = m[y] + 1;
}
else {
m[y] = 1;
}
}
foreach (reverse(sort(values(m))), x) {
foreach (indices(m), y) {
if (m[y] == x) {
plik -> write(y);
plik -> write(" - ");
plik -> write("%d\n", m[y]);
m = m - ([y:x]);
}
}
}
plik -> close();
write("Done!\n");
}