Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Associative Arrays (https://forums.graalonline.com/forums/showthread.php?t=83824)

xXziroXx 01-22-2009 06:28 PM

Associative Arrays
 
Will we ever get them? :(

Codein 01-22-2009 06:44 PM

Oooh, yeah. Good idea.

WhiteDragon 01-22-2009 07:21 PM

We already have hashes, associative arrays would just be the same thing with different syntax.

xXziroXx 01-22-2009 08:10 PM

Quote:

Originally Posted by WhiteDragon (Post 1459014)
We already have hashes, associative arrays would just be the same thing with different syntax.

There's a difference between manually scripting things and to have them implemented straight in the engine, though.

WhiteDragon 01-22-2009 08:35 PM

Quote:

Originally Posted by xXziroXx (Post 1459020)
There's a difference between manually scripting things and to have them implemented straight in the engine, though.

I don't really get what you mean.

Hashes are the most common way associative arrays are implemented, so we have associative arrays, just without the conventional syntax one would see in for example in PHP.

Loriel 01-22-2009 08:48 PM

At some point you would think people would just want to plob javascript into the engine.

Crow 01-22-2009 09:02 PM

Quote:

Originally Posted by Loriel (Post 1459026)
At some point you would think people would just want to plob javascript into the engine.

Lua please.

Loriel 01-22-2009 09:10 PM

Quote:

Originally Posted by Crow (Post 1459035)
Lua please.

Basically a toss-up between one-based arrays and the icky closure semantics, but, yeah, okay, lua.

WhiteDragon 01-22-2009 09:40 PM

Quote:

Originally Posted by Loriel (Post 1459048)
Basically a toss-up between one-based arrays and the icky closure semantics, but, yeah, okay, lua.

Well, now that we're at it... Haskell? :D

Loriel 01-22-2009 09:46 PM

Quote:

Originally Posted by WhiteDragon (Post 1459070)
Well, now that we're at it... Haskell? :D

I have never felt a stronger urge to throw my chair at some guy through the internet than I am experiencing right now. :mad:

I would not even know where to begin to write an associate array in haskell that has any better than O(n) lookups.

WhiteDragon 01-22-2009 11:00 PM

Quote:

Originally Posted by Loriel (Post 1459076)
I have never felt a stronger urge to throw my chair at some guy through the internet than I am experiencing right now. :mad:

I would not even know where to begin to write an associate array in haskell that has any better than O(n) lookups.

Haskell provides the lookup function which works differently on different data structures.

If you do it on a list like [("a", "1"), ("b", "2"), ("c", "3")] it'll return in O(n).

However, if you do it on a Data.Map which are represented as immutable balanced binary trees, it'll give you a O(log(n)).

Those would be the preferred methods since they both provide a purely functional interface, but you can use hash tables as well with an imperative interface in the IO Monad (with a data HashTable) giving you the O(1).

Inverness 01-29-2009 06:38 PM

Keep your inferior languages to yourself, obviously Python would be the better choice, its popularity speaks for itself. Utilizing Boost::Python makes it much easier to wrap C++.

Python implements hash tables (associative array) as the 'dict' object. You can specify dict literals using angle brackets.

e = {'key1': 'value1', 'key2': 'value2'}
print(e['key2'])

Python allows you to define many functions called by the interpreter, in this case, e['key2'] = 3 maps to e.__setitem__('key2', 3). You can quite easily take control of item or attribute lookup or other things.

One of the major points in favor of Python is readability, which is obviously important in Graal considering the programming experience and amount of people that would be looking at one script.

Thanks for thread URL Ziro.

Loriel 01-29-2009 09:13 PM

Quote:

Originally Posted by Inverness (Post 1461110)
Keep your inferior languages to yourself, obviously Python would be the better choice, its popularity speaks for itself. Utilizing Boost::Python makes it much easier to wrap C++.

If we are going down that road, keep your python to yourself and give me C++. :\

Lua is designed for embedding to begin with and there are plenty of ways to wrap C++ into lua. What makes boost.python superior to third-party lua binding libraries?

Quote:

Python implements hash tables (associative array) as the 'dict' object. You can specify dict literals using angle brackets.

e = {'key1': 'value1', 'key2': 'value2'}
print(e['key2'])

Python allows you to define many functions called by the interpreter, in this case, e['key2'] = 3 maps to e.__setitem__('key2', 3). You can quite easily take control of item or attribute lookup or other things.
lua, and I am pretty sure javascript as well, does these too, for what it is worth, and the associative-array data type is way more integrated into the core languages of lua and javascript as far as I can tell.

Quote:

One of the major points in favor of Python is readability, which is obviously important in Graal considering the programming experience and
amount of people that would be looking at one script.
This is way subjective. Show me how Python is more readable than lua. Lua's syntax is really hard to beat as far as elegance and straightfowardness go.

Inverness 01-29-2009 10:12 PM

Quote:

Originally Posted by Loriel (Post 1461148)
If we are going down that road, keep your python to yourself and give me C++. :\

Why have one when you can have both? It's quite easy to write C/C++ extensions for Python.
Quote:

Originally Posted by Loriel (Post 1461148)
Lua is designed for embedding to begin with and there are plenty of ways to wrap C++ into lua. What makes boost.python superior to third-party lua binding libraries?

Python is designed for both embedding and extending. Boost::Python is merely the connection between C++ and Python's C API, and is designed to wrap your C++ code without changing it. There's also the fact that it is part of Boost, I'd think the name carries some weight.
Quote:

Originally Posted by Loriel (Post 1461148)
lua, and I am pretty sure javascript as well, does these too, for what it is worth, and the associative-array data type is way more integrated into the core languages of lua and javascript as far as I can tell.

Python uses the dict (dictionary/associative-array) data type for storing all local, module (global), and object variables. It is a vital part of the language, so naturally it is extremely optimized same with Lua and Javascript.
Quote:

Originally Posted by Loriel (Post 1461148)
This is way subjective. Show me how Python is more readable than lua. Lua's syntax is really hard to beat as far as elegance and straightfowardness go.

I'd like a specific situation to apply it to.

WhiteDragon 01-30-2009 01:47 AM

Hey, let's find a thread where Inverness DOESN'T start arguing that Python is better than all other languages when he actually hasn't used most of the other ones people are talking about!

Inverness 01-30-2009 02:32 AM

Quote:

Originally Posted by WhiteDragon (Post 1461206)
Hey, let's find a thread where Inverness DOESN'T start arguing that Python is better than all other languages when he actually hasn't used most of the other ones people are talking about!

If you get the impression that I'm saying Python is "better than all other languages" then you have the wrong one.

I'm saying Python is better for Graal's needs, which are: clear and readable syntax, extensive documentation, and rich object-oriented capabilities, among other things.

WhiteDragon 01-30-2009 03:28 AM

Quote:

Originally Posted by Inverness (Post 1461110)
Keep your inferior languages to yourself, obviously Python would be the better choice

Quote:

Originally Posted by Inverness
If you get the impression that I'm saying Python is "better than all other languages" then you have the wrong one.

Either that or I'm illiterate.

Inverness 01-30-2009 03:55 AM

Quote:

Originally Posted by WhiteDragon (Post 1461231)
Either that or I'm illiterate.

I think its the latter.

And I await your response to the second half of my previous post.

WhiteDragon 01-30-2009 04:05 AM

Quote:

Originally Posted by Inverness (Post 1461219)
I'm saying Python is better for Graal's needs, which are: clear and readable syntax, extensive documentation, and rich object-oriented capabilities, among other things.

1. Lua has clear and readable syntax.
2. Lua has extensive documentation.
3. Lua is richly MULTI-paradigm! Check it out, you can be imperative, functional, prototypal, and object-oriented! Amazing!


1. Haskell has concise syntax.
2. Haskell has extensive documentation.
3. Haskell is a functional programming language! Sweet! Check it out, everything is a function!

Inverness 01-30-2009 04:21 AM

Quote:

Originally Posted by WhiteDragon (Post 1461238)
<post>

I see what you did there.

Of course, the better means of comparison would be to solve Graal problems in the language. And I think I'm bored enough to do that.

Loriel 01-30-2009 08:19 AM

Quote:

Originally Posted by Inverness (Post 1461240)
Of course, the better means of comparison would be to solve Graal problems in the language. And I think I'm bored enough to do that.

Ah, let us just hack together a quick Graal clone and cram any scripting language we can get out hand on into it!

Inverness 01-30-2009 09:05 PM

Quote:

Originally Posted by Loriel (Post 1461283)
Ah, let us just hack together a quick Graal clone and cram any scripting language we can get out hand on into it!

Already working on it. :D


All times are GMT +2. The time now is 05:16 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.