Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3]

Author Topic: DF in python?  (Read 9891 times)

Starver

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #30 on: October 04, 2012, 05:54:41 am »

Call-by-sharing is the common description.  In Python, strings are immutable, so when you assign  (arg = 'One')  you're only creating a new string for arg to reference within the function, and val remains unchanged since it's still referencing the 'Two' string.

Python now officially confuses me.  Usually if we set variable=constant, then var is still as variable as it once was.  And what if we set var2=var?

I pride myself on understanding all kinds of languages (even if I can't yet reliably write with them), but looks like Python is... too strange.

(Obviously, it could be the same sort of 'trick' as if you "shift @_" in a Perl sub (ruining the connection between caller parameters and making any $_[0] assignments local only), or dealing with $_[0] and $_[1] directly which (assuming the parameter is assignable to, i.e. not a constant) keeps itself being an alias for the original scalar variable and usable as an 'Lvalue' (thing wot can sit on the left hand side of an assignment).  While I always liked that feature in Perl, and use it, I always considered it a bit 'hacky', in the midst of all the rest of the default behaviour...  Even for me.  Even for Perl.)
Logged

SethCreiyd

  • Bay Watcher
  • [VESPERTINE]
    • View Profile
Re: DF in python?
« Reply #31 on: October 04, 2012, 11:31:42 am »

I'm not the best explainer of things, nor the most experienced with the language, but I'll try to clarify:

Spoiler (click to show/hide)
Logged

MadocComadrin

  • Bay Watcher
  • A mysterious laboratory goblin!
    • View Profile
Re: DF in python?
« Reply #32 on: October 04, 2012, 12:42:18 pm »

I'd say your assertion isn't actually true, and never was...

For a more software-relevant technical term (though eigenvalues are used quite a bit in physics engines too), try finding out what a "dual quaternion" is and what it's useful for by its name alone - even when knowing which of the many, many meanings of "dual" it refers to and what a "quaternion" is.
I think you might have missed the words "a general goal." It implies that there are other goals to balance and does not always hold for specific instances. I did not say trend; I did not say rule. You're not going to change my opinion that the term "call-by-sharing" is silly, and for every example you come up with that do not appear descriptive (I actually find the term eigenvalue to be rather poetic) I can find just as many that do.

Quote
That's implementation-specific. Python implementations (there is more than one already) can implement the same call-by-sharing semantics by actually copying the argument values, then copying them back if they were modified in the function. This is useful if the function is running on a different computer from the calling environment.
Then that's call-by-copy-restore! (And remote evaluation can throw a monkey wrench in many things.).
Logged

EvilTwin

  • Bay Watcher
  • likes skeletons for their afros
    • View Profile
Re: DF in python?
« Reply #33 on: October 04, 2012, 12:55:57 pm »

Actual Response to the OP:

If you are interested in programming games with Python, you should check out Blender 3D. It's a free 3D modeling software, but it includes a lot of additional things, for instance a game engine. This game engine utilizes a sensor-logic-actuator mechanism, whereby the sensor and actuator can actually be read out by a special Python-script logic-brick, so basically, Blender gives you a framework to run your scripts in, which then control game objects. I think that the Blender game engine is a great way to start out with game programming as you won't have to deal with resource-management and all that and can get a first grasp of game logic.
Logged

etgfrog

  • Bay Watcher
  • delete & NULL;
    • View Profile
Re: DF in python?
« Reply #34 on: October 04, 2012, 01:16:36 pm »

I'd consider myself competent with programing in python and overall I think it would be possible to write df in python and might even run faster in some cases(referring to late game fortresses, being able to cull the old unit list and having multi-threading split pathfinding across multiple cpus) but I seriously doubt anything done in even a years worth of work could stack up to DF, but I'd say the biggest hurdle would be getting pathfinding to be as efficient. Anyways...if you are interested in trying to make some sort of game, I'd recommend looking at pygame, so far I've found it to be pretty good for 2d and sprite based stuff.
Logged
"How dare you get angry after being scammed."

Starver

  • Bay Watcher
    • View Profile
Re: DF in python?
« Reply #35 on: October 04, 2012, 03:19:01 pm »

Started replying to SethCreiyd, but I ended up writing an awful lot more than I intended...  Basically, it appears that Python blatantly passes a reference in a situation where references are so ubiquitous that they are rarely remarked upon.  Which is perhaps subtly different from standard "pass-by-reference", but only subtly.


Quote
I hope that helps the confusion, though it's probably easier to understand than my explanations make it.  Though there are some weird aspects to it, Python makes sense once one gets used to it.  If I can learn to use it, anyone here can.[/size][/spoiler]
Well, what I took away from that is that working with references in Python is a whole lot less involved, because it's by default (and probably integrated with a better memory-handling/garbage-collection structure), and doesn't need loads of dereferencing/re-referencing code because it's made for an OO-context where most things are supposed to work on (object) references, regardless of what the user considers they may be.  But some of the awkward printing things (e.g. the printing of hash items, or the specific splicing out of an array item) I would normally have written out once and set as a function call.

And I thought Perl was loose with types[1], looks like Python is really far out on that field, man... ;)


Anyway, I may find some time to poke into Python...  Just need to get out of Function-Orientated and Data-Orientated mode, as I always end up when I do much of anything with Perl, and embrace Python's brand of Object-Orientation more fully!



[1] $scalar, @array, %hash, &code and *glob, but with the added 'benefit' that any $scalar (including a $scalar that is an $array[$index] or $hash{item} singularity...  and as for *globs, that's a lot more explaining!) could be a reference to anything, including further $scalars, @arrays, %hashes, &codefragments or *globs... ;)
Logged
Pages: 1 2 [3]